Scaffold out UI components

This commit is contained in:
rektdeckard
2020-07-21 23:07:36 -04:00
parent 016e6d987b
commit 19d9b8c7d2
24 changed files with 1063 additions and 528 deletions

View File

@@ -1,5 +1,5 @@
import { atom } from "recoil";
import { IconStyle } from "../lib/Icon";
import { IconStyle } from "../lib";
/**
* ATOM
@@ -20,7 +20,7 @@ export const styleQueryAtom = atom<IconStyle>({
export const iconSizeAtom = atom<number>({
key: "iconSizeAtom",
default: 24,
default: 32,
});
export const iconColorAtom = atom<string>({

View File

@@ -1,8 +1,8 @@
import { selector, selectorFamily } from "recoil";
import { searchQueryAtom, styleQueryAtom } from "./atoms";
import { Icon, IconStyle, IconCategory } from "../lib/Icon";
import { iconList } from "../lib/iconList";
import { IconEntry, IconCategory } from "../lib";
import { icons } from "../lib/icons";
/**
* SELECTOR
@@ -11,7 +11,7 @@ import { iconList } from "../lib/iconList";
* modifies the given state in some way:
*/
const isQueryMatch = (icon: Icon, query: string): boolean => {
const isQueryMatch = (icon: IconEntry, query: string): boolean => {
return (
icon.name.includes(query) ||
icon.tags.some((tag) => tag.toLowerCase().includes(query)) ||
@@ -19,44 +19,43 @@ const isQueryMatch = (icon: Icon, query: string): boolean => {
);
};
const isStyleMatch = (icon: Icon, style?: IconStyle): boolean => {
return !style || icon.style === style;
};
export const filteredQueryResultsSelector = selector<Icon[]>({
export const filteredQueryResultsSelector = selector<Readonly<IconEntry[]>>({
key: "filteredQueryResultsSelector",
get: ({ get }) => {
const query = get(searchQueryAtom).trim().toLowerCase();
const style = get(styleQueryAtom);
if (!query && !style) return iconList;
if (!query && !style) return icons;
return iconList.filter((icon) => {
return isStyleMatch(icon, style) && isQueryMatch(icon, query);
return icons.filter((icon) => {
return isQueryMatch(icon, query);
});
// .sort(() => Math.floor(Math.random() - 0.5));
},
});
type CategorizedIcons = {
[key in IconCategory]?: Icon[];
};
type CategorizedIcons = Partial<Record<IconCategory, IconEntry[]>>;
export const categorizedQueryResultsSelector = selector<CategorizedIcons>({
export const categorizedQueryResultsSelector = selector<
Readonly<CategorizedIcons>
>({
key: "categorizedQueryResultsSelector",
get: ({ get }) => {
const filteredResults = get(filteredQueryResultsSelector);
return filteredResults.reduce<CategorizedIcons>((acc, curr) => {
curr.categories.forEach((category) => {
if (acc[category]) acc[category]?.push(curr);
else acc[category] = [curr];
if (!acc[category]) acc[category] = [];
acc[category]!!.push(curr);
});
return acc;
}, {});
},
});
export const singleCategoryQueryResultsSelector = selectorFamily<Icon[], IconCategory>({
export const singleCategoryQueryResultsSelector = selectorFamily<
Readonly<IconEntry[]>,
IconCategory
>({
key: "singleCategoryQueryResultsSelector",
get: (category: IconCategory) => ({ get }) => {
const filteredResults = get(filteredQueryResultsSelector);