diff --git a/packages/fakeyou.com/src/hooks/useBatchContent/useBatchContent.tsx b/packages/fakeyou.com/src/hooks/useBatchContent/useBatchContent.tsx index f5b781e0e9..09f41f33af 100644 --- a/packages/fakeyou.com/src/hooks/useBatchContent/useBatchContent.tsx +++ b/packages/fakeyou.com/src/hooks/useBatchContent/useBatchContent.tsx @@ -28,7 +28,7 @@ export default function useBatchContent({ fetcher, modLibrary = (current: any, res: any, entity_token: string ) => current, onPass, - onFail, + onFail = { fetch: () => new Promise(() => {}) }, resultsKey, toggleCheck }: Props) { @@ -36,26 +36,31 @@ export default function useBatchContent({ const [library, librarySet] = useState({}); const [busyList, busyListSet] = useState({}); const [status, statusSet] = useState(FetchStatus.ready); + const [tokenType,tokenTypeSet] = useState(""); const gather = ({ expand, key, res }: Gather) => { let tokens = res.results ? res.results.map((item: any) => item[key]) : [res[key]]; + let abc = tokens.reduce((obj = {},token = "") => ({ ...obj, [token]: true }),{}) // console.log("🪙",fetcher); - busyListSet(tokens.reduce((obj = {},token = "") => ({ ...obj, [token]: true }),{})); // add current batch to busy list + tokenTypeSet(key) + busyListSet(abc); // add current batch to busy list fetcher("",{},{ tokens }).then((batchRes: any) => { - // console.log("🪙", res, modLibrary); + // console.log("🦄",resultsKey, res, modLibrary); if (batchRes.success && !!batchRes[resultsKey]) { - // console.log("🥏",batchRes[resultsKey]); + // console.log("🥏",resultsKey); let newBatch = batchRes[resultsKey].reduce((obj = {}, { entity_token = "", ...current }) => { - // console.log("🧲",current, res, entity_token, obj); + // console.log("🧲", resultsKey, {current, res, entity_token, obj}); let newCurrent = { ...obj, - [entity_token]: { ...modLibrary(current, res, entity_token) } + [entity_token]: { ...modLibrary(current, res, entity_token, key) } }; + + + // console.log("😡", resultsKey, newCurrent); return newCurrent; },{}); - - // console.log("😡", newBatch); + // console.log("🐸",busyList); busyListSet({}); // this should be a for each key in tokens delete from busyList, but this is fine for now librarySet((library: any) => expand ? { ...library, ...newBatch } : newBatch); } @@ -80,6 +85,7 @@ export default function useBatchContent({ console.log(`⏳ toggling entity ${ entity_token }, in library?: ${ !!inLibrary }`); if (inLibrary && checker(inLibrary)) { + // console.log("⭕️"); return onPass.fetch(entity_token, entity_type, library) .then((res: any) => { console.log("⭕️",res); @@ -89,6 +95,7 @@ export default function useBatchContent({ return false; }); } else { + // console.log("❌"); return onFail.fetch(entity_token, entity_type, library) .then((res: any) => { console.log("❌",res); @@ -123,6 +130,7 @@ export default function useBatchContent({ makeProps, status, statusSet, + tokenType, toggle, toggled }; diff --git a/packages/fakeyou.com/src/hooks/useRatings/useRatings.tsx b/packages/fakeyou.com/src/hooks/useRatings/useRatings.tsx index c06d0d0798..c427c49911 100644 --- a/packages/fakeyou.com/src/hooks/useRatings/useRatings.tsx +++ b/packages/fakeyou.com/src/hooks/useRatings/useRatings.tsx @@ -4,40 +4,45 @@ import { useBatchContent } from "hooks"; export default function useRatings() { const fetch = (entity_token: string, entity_type: string, lib: any) => { - return SetRating("",{ + const newRating = { entity_token, entity_type, - rating_value: lib[entity_token].rating_value === "neutral" ? "positive" : "neutral" - }); + rating_value: lib[entity_token]?.rating_value !== "positive" ? "positive" : "neutral" + } + // console.log("😎",lib[entity_token], newRating); + return SetRating("", newRating); + }; + + const modLibrary = (res: any, entity_token: string, entity_type: string, lib: any) => { + return { + ...lib, + [entity_token]: { + entity_type, + rating_value: lib[entity_token].rating_value === "neutral" ? "positive" : "neutral", + positive_rating_count: res.new_positive_rating_count_for_entity + } + }; }; const ratings = useBatchContent({ fetcher: GetRatings, checker: () => true, - modLibrary: (current: any, res: any, entity_token: string) => { + modLibrary: (current: any, res: any, entity_token: string, tokenType: string) => { + // console.log("🪼", tokenType, res ); let { positive_rating_count } = res.results ? res.results.find((item: any, i: number) => - item.weight_token === entity_token + item[tokenType] === entity_token ).stats : res.stats; return { ...current, positive_rating_count }; }, - onPass: { - fetch, - modLibrary: (res: any, entity_token: string, entity_type: string, lib: any) => { - return { - ...lib, - [entity_token]: { - entity_type, - rating_value: lib[entity_token].rating_value === "neutral" ? "positive" : "neutral", - positive_rating_count: res.new_positive_rating_count_for_entity - } - }; - } - }, + onFail: { fetch, modLibrary }, + onPass: { fetch, modLibrary }, resultsKey: "ratings", toggleCheck: (entity: any) => (entity?.rating_value || "") === "positive" }); + // console.log("🍎",ratings.busyList); + return { ...ratings, makeProps: ({ entityToken, entityType }: { entityToken: string, entityType: string }) => ({ 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 26207a612c..c327727b54 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 @@ -39,7 +39,7 @@ export default function MediaTab() { listSet, onInputChange: () => setShowMasonryGrid(false), onSuccess: res => { - bookmarks.gather({ res, expand: true, key: "token" }); // expand rather than replace for lazy loading + ratings.gather({ res, expand: true, key: "token" }); // expand rather than replace for lazy loading setShowMasonryGrid(true); }, requestList: true,