Skip to content

Commit

Permalink
✨ Add new options.
Browse files Browse the repository at this point in the history
  • Loading branch information
pheralb committed Dec 14, 2023
1 parent 7abef9f commit 0184f1b
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@
import Grid from '@/components/grid.svelte';
import NotFound from '@/components/notFound.svelte';
// Icons:
import ArrowsClockWise from 'phosphor-svelte/lib/ArrowsClockwise';
import ArrowSquareOut from 'phosphor-svelte/lib/ArrowSquareOut';
// Search:
let searchTerm = '';
let filteredSvgs: iSVG[] = [];
if (searchTerm.length === 0) {
filteredSvgs = allSvgs.sort((a: iSVG, b: iSVG) => {
return a.title.localeCompare(b.title);
return b.id - a.id;
});
}
Expand All @@ -33,6 +37,32 @@
searchTerm = '';
searchSvgs();
};
// Sort:
let sorted: boolean = false;
const sort = () => {
if (sorted) {
sortByLatest();
} else {
sortAlphabetically();
}
sorted = !sorted;
};
// Sort alphabetically:
const sortAlphabetically = () => {
filteredSvgs = filteredSvgs.sort((a: iSVG, b: iSVG) => {
return a.title.localeCompare(b.title);
});
};
// Sort by latest:
const sortByLatest = () => {
filteredSvgs = filteredSvgs.sort((a: iSVG, b: iSVG) => {
return b.id - a.id;
});
};
</script>

<svelte:head>
Expand All @@ -46,6 +76,23 @@
clearSearch={() => clearSearch()}
placeholder={`Search ${filteredSvgs.length} logos...`}
/>
<div class={`flex items-center justify-between my-4 ${filteredSvgs.length === 0 && 'hidden'}`}>
<button
class="flex items-center justify-center space-x-2 rounded-md py-1.5 text-sm font-medium text-neutral-500 dark:text-neutral-400 hover:text-dark dark:hover:text-white duration-100 transition-colors"
on:click={() => sort()}
>
<ArrowsClockWise size={14} />
<span>{sorted ? 'Sort by latest' : 'Sort alphabetically'}</span>
</button>
<a
class="flex items-center justify-center space-x-2 rounded-md py-1.5 text-sm font-medium text-neutral-500 dark:text-neutral-400 hover:text-dark dark:hover:text-white duration-100 transition-colors"
href="https://github.com/pheralb/svgl?tab=readme-ov-file#-getting-started"
target="_blank"
>
<span>Submit SVG</span>
<ArrowSquareOut size={14} />
</a>
</div>
<Grid>
{#each filteredSvgs as svg}
<SvgCard svgInfo={svg} />
Expand Down

1 comment on commit 0184f1b

@vercel
Copy link

@vercel vercel bot commented on 0184f1b Dec 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

svgl – ./

svgl-pheralb.vercel.app
svgl-git-main-pheralb.vercel.app
svgl.vercel.app

Please sign in to comment.