weight state separated for editing

This commit is contained in:
Victor committed 2023-12-24 16:03:38 -05:00
1 parent a055ac5533
commit 74968b642c
2 files changed
+15 -10

No files matched your search

@@ -9,6 +9,9 @@ interface Props {
export default function useWeightFetch({ token }: Props) {
const [data, setData] = useState<Weight | undefined | null>(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 };
};
@@ -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({
)}
<div>
<div className="d-flex gap-2 align-items-center flex-wrap">
<h1 className="fw-bold mb-2">{weight.title}</h1>
<h1 className="fw-bold mb-2">{title}</h1>
</div>
<div className="d-flex gap-3 flex-wrap align-items-center">
<div className="d-flex gap-2 align-items-center flex-wrap">
@@ -398,10 +396,10 @@ export default function WeightPage({
<div className="col-12 col-xl-8 d-flex flex-column gap-3">
<div className="media-wrapper">{renderWeightComponent(weight)}</div>
{weight.description_markdown !== "" && (
{ descriptionMD !== "" && (
<Panel padding={true}>
<h4 className="fw-semibold mb-3">Description</h4>
<p>{weight.description_markdown}</p>
<p>{ descriptionMD }</p>
</Panel>
)}
@@ -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}
/>
</div>