From 0cdf113e296c4160042b351dabdb5293fab627c3 Mon Sep 17 00:00:00 2001 From: Victor Date: Tue, 13 Feb 2024 16:36:05 -0800 Subject: [PATCH 1/4] fixed bookmarks/likes on bookmarks + crash on bookmarks --- .../components/common/Card/AudioCard/AudioCard.tsx | 2 +- .../components/common/Card/ImageCard/ImageCard.tsx | 2 +- .../src/hooks/useBatchContent/useBatchContent.tsx | 3 ++- .../fakeyou.com/src/hooks/useRatings/useRatings.tsx | 13 ++++++++++--- .../profile/profile_view/tabs/BookmarksTab.tsx | 6 +++--- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/packages/fakeyou.com/src/components/common/Card/AudioCard/AudioCard.tsx b/packages/fakeyou.com/src/components/common/Card/AudioCard/AudioCard.tsx index 6344ea1ca3..476a5a96c6 100644 --- a/packages/fakeyou.com/src/components/common/Card/AudioCard/AudioCard.tsx +++ b/packages/fakeyou.com/src/components/common/Card/AudioCard/AudioCard.tsx @@ -182,7 +182,7 @@ export default function AudioCard({ {...{ creator: data?.creator || data.details.maybe_weight_data?.maybe_creator, - entityToken: data.weight_token, + entityToken: data.weight_token || data.details?.entity_token, entityType: "model_weight", makeBookmarksProps: bookmarks?.makeProps, makeRatingsProps: ratings?.makeProps, diff --git a/packages/fakeyou.com/src/components/common/Card/ImageCard/ImageCard.tsx b/packages/fakeyou.com/src/components/common/Card/ImageCard/ImageCard.tsx index dd4680c3fd..77d63fa7d5 100644 --- a/packages/fakeyou.com/src/components/common/Card/ImageCard/ImageCard.tsx +++ b/packages/fakeyou.com/src/components/common/Card/ImageCard/ImageCard.tsx @@ -184,7 +184,7 @@ export default function ImageCard({ creator: data.creator || data.details.maybe_weight_data?.maybe_creator, - entityToken: data.weight_token, + entityToken: data.weight_token || data.details?.entity_token, entityType: "model_weight", makeBookmarksProps: bookmarks?.makeProps, makeRatingsProps: ratings?.makeProps, diff --git a/packages/fakeyou.com/src/hooks/useBatchContent/useBatchContent.tsx b/packages/fakeyou.com/src/hooks/useBatchContent/useBatchContent.tsx index 3d6e08885b..122df522e7 100644 --- a/packages/fakeyou.com/src/hooks/useBatchContent/useBatchContent.tsx +++ b/packages/fakeyou.com/src/hooks/useBatchContent/useBatchContent.tsx @@ -57,7 +57,8 @@ export default function useBatchContent({ const dlog = (...dbg: any) => debug ? console.log(...dbg) : {}; const gather = ({ expand, key, res }: Gather) => { - let tokens = res.results ? res.results.map((item: any) => item[key]) : [res[key]]; + let tokens = res.results ? res.results.map((item: any) => item.details[key] || item[key]) : [res[key]]; + // console.log("😎",tokens); let abc = tokens.reduce((obj = {},token = "") => ({ ...obj, [token]: true }),{}) dlog("🪙",fetcher); tokenTypeSet(key) diff --git a/packages/fakeyou.com/src/hooks/useRatings/useRatings.tsx b/packages/fakeyou.com/src/hooks/useRatings/useRatings.tsx index 7e2167eaa3..e72622b0a7 100644 --- a/packages/fakeyou.com/src/hooks/useRatings/useRatings.tsx +++ b/packages/fakeyou.com/src/hooks/useRatings/useRatings.tsx @@ -34,9 +34,16 @@ export default function useRatings() { checker: () => true, // debug: "useRatings", modLibrary: (current: any, res: any, entity_token: string, tokenType: string) => { - let { positive_rating_count } = res.results ? res.results.find((item: any, i: number) => - item[tokenType] === entity_token - ).stats : res.stats; + + let result = res.results ? res.results.find((item: any, i: number) => + { + return item.details[tokenType] === entity_token || item[tokenType] === entity_token + } + ) : res; + + let { positive_rating_count } = result.details.stats || result.stats; + + // let { positive_rating_count } = res.results ? itemMatch.details.stats || itemMatch.details.stats return { ...current, positive_rating_count }; }, diff --git a/packages/fakeyou.com/src/v2/view/pages/profile/profile_view/tabs/BookmarksTab.tsx b/packages/fakeyou.com/src/v2/view/pages/profile/profile_view/tabs/BookmarksTab.tsx index 38a8d19475..056c5cc874 100644 --- a/packages/fakeyou.com/src/v2/view/pages/profile/profile_view/tabs/BookmarksTab.tsx +++ b/packages/fakeyou.com/src/v2/view/pages/profile/profile_view/tabs/BookmarksTab.tsx @@ -58,8 +58,8 @@ export default function BookmarksTab({ username }: { username: string }) { listSet, onInputChange: () => setShowMasonryGrid(false), onSuccess: res => { - bookmarks.gather({ res, key: "weight_token" }); - ratings.gather({ res, key: "weight_token" }); + bookmarks.gather({ res, key: "entity_token" }); + ratings.gather({ res, key: "entity_token" }); setShowMasonryGrid(true); }, requestList: true, @@ -236,7 +236,7 @@ export default function BookmarksTab({ username }: { username: string }) { > From f635436450327b94a39e4c0b07a8ce52ef46eae6 Mon Sep 17 00:00:00 2001 From: Victor Date: Tue, 13 Feb 2024 16:51:50 -0800 Subject: [PATCH 2/4] fixed media page not reloading when token changes --- packages/fakeyou.com/src/hooks/useMedia/useMedia.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/fakeyou.com/src/hooks/useMedia/useMedia.tsx b/packages/fakeyou.com/src/hooks/useMedia/useMedia.tsx index 8c1a616337..0e9e5f9932 100644 --- a/packages/fakeyou.com/src/hooks/useMedia/useMedia.tsx +++ b/packages/fakeyou.com/src/hooks/useMedia/useMedia.tsx @@ -7,7 +7,6 @@ export default function useMedia({ mediaToken = "", onSuccess = (res:MediaFile) const [status, statusSet] = useState(FetchStatus.ready); const [writeStatus, writeStatusSet] = useState(FetchStatus.paused); const [media,mediaSet] = useState(); - const remove = (as_mod: boolean) => { writeStatusSet(FetchStatus.in_progress); DeleteMedia(mediaToken, { @@ -35,6 +34,11 @@ export default function useMedia({ mediaToken = "", onSuccess = (res:MediaFile) }); } + if (media && media.token !== mediaToken) { + mediaSet(undefined); + statusSet(FetchStatus.ready); + } + },[media, mediaToken, onSuccess, status, statusSet]); return { media, mediaSet, remove, status, writeStatus }; }; \ No newline at end of file From 72086fb5267310a53766e30897e8d8f1f57f1efd Mon Sep 17 00:00:00 2001 From: Victor Date: Tue, 13 Feb 2024 17:13:44 -0800 Subject: [PATCH 3/4] fixed bug with cards not displaying --- .../fakeyou.com/src/hooks/useBatchContent/useBatchContent.tsx | 3 +-- packages/fakeyou.com/src/hooks/useLazyLists/useLazyLists.tsx | 3 ++- .../fakeyou.com/src/v2/view/pages/explore/tabs/MediaTab.tsx | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/fakeyou.com/src/hooks/useBatchContent/useBatchContent.tsx b/packages/fakeyou.com/src/hooks/useBatchContent/useBatchContent.tsx index 122df522e7..a69e201267 100644 --- a/packages/fakeyou.com/src/hooks/useBatchContent/useBatchContent.tsx +++ b/packages/fakeyou.com/src/hooks/useBatchContent/useBatchContent.tsx @@ -57,8 +57,7 @@ export default function useBatchContent({ const dlog = (...dbg: any) => debug ? console.log(...dbg) : {}; const gather = ({ expand, key, res }: Gather) => { - let tokens = res.results ? res.results.map((item: any) => item.details[key] || item[key]) : [res[key]]; - // console.log("😎",tokens); + let tokens = res.results ? res.results.map((item: any) => item.detail ? item.details[key] : item[key]) : [res[key]]; let abc = tokens.reduce((obj = {},token = "") => ({ ...obj, [token]: true }),{}) dlog("🪙",fetcher); tokenTypeSet(key) diff --git a/packages/fakeyou.com/src/hooks/useLazyLists/useLazyLists.tsx b/packages/fakeyou.com/src/hooks/useLazyLists/useLazyLists.tsx index 92151b86e9..f9d5947f15 100644 --- a/packages/fakeyou.com/src/hooks/useLazyLists/useLazyLists.tsx +++ b/packages/fakeyou.com/src/hooks/useLazyLists/useLazyLists.tsx @@ -95,7 +95,7 @@ export default function useLazyLists({ if (urlUpdate) { history.replace({ pathname, search }); } fetcher("", {}, queries).then((res: any) => { - if (debug) + // if (debug) console.log(`🐞 useLazyLists success debug at: ${debug}`, res); statusSet(FetchStatus.success); onSuccess(res); @@ -115,6 +115,7 @@ export default function useLazyLists({ // Key exists, just update the existing data const updatedObj = { ...prevObj }; updatedObj[keyExists] = res.results; + console.log("💛",updatedObj); return updatedObj; } }); diff --git a/packages/fakeyou.com/src/v2/view/pages/explore/tabs/MediaTab.tsx b/packages/fakeyou.com/src/v2/view/pages/explore/tabs/MediaTab.tsx index b38dd40b8d..dd51d4e4f0 100644 --- a/packages/fakeyou.com/src/v2/view/pages/explore/tabs/MediaTab.tsx +++ b/packages/fakeyou.com/src/v2/view/pages/explore/tabs/MediaTab.tsx @@ -29,6 +29,7 @@ export default function MediaTab() { ); const [showMasonryGrid, setShowMasonryGrid] = useState(true); const [list, listSet] = useState([]); + console.log("💙",list); const media = useLazyLists({ addQueries: { page_size: 24, @@ -42,8 +43,10 @@ export default function MediaTab() { listSet, onInputChange: () => setShowMasonryGrid(false), onSuccess: res => { + console.log("😎",res); ratings.gather({ res, expand: true, key: "token" }); // expand rather than replace for lazy loading bookmarks.gather({ res, expand: true, key: "token" }); // expand rather than replace for lazy loading + console.log("🩵",); setShowMasonryGrid(true); }, requestList: true, From 4cd834e04cc6367f8b924965e7efdad7c6409c93 Mon Sep 17 00:00:00 2001 From: Victor Date: Tue, 13 Feb 2024 19:54:39 -0800 Subject: [PATCH 4/4] fixed likes not loading --- .../src/hooks/useBatchContent/useBatchContent.tsx | 6 +++--- .../fakeyou.com/src/hooks/useLazyLists/useLazyLists.tsx | 3 +-- packages/fakeyou.com/src/hooks/useRatings/useRatings.tsx | 6 ++---- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/fakeyou.com/src/hooks/useBatchContent/useBatchContent.tsx b/packages/fakeyou.com/src/hooks/useBatchContent/useBatchContent.tsx index a69e201267..d46add91ca 100644 --- a/packages/fakeyou.com/src/hooks/useBatchContent/useBatchContent.tsx +++ b/packages/fakeyou.com/src/hooks/useBatchContent/useBatchContent.tsx @@ -57,11 +57,11 @@ export default function useBatchContent({ const dlog = (...dbg: any) => debug ? console.log(...dbg) : {}; const gather = ({ expand, key, res }: Gather) => { - let tokens = res.results ? res.results.map((item: any) => item.detail ? item.details[key] : item[key]) : [res[key]]; - let abc = tokens.reduce((obj = {},token = "") => ({ ...obj, [token]: true }),{}) + let tokens = res.results ? res.results.map((item: any) => (item.details || item)[key]) : [res[key]]; + let loadingTokens = tokens.reduce((obj = {},token = "") => ({ ...obj, [token]: true }),{}) dlog("🪙",fetcher); tokenTypeSet(key) - busyListSet(abc); // add current batch to busy list + busyListSet(loadingTokens); // add current batch to busy list fetcher("",{},{ tokens }).then((batchRes: any) => { // console.log("🦄",resultsKey, res, modLibrary); diff --git a/packages/fakeyou.com/src/hooks/useLazyLists/useLazyLists.tsx b/packages/fakeyou.com/src/hooks/useLazyLists/useLazyLists.tsx index f9d5947f15..92151b86e9 100644 --- a/packages/fakeyou.com/src/hooks/useLazyLists/useLazyLists.tsx +++ b/packages/fakeyou.com/src/hooks/useLazyLists/useLazyLists.tsx @@ -95,7 +95,7 @@ export default function useLazyLists({ if (urlUpdate) { history.replace({ pathname, search }); } fetcher("", {}, queries).then((res: any) => { - // if (debug) + if (debug) console.log(`🐞 useLazyLists success debug at: ${debug}`, res); statusSet(FetchStatus.success); onSuccess(res); @@ -115,7 +115,6 @@ export default function useLazyLists({ // Key exists, just update the existing data const updatedObj = { ...prevObj }; updatedObj[keyExists] = res.results; - console.log("💛",updatedObj); return updatedObj; } }); diff --git a/packages/fakeyou.com/src/hooks/useRatings/useRatings.tsx b/packages/fakeyou.com/src/hooks/useRatings/useRatings.tsx index e72622b0a7..08b0dfc83e 100644 --- a/packages/fakeyou.com/src/hooks/useRatings/useRatings.tsx +++ b/packages/fakeyou.com/src/hooks/useRatings/useRatings.tsx @@ -37,13 +37,11 @@ export default function useRatings() { let result = res.results ? res.results.find((item: any, i: number) => { - return item.details[tokenType] === entity_token || item[tokenType] === entity_token + return (item.details || item)[tokenType] === entity_token } ) : res; - let { positive_rating_count } = result.details.stats || result.stats; - - // let { positive_rating_count } = res.results ? itemMatch.details.stats || itemMatch.details.stats + let { positive_rating_count } = (result.details || result).stats; return { ...current, positive_rating_count }; },