Keep on pushing images to Gallery

Hello
I have a gallery on which I want to apply some filters. This gallery has to keep on adding images to the gallery, for example, when I select ‘leggings’ it only shows leggings images and when I select ‘socks’ it shows socks but I want the leggings images to stay and show socks images on the gallery as well. This is the url:

This is the code I have so far:


export function button4_click(event, $w) {
	wixData.query('Clothing').eq('type', 'Leggings') 
	    .find().then(result => {
	    //Get data of the first row 
	    const rowInDatabase = result.items[0]; 
	    //Creating array for images to put it gallery 
	    const imagesToShow = []; //going over all fields in the row 
	    for (let key in rowInDatabase) { 
	    //assuming images fields have the word 'image' in them 
	    if (key.includes('image')) {                 
	        imagesToShow.push({src: rowInDatabase[key]}); } 
	    } 
	    $w('#gallery1').items = imagesToShow; 
	});
}

export function button5_click(event, $w) {
	wixData.query('Clothing').eq('type', 'Socks') 
	    .find().then(result => {
	    //Get data of the first row 
	    const rowInDatabase = result.items[0]; 
	    //Creating array for images to put it gallery 
	    const imagesToShow = []; //going over all fields in the row 
	    for (let key in rowInDatabase) { 
	    //assuming images fields have the word 'image' in them 
	    if (key.includes('image')) {                 
	        imagesToShow.push({src: rowInDatabase[key]}); } 
	    } 
	    $w('#gallery1').items = imagesToShow; 
	});
}

Any help from Wix experts?

well declaring the array outside of both functions solved the problem but the problem is that it only shows one image at a time