From 74968b642c03c3f6357ae2539600c5cbb2b4e656 Mon Sep 17 00:00:00 2001 From: Victor Date: Sun, 24 Dec 2023 16:03:38 -0500 Subject: [PATCH] weight state separated for editing --- .../src/hooks/useWeightFetch/useWeightFetch.tsx | 11 +++++++++-- .../src/v2/view/pages/weight/WeightPage.tsx | 14 ++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/packages/fakeyou.com/src/hooks/useWeightFetch/useWeightFetch.tsx b/packages/fakeyou.com/src/hooks/useWeightFetch/useWeightFetch.tsx index 1e6bf237fe..fe46b9a76c 100644 --- a/packages/fakeyou.com/src/hooks/useWeightFetch/useWeightFetch.tsx +++ b/packages/fakeyou.com/src/hooks/useWeightFetch/useWeightFetch.tsx @@ -9,6 +9,9 @@ interface Props { export default function useWeightFetch({ token }: Props) { const [data, setData] = useState(null); const [status, statusSet] = useState(FetchStatus.ready); + const [title, titleSet] = useState(""); + const [visiblity, visiblitySet] = useState("public"); + const [descriptionMD, descriptionMDSet] = useState(); const isLoading = status === FetchStatus.ready || status === FetchStatus.in_progress; const fetchError = status === FetchStatus.error; @@ -17,9 +20,13 @@ export default function useWeightFetch({ token }: Props) { statusSet(FetchStatus.in_progress); GetWeight(token, {}) .then((res: any) => { + let { creator_set_visibility, description_markdown, title: resTitle, ...response } = res; console.log("🏋️", res, status); statusSet(FetchStatus.success); - setData(res); + titleSet(resTitle); + descriptionMDSet(description_markdown); + visiblitySet(creator_set_visibility); + setData(response); }) .catch(err => { statusSet(FetchStatus.error); @@ -27,5 +34,5 @@ export default function useWeightFetch({ token }: Props) { } }, [status, token, data]); - return { data, fetchError, isLoading, status }; + return { data, fetchError, isLoading, descriptionMD, status, title, visiblity }; }; \ No newline at end of file diff --git a/packages/fakeyou.com/src/v2/view/pages/weight/WeightPage.tsx b/packages/fakeyou.com/src/v2/view/pages/weight/WeightPage.tsx index 3c01b9a7aa..9e27ee47c0 100644 --- a/packages/fakeyou.com/src/v2/view/pages/weight/WeightPage.tsx +++ b/packages/fakeyou.com/src/v2/view/pages/weight/WeightPage.tsx @@ -64,7 +64,7 @@ export default function WeightPage({ inferenceJobsByCategory, }: WeightProps) { const { weight_token } = useParams<{ weight_token: string }>(); - const { data: weight, fetchError, isLoading, status } = useWeightFetch({ token: weight_token }); + const { data: weight, descriptionMD, fetchError, isLoading, title } = useWeightFetch({ token: weight_token }); const timeUpdated = moment(weight?.updated_at || "").fromNow(); const dateUpdated = moment(weight?.updated_at || "").format("LLL"); const dateCreated = moment(weight?.updated_at || "").format("LLL"); @@ -76,8 +76,6 @@ export default function WeightPage({ const bucketConfig = new BucketConfig(); - console.log("😎",status, isLoading); - const weightTypeInfo = useWeightTypeInfo( weight?.weights_type || WeightType.NONE ); @@ -312,7 +310,7 @@ export default function WeightPage({ const shareUrl = `https://fakeyou.com/weight/${weight.weight_token}`; const shareText = `Use FakeYou to generate speech as ${ - weight.title || "your favorite characters" + title || "your favorite characters" }!`; const handleCopyLink = () => { @@ -359,7 +357,7 @@ export default function WeightPage({ )}
-

{weight.title}

+

{title}

@@ -398,10 +396,10 @@ export default function WeightPage({
{renderWeightComponent(weight)}
- {weight.description_markdown !== "" && ( + { descriptionMD !== "" && (

Description

-

{weight.description_markdown}

+

{ descriptionMD }

)} @@ -576,7 +574,7 @@ export default function WeightPage({ show={isDeleteModalOpen} handleClose={closeDeleteModal} title="Delete Weight" - content={`Are you sure you want to delete "${weight.title}"? This action cannot be undone.`} + content={`Are you sure you want to delete "${title}"? This action cannot be undone.`} onConfirm={handleDelete} />