mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-06 02:00:46 +00:00
added ratings/bookmarks to WeightPage
This commit is contained in:
1 parent
c91512e046
commit
fc513eec11
9 files changed
+51
-34
No files matched your search
@@ -36,7 +36,7 @@ export default function AudioCard({
|
||||
type === "media"
|
||||
? `/media/${data.token}`
|
||||
: `/weight/${data.weight_token || data.details.entity_token}${
|
||||
origin ? "?origin=" + origin + "&ehhh=mehh" : ""
|
||||
origin ? "?origin=" + origin : ""
|
||||
}`;
|
||||
|
||||
const handleInnerClick = (event: any) => {
|
||||
|
||||
@@ -33,7 +33,7 @@ export default function ImageCard({
|
||||
type === "media"
|
||||
? `/media/${data.token}`
|
||||
: `/weight/${data.weight_token || data.details.entity_token}${
|
||||
origin ? "?origin=" + origin + "&ehhh=mehh" : ""
|
||||
origin ? "?origin=" + origin : ""
|
||||
}`;
|
||||
|
||||
const handleInnerClick = (event: any) => {
|
||||
|
||||
@@ -4,6 +4,7 @@ import { FetchStatus } from "@storyteller/components/src/api/_common/SharedFetch
|
||||
interface Props {
|
||||
checker: any,
|
||||
fetcher: any,
|
||||
modLibrary?: any,
|
||||
onPass?: any,
|
||||
onFail?: any,
|
||||
resultsKey: string
|
||||
@@ -23,6 +24,7 @@ interface Gather {
|
||||
export default function useBatchContent({
|
||||
checker,
|
||||
fetcher,
|
||||
modLibrary = (current: any, res: any, entity_token: string ) => current,
|
||||
onPass,
|
||||
onFail,
|
||||
resultsKey }: Props) {
|
||||
@@ -30,17 +32,21 @@ export default function useBatchContent({
|
||||
const [busyList, busyListSet] = useState<Library>({});
|
||||
const [status, statusSet] = useState(FetchStatus.ready);
|
||||
|
||||
const gather = ({ expand, key, modLibrary = (x: any, res: any, entity_token: string ) => x, res }: Gather) => {
|
||||
let tokens = res.results.map((item: any) => item[key]);
|
||||
// console.log("🪙",res.results, tokens);
|
||||
const gather = ({ expand, key, res }: Gather) => {
|
||||
let tokens = res.results ? res.results.map((item: any) => item[key]) : [res[key]];
|
||||
// console.log("🪙",fetcher);
|
||||
busyListSet(tokens.reduce((obj = {},token = "") => ({ ...obj, [token]: true }),{})); // add current batch to busy list
|
||||
fetcher("",{},{ tokens }).then((batchRes: any) => {
|
||||
// console.log("😡",batchRes,resultsKey);
|
||||
if (batchRes.success && batchRes[resultsKey]) {
|
||||
|
||||
console.log("🪙", batchRes.success && !!batchRes[resultsKey]);
|
||||
if (batchRes.success && !!batchRes[resultsKey]) {
|
||||
|
||||
let newBatch = batchRes[resultsKey].reduce((obj = {}, { entity_token = "", ...current }) => ({
|
||||
...obj,
|
||||
[entity_token]: { ...modLibrary(current, res, entity_token) }
|
||||
}),{});
|
||||
|
||||
console.log("😡", newBatch);
|
||||
busyListSet({}); // this should be a for each key in tokens delete from busyList, but this is fine for now
|
||||
listSet((list: any) => expand ? { ...list, ...newBatch } : newBatch);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,16 @@ export default function useBookmarks() {
|
||||
const { busyList, gather, list, status, toggle } = useBatchContent({
|
||||
checker: ({ maybe_bookmark_token }: any) => !!maybe_bookmark_token,
|
||||
fetcher: GetBookmarks,
|
||||
modLibrary: (current: any, res: any, entity_token: string) => {
|
||||
// let thing = res.results ? res.results.find((item: any, i: number) =>
|
||||
// item.weight_token === entity_token
|
||||
// )
|
||||
let { positive_rating_count } = res.results ? res.results.find((item: any, i: number) =>
|
||||
item.weight_token === entity_token
|
||||
).stats : res.stats;
|
||||
|
||||
return { ...current, positive_rating_count };
|
||||
},
|
||||
onPass: {
|
||||
fetch: (entity_token: string, entity_type: string, lib: any) => {
|
||||
let bookmarkToken = lib[entity_token].maybe_bookmark_token;
|
||||
|
||||
@@ -46,7 +46,7 @@ export default function useRatings() {
|
||||
resultsKey: "ratings"
|
||||
});
|
||||
|
||||
console.log("🔮",list);
|
||||
// console.log("🔮",list);
|
||||
|
||||
return { busyList, gather, list, status, toggleStatus, toggleStatusSet, toggle };
|
||||
};
|
||||
@@ -7,11 +7,14 @@ import { DeleteWeight } from "@storyteller/components/src/api/weights/DeleteWeig
|
||||
import { useCoverImgUpload } from "hooks";
|
||||
|
||||
interface Props {
|
||||
onRemove?: (x: any) => void;
|
||||
token: string;
|
||||
onSuccess?: (res: Weight) => any,
|
||||
onRemove?: (x: any) => void,
|
||||
token: string
|
||||
}
|
||||
|
||||
export default function useWeightFetch({ onRemove = () => {}, token }: Props) {
|
||||
const n = (x?: any) => {};
|
||||
|
||||
export default function useWeightFetch({ onRemove = n, onSuccess = n, token }: Props) {
|
||||
const [data, setData] = useState<Weight | undefined | null>(null);
|
||||
const [status, statusSet] = useState(FetchStatus.ready);
|
||||
const [writeStatus, writeStatusSet] = useState(FetchStatus.paused);
|
||||
@@ -77,13 +80,14 @@ export default function useWeightFetch({ onRemove = () => {}, token }: Props) {
|
||||
titleSet(resTitle);
|
||||
descriptionMDSet(description_markdown);
|
||||
visibilitySet(creator_set_visibility);
|
||||
onSuccess(res);
|
||||
setData(res);
|
||||
})
|
||||
.catch(err => {
|
||||
statusSet(FetchStatus.error);
|
||||
});
|
||||
}
|
||||
}, [status, token, data]);
|
||||
}, [status, onSuccess, token, data]);
|
||||
|
||||
return { coverImg, data, fetchError, isLoading, descriptionMD, onChange, remove, status, title, update, visibility, writeStatus };
|
||||
};
|
||||
@@ -38,18 +38,7 @@ export default function WeightsTab() {
|
||||
onInputChange: () => setShowMasonryGrid(false),
|
||||
onSuccess: (res) => {
|
||||
bookmarks.gather({ res, expand: true, key: "weight_token" }); // expand rather than replace for lazy loading
|
||||
ratings.gather({
|
||||
res,
|
||||
expand: true,
|
||||
key: "weight_token",
|
||||
modLibrary: (current: any, res: any, entity_token: string) => {
|
||||
let { positive_rating_count } = res.results.find((item: any, i: number) =>
|
||||
item.weight_token === entity_token
|
||||
).stats;
|
||||
|
||||
return { ...current, positive_rating_count };
|
||||
}
|
||||
});
|
||||
ratings.gather({ res, expand: true, key: "weight_token" });
|
||||
setShowMasonryGrid(true);
|
||||
},
|
||||
requestList: true,
|
||||
|
||||
@@ -49,8 +49,8 @@ export default function WeightsTab({ username }: { username: string }) {
|
||||
listSet,
|
||||
onInputChange: () => setShowMasonryGrid(false),
|
||||
onSuccess: (res) => {
|
||||
bookmarks.gather({ res, key: "weight_token" });
|
||||
// ratings.gather(res);
|
||||
bookmarks.gather({ res, key: "weight_token" }); // expand rather than replace for lazy loading
|
||||
ratings.gather({ res, key: "weight_token" });
|
||||
setShowMasonryGrid(true);
|
||||
},
|
||||
requestList: true,
|
||||
|
||||
@@ -33,7 +33,7 @@ import TtsInferencePanel from "./inference_panels/TtsInferencePanel";
|
||||
import Modal from "components/common/Modal";
|
||||
import SocialButton from "components/common/SocialButton";
|
||||
import Input from "components/common/Input";
|
||||
import { useBookmarks, useWeightFetch } from "hooks";
|
||||
import { useBookmarks, useWeightFetch, useRatings } from "hooks";
|
||||
import useWeightTypeInfo from "hooks/useWeightTypeInfo/useWeightTypeInfo";
|
||||
import moment from "moment";
|
||||
import WeightCoverImage from "components/common/WeightCoverImage";
|
||||
@@ -67,6 +67,8 @@ export default function WeightPage({
|
||||
const { weight_token } = useParams<{ weight_token: string }>();
|
||||
const origin = search ? new URLSearchParams(search).get("origin") : "";
|
||||
const history = useHistory();
|
||||
const bookmarks = useBookmarks();
|
||||
const ratings = useRatings();
|
||||
const {
|
||||
data: weight,
|
||||
descriptionMD,
|
||||
@@ -78,6 +80,10 @@ export default function WeightPage({
|
||||
onRemove: () => {
|
||||
history.push(origin || "");
|
||||
},
|
||||
onSuccess: (res: any) => {
|
||||
bookmarks.gather({ res, key: "weight_token" }); // expand rather than replace for lazy loading
|
||||
ratings.gather({ res, key: "weight_token" });
|
||||
},
|
||||
token: weight_token,
|
||||
});
|
||||
|
||||
@@ -88,8 +94,6 @@ export default function WeightPage({
|
||||
const [buttonLabel, setButtonLabel] = useState("Copy");
|
||||
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
|
||||
|
||||
const bookmarks = useBookmarks();
|
||||
|
||||
const bucketConfig = new BucketConfig();
|
||||
|
||||
const weightTypeInfo = useWeightTypeInfo(
|
||||
@@ -307,6 +311,7 @@ export default function WeightPage({
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// const handleBookmark = () => {
|
||||
// return bookmarks.toggle(); // this function checks if the bookmark exists, truthy = deleted, falsy = created
|
||||
// };
|
||||
@@ -375,20 +380,23 @@ export default function WeightPage({
|
||||
<div className="d-flex align-items-center gap-2">
|
||||
<LikeButton
|
||||
{...{
|
||||
busy: ratings.busyList[weight_token],
|
||||
entityToken: weight_token,
|
||||
entityType: "model_weight",
|
||||
likeCount: 1200,
|
||||
onToggle: bookmarks.toggle,
|
||||
likeCount: ratings?.list[weight_token]?.positive_rating_count || 0,
|
||||
initialToggled: (ratings?.list[weight_token]?.rating_value || "") === "positive",
|
||||
onToggle: ratings?.toggle,
|
||||
large: true,
|
||||
}}
|
||||
/>
|
||||
<BookmarkButton
|
||||
{...{
|
||||
busy: bookmarks.busyList[weight_token],
|
||||
entityToken: weight_token,
|
||||
entityType: "model_weight",
|
||||
onToggle: bookmarks.toggle,
|
||||
large: true,
|
||||
initialToggled: bookmarks.list[weight_token]
|
||||
onToggle: bookmarks?.toggle,
|
||||
initialToggled: bookmarks?.list[weight_token]?.maybe_bookmark_token,
|
||||
large: true
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user