From 27887e227844bf47bb312f931b763d51dd449f4d Mon Sep 17 00:00:00 2001 From: Victor Date: Wed, 24 Jan 2024 11:53:48 -0800 Subject: [PATCH] fixed landing on home page upon deleting, and replaced "origin" value with "source" as origin is a global --- .../common/Card/AudioCard/AudioCard.tsx | 15 +++++---------- .../common/Card/ImageCard/ImageCard.tsx | 13 ++++--------- .../common/Card/MocapCard/MocapCard.tsx | 15 +++++---------- .../common/Card/VideoCard/VideoCard.tsx | 9 ++++----- .../src/components/common/Card/getCardUrl.tsx | 7 +++++++ .../providers/SessionProvider/SessionProvider.tsx | 1 - .../src/hooks/useRatings/useRatings.tsx | 8 +------- .../src/hooks/useWeightFetch/useWeightFetch.tsx | 4 ++-- .../v2/view/pages/explore/tabs/FeaturedTab.tsx | 6 ++++-- .../src/v2/view/pages/explore/tabs/MediaTab.tsx | 6 +++--- .../src/v2/view/pages/explore/tabs/WeightsTab.tsx | 3 ++- .../profile/profile_view/tabs/BookmarksTab.tsx | 6 +++--- .../pages/profile/profile_view/tabs/MediaTab.tsx | 6 +++--- .../profile/profile_view/tabs/WeightsTab.tsx | 4 ++-- .../src/v2/view/pages/weight/WeightPage.tsx | 8 +++++--- 15 files changed, 50 insertions(+), 61 deletions(-) create mode 100644 packages/fakeyou.com/src/components/common/Card/getCardUrl.tsx 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 a21fb41db5..55a9c38a1f 100644 --- a/packages/fakeyou.com/src/components/common/Card/AudioCard/AudioCard.tsx +++ b/packages/fakeyou.com/src/components/common/Card/AudioCard/AudioCard.tsx @@ -13,14 +13,15 @@ import useWeightTypeInfo from "hooks/useWeightTypeInfo/useWeightTypeInfo"; import WeightCoverImage from "components/common/WeightCoverImage"; import { BucketConfig } from "@storyteller/components/src/api/BucketConfig"; import useToken from "hooks/useToken"; +import getCardUrl from "../getCardUrl"; interface AudioCardProps { bookmarks?: any; data: any; - origin?: string; ratings?: any; showCreator?: boolean; showCover?: boolean; + source?: string; type: "media" | "weights"; inSelectModal?: boolean; onResultSelect?: () => void; @@ -29,22 +30,17 @@ interface AudioCardProps { export default function AudioCard({ bookmarks, data, - origin = "", ratings, showCreator, showCover, + source = "", type, inSelectModal = false, onResultSelect, }: AudioCardProps) { const { setToken, setWeightTitle } = useToken(); + const linkUrl = getCardUrl(data,source,type); const history = useHistory(); - const linkUrl = - type === "media" - ? `/media/${data.token}` - : `/weight/${data.weight_token || data.details.entity_token}${ - origin ? "?origin=" + origin : "" - }`; const handleInnerClick = (event: any) => { event.stopPropagation(); @@ -257,8 +253,7 @@ export default function AudioCard({ ) : ( {card} 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 8028fa8df1..72b029c527 100644 --- a/packages/fakeyou.com/src/components/common/Card/ImageCard/ImageCard.tsx +++ b/packages/fakeyou.com/src/components/common/Card/ImageCard/ImageCard.tsx @@ -11,13 +11,14 @@ import { faArrowRight } from "@fortawesome/pro-solid-svg-icons"; import useWeightTypeInfo from "hooks/useWeightTypeInfo/useWeightTypeInfo"; import { BucketConfig } from "@storyteller/components/src/api/BucketConfig"; import useToken from "hooks/useToken"; +import getCardUrl from "../getCardUrl"; interface ImageCardProps { bookmarks?: any; data: any; - origin?: string; ratings?: any; showCreator?: boolean; + source?: string; type: "media" | "weights"; inSelectModal?: boolean; onResultSelect?: () => void; @@ -26,8 +27,8 @@ interface ImageCardProps { export default function ImageCard({ bookmarks, data, - origin = "", showCreator, + source = "", ratings, type, inSelectModal = false, @@ -35,12 +36,7 @@ export default function ImageCard({ }: ImageCardProps) { const history = useHistory(); const { setToken, setWeightTitle } = useToken(); - const linkUrl = - type === "media" - ? `/media/${data.token}` - : `/weight/${data.weight_token || data.details.entity_token}${ - origin ? "?origin=" + origin : "" - }`; + const linkUrl = getCardUrl(data,source,type); const handleInnerClick = (event: any) => { event.stopPropagation(); @@ -268,7 +264,6 @@ export default function ImageCard({ {card} diff --git a/packages/fakeyou.com/src/components/common/Card/MocapCard/MocapCard.tsx b/packages/fakeyou.com/src/components/common/Card/MocapCard/MocapCard.tsx index 3e3646a673..8013d13f1a 100644 --- a/packages/fakeyou.com/src/components/common/Card/MocapCard/MocapCard.tsx +++ b/packages/fakeyou.com/src/components/common/Card/MocapCard/MocapCard.tsx @@ -7,31 +7,27 @@ import LikeButton from "components/common/LikeButton"; import CreatorName from "../CreatorName"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faPersonWalking } from "@fortawesome/pro-solid-svg-icons"; +import getCardUrl from "../getCardUrl"; // import { BucketConfig } from "@storyteller/components/src/api/BucketConfig"; interface ImageCardProps { bookmarks: any; data: any; - origin?: string; ratings: any; showCreator?: boolean; + source?: string; type: "media" | "weights"; } export default function ImageCard({ bookmarks, data, - origin = "", showCreator, + source = "", ratings, type, }: ImageCardProps) { - const linkUrl = - type === "media" - ? `/media/${data.token}` - : `/weight/${data.weight_token || data.details.entity_token}${ - origin ? "?origin=" + origin : "" - }`; + const linkUrl = getCardUrl(data,source,type); const handleInnerClick = (event: any) => { event.stopPropagation(); @@ -44,8 +40,7 @@ export default function ImageCard({ return ( diff --git a/packages/fakeyou.com/src/components/common/Card/VideoCard/VideoCard.tsx b/packages/fakeyou.com/src/components/common/Card/VideoCard/VideoCard.tsx index f27cb72cf6..d30bac3723 100644 --- a/packages/fakeyou.com/src/components/common/Card/VideoCard/VideoCard.tsx +++ b/packages/fakeyou.com/src/components/common/Card/VideoCard/VideoCard.tsx @@ -10,12 +10,13 @@ import CreatorName from "../CreatorName"; import { BucketConfig } from "@storyteller/components/src/api/BucketConfig"; import { Link } from "react-router-dom"; import useToken from "hooks/useToken"; +import getCardUrl from "../getCardUrl"; interface VideoCardProps { data: any; - origin?: string; ratings?: any; showCreator?: boolean; + source?: string; type: "media" | "weights"; inSelectModal?: boolean; onResultSelect?: () => void; @@ -23,16 +24,15 @@ interface VideoCardProps { export default function VideoCard({ data, - origin = "", ratings, showCreator, + source = "", type, inSelectModal = false, onResultSelect, }: VideoCardProps) { const { setToken, setWeightTitle } = useToken(); - const linkUrl = - type === "media" ? `/media/${data.token}` : `/weight/${data.weight_token}`; + const linkUrl = getCardUrl(data,source,type); const handleInnerClick = (event: any) => { event.stopPropagation(); @@ -197,7 +197,6 @@ export default function VideoCard({ {card} diff --git a/packages/fakeyou.com/src/components/common/Card/getCardUrl.tsx b/packages/fakeyou.com/src/components/common/Card/getCardUrl.tsx new file mode 100644 index 0000000000..98450f2076 --- /dev/null +++ b/packages/fakeyou.com/src/components/common/Card/getCardUrl.tsx @@ -0,0 +1,7 @@ +const getCardUrl = (data: any, source: string, type: string) => { + let prefix = type === "media" ? `/media/${data.token}` : `/weight/${data.weight_token || data.details?.entity_token}`; + let suffix = source ? "?source=" + source : ""; + return prefix + suffix; +} + +export default getCardUrl; \ No newline at end of file diff --git a/packages/fakeyou.com/src/components/providers/SessionProvider/SessionProvider.tsx b/packages/fakeyou.com/src/components/providers/SessionProvider/SessionProvider.tsx index b1b155eab9..200f6c5796 100644 --- a/packages/fakeyou.com/src/components/providers/SessionProvider/SessionProvider.tsx +++ b/packages/fakeyou.com/src/components/providers/SessionProvider/SessionProvider.tsx @@ -13,7 +13,6 @@ interface Props { } export default function SessionProvider({ children, querySession, querySubscriptions, sessionFetched, sessionWrapper }: Props) { - console.log("🥕",sessionWrapper); const sessionResponse = sessionWrapper?.sessionStateResponse || { logged_in: false }; const { logged_in: loggedIn, user } = sessionResponse; const [view,viewSet] = useState(ModalView.Closed); diff --git a/packages/fakeyou.com/src/hooks/useRatings/useRatings.tsx b/packages/fakeyou.com/src/hooks/useRatings/useRatings.tsx index 6823b45898..ad76b737ed 100644 --- a/packages/fakeyou.com/src/hooks/useRatings/useRatings.tsx +++ b/packages/fakeyou.com/src/hooks/useRatings/useRatings.tsx @@ -9,7 +9,6 @@ export default function useRatings() { entity_type, rating_value: lib[entity_token]?.rating_value !== "positive" ? "positive" : "neutral" } - // console.log("😎",lib[entity_token], newRating); return SetRating("", newRating); }; @@ -27,15 +26,12 @@ export default function useRatings() { const ratings = useBatchContent({ fetcher: GetRatings, checker: () => true, - debug: "useRatings", + // debug: "useRatings", 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[tokenType] === entity_token ).stats : res.stats; - console.log("🐽",positive_rating_count); - return { ...current, positive_rating_count }; }, onFail: { fetch, modLibrary }, @@ -44,8 +40,6 @@ export default function useRatings() { 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/hooks/useWeightFetch/useWeightFetch.tsx b/packages/fakeyou.com/src/hooks/useWeightFetch/useWeightFetch.tsx index b885972460..e3d6790503 100644 --- a/packages/fakeyou.com/src/hooks/useWeightFetch/useWeightFetch.tsx +++ b/packages/fakeyou.com/src/hooks/useWeightFetch/useWeightFetch.tsx @@ -55,10 +55,10 @@ export default function useWeightFetch({ onRemove = n, onSuccess = n, token }: P }); }; - const remove = () => { + const remove = (as_mod: boolean) => { writeStatusSet(FetchStatus.in_progress); DeleteWeight(token, { - as_mod: true, + as_mod, set_delete: true, }).then((res: any) => { writeStatusSet(FetchStatus.success); diff --git a/packages/fakeyou.com/src/v2/view/pages/explore/tabs/FeaturedTab.tsx b/packages/fakeyou.com/src/v2/view/pages/explore/tabs/FeaturedTab.tsx index 35660bad4b..99b4301b73 100644 --- a/packages/fakeyou.com/src/v2/view/pages/explore/tabs/FeaturedTab.tsx +++ b/packages/fakeyou.com/src/v2/view/pages/explore/tabs/FeaturedTab.tsx @@ -1,4 +1,5 @@ import React, { useEffect, useRef, useState } from "react"; +import { useLocation } from "react-router-dom"; import MasonryGrid from "components/common/MasonryGrid/MasonryGrid"; import MediaCards from "components/common/Card/MediaCards"; import { Link } from "react-router-dom"; @@ -13,6 +14,7 @@ import SkeletonCard from "components/common/Card/SkeletonCard"; import "./FeaturedTab.scss"; export default function FeaturedTab() { + const { pathname: source } = useLocation(); const bookmarks = useBookmarks(); const ratings = useRatings(); const gridContainerRef = useRef(null); @@ -83,10 +85,10 @@ export default function FeaturedTab() { let props = { bookmarks, data, - origin, ratings, - type: "media", showCreator: true, + source, + type: "media", }; return ( 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 c327727b54..92ca0b7cec 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 @@ -16,7 +16,7 @@ import InfiniteScroll from "react-infinite-scroll-component"; import prepFilter from "resources/prepFilter"; export default function MediaTab() { - const { search } = useLocation(); + const { pathname: source, search } = useLocation(); const urlQueries = new URLSearchParams(search); const bookmarks = useBookmarks(); const ratings = useRatings(); @@ -33,7 +33,7 @@ export default function MediaTab() { ...prepFilter(mediaType, "filter_media_type"), }, addSetters: { mediaTypeSet }, - debug: "explore media tab", + // debug: "explore media tab", fetcher: ListMediaFiles, list, listSet, @@ -125,7 +125,7 @@ export default function MediaTab() { let props = { bookmarks, data, - origin, + source, ratings, type: "media", showCreator: true, diff --git a/packages/fakeyou.com/src/v2/view/pages/explore/tabs/WeightsTab.tsx b/packages/fakeyou.com/src/v2/view/pages/explore/tabs/WeightsTab.tsx index edd106f814..7051a520aa 100644 --- a/packages/fakeyou.com/src/v2/view/pages/explore/tabs/WeightsTab.tsx +++ b/packages/fakeyou.com/src/v2/view/pages/explore/tabs/WeightsTab.tsx @@ -16,7 +16,7 @@ import { useBookmarks, useLazyLists, useRatings } from "hooks"; import prepFilter from "resources/prepFilter"; export default function WeightsTab() { - const { search } = useLocation(); + const { pathname: source, search } = useLocation(); const urlQueries = new URLSearchParams(search); const bookmarks = useBookmarks(); const ratings = useRatings(); @@ -188,6 +188,7 @@ export default function WeightsTab() { let props = { bookmarks, data, + source, ratings, showCreator: true, type: "weights", 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 d16a85f7d4..7f9c885632 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 @@ -15,7 +15,7 @@ import WeightsCards from "components/common/Card/WeightsCards"; import prepFilter from "resources/prepFilter"; export default function BookmarksTab({ username }: { username: string }) { - const { pathname: origin, search } = useLocation(); + const { pathname: source, search } = useLocation(); const urlQueries = new URLSearchParams(search); const bookmarks = useBookmarks(); const ratings = useRatings(); @@ -52,7 +52,7 @@ export default function BookmarksTab({ username }: { username: string }) { ...prepFilter(weightCategory, "maybe_scoped_weight_category"), }, addSetters: { sdSet, ttsSet, vcSet, weightCategorySet, weightTypeSet }, - debug: "bookmarks tab", + // debug: "bookmarks tab", fetcher: GetBookmarksByUser, list, listSet, @@ -209,7 +209,7 @@ export default function BookmarksTab({ username }: { username: string }) { onLayoutComplete={() => console.log("Layout complete!")} > {dataList.map((data: any, key: number) => { - let weightProps = { bookmarks, data, origin, ratings, showCreator: true, type: "weights" }; + let weightProps = { bookmarks, data, ratings, showCreator: true, source, type: "weights" }; // let mediaProps = { // bookmarks, diff --git a/packages/fakeyou.com/src/v2/view/pages/profile/profile_view/tabs/MediaTab.tsx b/packages/fakeyou.com/src/v2/view/pages/profile/profile_view/tabs/MediaTab.tsx index 4f1d866bd6..0bc7e3bcaf 100644 --- a/packages/fakeyou.com/src/v2/view/pages/profile/profile_view/tabs/MediaTab.tsx +++ b/packages/fakeyou.com/src/v2/view/pages/profile/profile_view/tabs/MediaTab.tsx @@ -17,7 +17,7 @@ import { useListContent, useRatings } from "hooks"; import prepFilter from "resources/prepFilter"; export default function MediaTab({ username }: { username: string }) { - const { pathname: origin, search } = useLocation(); + const { pathname: source, search } = useLocation(); const urlQueries = new URLSearchParams(search); // const bookmarks = useBookmarks(); const ratings = useRatings(); @@ -33,7 +33,7 @@ export default function MediaTab({ username }: { username: string }) { ...prepFilter(mediaType, "filter_media_type"), }, addSetters: { mediaTypeSet }, - debug: "profile media", + // debug: "profile media", fetcher: GetMediaByUser, list, listSet, @@ -116,7 +116,7 @@ export default function MediaTab({ username }: { username: string }) { onLayoutComplete={() => console.log("Layout complete!")} > {media.list.map((data: MediaFile, key: number) => { - let props = { data, origin, ratings, type: "media" }; + let props = { data, source, ratings, type: "media" }; return (
(); const urlQueries = new URLSearchParams(search); const gridContainerRef = useRef(null); @@ -198,7 +198,7 @@ export default function WeightsTab({ username }: { username: string }) { onLayoutComplete={() => console.log("Layout complete!")} > {weights.list.map((data: any, key: number) => { - let props = { bookmarks, data, origin, ratings, showCreator: true, type: "weights" }; + let props = { bookmarks, data, ratings, showCreator: true, type: "weights", source }; return (
(); - const origin = search ? new URLSearchParams(search).get("origin") : ""; + const source = search ? new URLSearchParams(search).get("source") : ""; const history = useHistory(); const bookmarks = useBookmarks(); const ratings = useRatings(); @@ -72,7 +72,7 @@ export default function WeightPage({ remove, } = useWeightFetch({ onRemove: () => { - history.push(origin || ""); + history.push(source || ""); }, onSuccess: (res: any) => { bookmarks.gather({ res, key: "weight_token" }); // expand rather than replace for lazy loading @@ -98,6 +98,8 @@ export default function WeightPage({ fullLabel: weightTypeFull, } = weightTypeInfo; + const deleteWeight = () => remove(!!user?.can_ban_users); + function renderWeightComponent(weight: Weight) { switch (weight.weight_category) { case WeightCategory.TTS: @@ -570,7 +572,7 @@ export default function WeightPage({ content={() => ( <>{`Are you sure you want to delete "${title}"? This action cannot be undone.`} )} - onConfirm={remove} + onConfirm={deleteWeight} />
);