fix filter crash
This commit is contained in:
parent
e4c05771e3
commit
1f7c16f626
@ -19,6 +19,16 @@ const SORT_KEYS = {
|
|||||||
export type GalleryImage =
|
export type GalleryImage =
|
||||||
Queries.GalleryPageQueryQuery["allFile"]["nodes"][number];
|
Queries.GalleryPageQueryQuery["allFile"]["nodes"][number];
|
||||||
|
|
||||||
|
const debugWrap =
|
||||||
|
(name: string, fn: Function) =>
|
||||||
|
(...asdf: any) => {
|
||||||
|
try {
|
||||||
|
return fn(...asdf);
|
||||||
|
} catch (e) {
|
||||||
|
console.log("threw in " + name, e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const GalleryPage = ({ data }: PageProps<Queries.GalleryPageQueryQuery>) => {
|
const GalleryPage = ({ data }: PageProps<Queries.GalleryPageQueryQuery>) => {
|
||||||
const hash =
|
const hash =
|
||||||
typeof window !== "undefined" ? window.location.hash.replace("#", "") : "";
|
typeof window !== "undefined" ? window.location.hash.replace("#", "") : "";
|
||||||
@ -120,37 +130,45 @@ const GalleryPage = ({ data }: PageProps<Queries.GalleryPageQueryQuery>) => {
|
|||||||
}, 100);
|
}, 100);
|
||||||
}, [setSortKey, setKeyword, scrollIntoView]);
|
}, [setSortKey, setKeyword, scrollIntoView]);
|
||||||
|
|
||||||
const images: GalleryImage[] = React.useMemo(
|
const images: GalleryImage[] = React.useMemo(() => {
|
||||||
() =>
|
const sort =
|
||||||
R.pipe(
|
|
||||||
// @ts-ignore
|
|
||||||
sortKey === "date"
|
sortKey === "date"
|
||||||
? R.sort((node1: typeof data["allFile"]["nodes"][number], node2) => {
|
? R.sort((node1: typeof data["allFile"]["nodes"][number], node2) => {
|
||||||
const date1 = new Date(
|
const date1 = new Date(
|
||||||
// @ts-ignore
|
R.pathOr("", ["fields", "imageMeta", "dateTaken"], node1)
|
||||||
R.path(["fields", "imageMeta", "dateTaken"], node1)
|
|
||||||
);
|
);
|
||||||
const date2 = new Date(
|
const date2 = new Date(
|
||||||
// @ts-ignore
|
R.pathOr("", ["fields", "imageMeta", "dateTaken"], node2)
|
||||||
R.path(["fields", "imageMeta", "dateTaken"], node2)
|
|
||||||
);
|
);
|
||||||
return -1 * (date1.getTime() - date2.getTime());
|
return -1 * (date1.getTime() - date2.getTime());
|
||||||
})
|
})
|
||||||
: // @ts-ignore
|
: R.sort(
|
||||||
R.sort(R.descend(R.path(SORT_KEYS[sortKey]))),
|
|
||||||
filterKeyword
|
|
||||||
? R.filter((image) =>
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
R.descend(R.path<GalleryImage>(SORT_KEYS[sortKey]))
|
||||||
|
);
|
||||||
|
|
||||||
|
const filter = filterKeyword
|
||||||
|
? R.filter((image) =>
|
||||||
R.includes(
|
R.includes(
|
||||||
filterKeyword,
|
filterKeyword,
|
||||||
|
R.pathOr([], ["fields", "imageMeta", "meta", "Keywords"], image)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
: R.identity;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const ret = R.pipe(
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
R.path(["fields", "imageMeta", "meta", "Keywords"], image)
|
sort,
|
||||||
)
|
filter
|
||||||
)
|
)(data.allFile.nodes) as any;
|
||||||
: R.identity
|
return ret;
|
||||||
)(data.allFile.nodes) as any,
|
} catch (e) {
|
||||||
[data, sortKey, filterKeyword]
|
console.log("caught images!", e);
|
||||||
);
|
return [];
|
||||||
|
}
|
||||||
|
}, [data, sortKey, filterKeyword]);
|
||||||
|
console.log("🚀 ~ file: photogallery.tsx ~ line 175 ~ GalleryPage ~ filterKeyword", filterKeyword)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@ -210,8 +228,8 @@ const GalleryPage = ({ data }: PageProps<Queries.GalleryPageQueryQuery>) => {
|
|||||||
md: 4,
|
md: 4,
|
||||||
lg: 4,
|
lg: 4,
|
||||||
xl: 5,
|
xl: 5,
|
||||||
'2xl': 6.1,
|
"2xl": 6.1,
|
||||||
'3xl': 7.5,
|
"3xl": 7.5,
|
||||||
}}
|
}}
|
||||||
debugHue={sortKey === "hue_debug"}
|
debugHue={sortKey === "hue_debug"}
|
||||||
debugRating={sortKey === "rating" && showDebug}
|
debugRating={sortKey === "rating" && showDebug}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user