diff --git a/frontend/src/contexts/SearchImageContext.tsx b/frontend/src/contexts/SearchImageContext.tsx index 35a9ded..72bd2af 100644 --- a/frontend/src/contexts/SearchImageContext.tsx +++ b/frontend/src/contexts/SearchImageContext.tsx @@ -30,6 +30,8 @@ export type SearchImageStore = { Array<{ date: Date; images: JustTheImageWhatAreTheseNames }> >; + lists: Accessor>["Lists"]>; + userImages: Accessor; imagesWithProperties: Accessor>; @@ -117,6 +119,7 @@ export const SearchImageContextProvider: Component = (props) => { value={{ images: imageData, imagesByDate: sortedImages, + lists: () => data()?.Lists ?? [], imagesWithProperties: imagesWithProperties, userImages: () => data()?.UserImages ?? [], processingImages, diff --git a/frontend/src/pages/front/gallery.tsx b/frontend/src/pages/front/gallery.tsx index 1800dd2..058eaec 100644 --- a/frontend/src/pages/front/gallery.tsx +++ b/frontend/src/pages/front/gallery.tsx @@ -4,6 +4,7 @@ import { SearchImageStore, useSearchImageContext, } from "@contexts/SearchImageContext"; +import fastHashCode from "../../utils/hash"; // TODO: lots of stuff to do with Entities, this could be seperated into a centralized place. const CategoryColor: Record< @@ -16,8 +17,22 @@ const CategoryColor: Record< note: "bg-green-50", }; +const colors = [ + "bg-emerald-50", + "bg-lime-50", + + "bg-indigo-50", + "bg-sky-50", + + "bg-amber-50", + "bg-teal-50", + + "bg-fuchsia-50", + "bg-pink-50", +]; + export const Categories: Component = () => { - const { categories } = useSearchImageContext(); + const { categories, lists } = useSearchImageContext(); return (
@@ -41,6 +56,26 @@ export const Categories: Component = () => { )}
+

Generated Lists

+
+ + {(list) => ( + +

{list.Name}

+

{list.Images.length}

+
+ )} +
+
); }; diff --git a/frontend/src/utils/hash.ts b/frontend/src/utils/hash.ts new file mode 100644 index 0000000..ff50e20 --- /dev/null +++ b/frontend/src/utils/hash.ts @@ -0,0 +1,41 @@ +// Adding options parameter to allow to change the behavior of the function (should be compatible with the first version of the function) +/** + * Generate a hash from a string, simple and fast. + * reference: https://werxltd.com/wp/2010/05/13/javascript-implementation-of-javas-string-hashcode-method/ + * @version 2.1.0 + * @param {string} str Input string + * @param {Object} options Options + * @param {boolean} options.forcePositive If true, the hash will be forcePositive. + * @param {boolean} options.caseSensitive Case sensitive + * @param {boolean} options.seed Seed for the hash + */ +// From https://github.com/alexandrehpiva/fast-hash-code/blob/main/src/index.ts +export function fastHashCode( + str: string, + options: { + forcePositive?: boolean; + caseSensitive?: boolean; + seed?: number; + } = {}, +): number { + const { forcePositive = false, caseSensitive = true, seed = 0 } = options; + + if (!caseSensitive) { + str = str.toLowerCase(); + } + + let hash = seed; + let i; + for (i = 0; i < str.length; i++) { + hash = (hash << 5) - hash + str.charCodeAt(i); + hash |= 0; // Convert to 32bit integer + } + + if (forcePositive) { + hash = hash & 0x7fffffff; + } + + return hash; +} + +export default fastHashCode;