From a3a24733461acb97e8fcef221a838d9885327d2d Mon Sep 17 00:00:00 2001 From: BFlat Date: Fri, 19 Jan 2024 14:03:30 +0700 Subject: [PATCH] selectsearcher updates --- .../api/image_generation/EnqueueImageGen.ts | 2 +- .../common/Card/AudioCard/AudioCard.tsx | 239 ++++++++------ .../common/Card/ImageCard/ImageCard.tsx | 294 ++++++++++-------- .../common/LoadingSpinner/LoadingSpinner.tsx | 19 ++ .../components/common/LoadingSpinner/index.ts | 1 + .../src/components/common/Modal/Modal.scss | 12 + .../src/components/common/Modal/Modal.tsx | 21 +- .../components/common/Searcher/Searcher.scss | 13 +- .../components/common/Searcher/Searcher.tsx | 153 +++++---- .../common/SelectSearcher/SelectSearcher.tsx | 76 +++++ .../fakeyou.com/src/hooks/useToken/index.ts | 1 + .../src/hooks/useToken/useToken.tsx | 17 + .../v2/view/pages/dev_upload/DevUpload.tsx | 49 +-- .../src/v2/view/pages/search/SearchPage.tsx | 7 +- .../inference_panels/SdInferencePanel.tsx | 50 +-- 15 files changed, 589 insertions(+), 365 deletions(-) create mode 100644 packages/fakeyou.com/src/components/common/LoadingSpinner/LoadingSpinner.tsx create mode 100644 packages/fakeyou.com/src/components/common/LoadingSpinner/index.ts create mode 100644 packages/fakeyou.com/src/components/common/SelectSearcher/SelectSearcher.tsx create mode 100644 packages/fakeyou.com/src/hooks/useToken/index.ts create mode 100644 packages/fakeyou.com/src/hooks/useToken/useToken.tsx diff --git a/packages/components/src/api/image_generation/EnqueueImageGen.ts b/packages/components/src/api/image_generation/EnqueueImageGen.ts index 7bc060cebd..1e11349f67 100644 --- a/packages/components/src/api/image_generation/EnqueueImageGen.ts +++ b/packages/components/src/api/image_generation/EnqueueImageGen.ts @@ -3,7 +3,7 @@ import { ApiConfig } from "../ApiConfig"; export interface EnqueueImageGenRequest { uuid_idempotency_token: string; maybe_sd_model_token: string; - maybe_lora_model_token: string; + maybe_lora_model_token: string | null; maybe_prompt: string; maybe_n_prompt: string; maybe_seed: number; 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 487a7c0db1..f053141da6 100644 --- a/packages/fakeyou.com/src/components/common/Card/AudioCard/AudioCard.tsx +++ b/packages/fakeyou.com/src/components/common/Card/AudioCard/AudioCard.tsx @@ -1,5 +1,5 @@ import React from "react"; -import { Link } from "react-router-dom"; +import { Link, useHistory } from "react-router-dom"; import Card from "../Card"; import AudioPlayer from "components/common/AudioPlayer"; import useTimeAgo from "hooks/useTimeAgo"; @@ -12,15 +12,18 @@ import Button from "components/common/Button"; 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"; interface AudioCardProps { - bookmarks: any; + bookmarks?: any; data: any; origin?: string; - ratings: any; + ratings?: any; showCreator?: boolean; showCover?: boolean; type: "media" | "weights"; + inSearcher?: boolean; + onResultSelect?: () => void; } export default function AudioCard({ @@ -31,7 +34,11 @@ export default function AudioCard({ showCreator, showCover, type, + inSearcher = false, + onResultSelect, }: AudioCardProps) { + const { setToken, setWeightTitle } = useToken(); + const history = useHistory(); const linkUrl = type === "media" ? `/media/${data.token}` @@ -43,6 +50,12 @@ export default function AudioCard({ event.stopPropagation(); }; + const handleSearcherResultSelect = () => { + setToken(data.weight_token); + setWeightTitle && setWeightTitle(data.title); + onResultSelect && onResultSelect(); + }; + const timeAgo = useTimeAgo(data.created_at); const { label: weightBadgeLabel, color: weightBadgeColor } = @@ -72,57 +85,50 @@ export default function AudioCard({ } } - return ( - - - {type === "media" && ( - <> -
-
-
- -
+ const card = ( + + {type === "media" && ( + <> +
+
+
+
- -
- {data.origin.maybe_model - ? data.origin.maybe_model.title - : "Media Audio"} -
-

{timeAgo}

- +
+ {data.origin.maybe_model + ? data.origin.maybe_model.title + : "Media Audio"} +
+

{timeAgo}

+
-
+ -
- {showCreator && ( -
- -
- )} +
+
+ {showCreator && ( +
+ +
+ )} + + {ratings && (
-
- - )} + )} +
+ + )} - {type === "weights" && ( - <> -
- {showCover && ( - - )} + {type === "weights" && ( + <> +
+ {showCover && ( + + )} -
-
-
- -
+
+
+
+ +
+ {inSearcher ? ( +
+ )} +
-
-
-
- {data.title || data.details.maybe_weight_data.title} -
-

{timeAgo}

-
+
+
+
+ {data.title || data.details.maybe_weight_data.title} +
+

{timeAgo}

+
-
+
-
- {showCreator && ( -
- -
- )} +
+ {showCreator && ( +
+ +
+ )} + {ratings && (
+ )} + + {bookmarks && ( -
- - )} - - + )} +
+ + )} + + ); + + return ( + <> + {inSearcher ? ( + <>{card} + ) : ( + + {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 269f829073..98079ac2ea 100644 --- a/packages/fakeyou.com/src/components/common/Card/ImageCard/ImageCard.tsx +++ b/packages/fakeyou.com/src/components/common/Card/ImageCard/ImageCard.tsx @@ -18,6 +18,7 @@ interface ImageCardProps { ratings: any; showCreator?: boolean; type: "media" | "weights"; + inSearcher?: boolean; } export default function ImageCard({ @@ -27,6 +28,7 @@ export default function ImageCard({ showCreator, ratings, type, + inSearcher = false, }: ImageCardProps) { const history = useHistory(); const linkUrl = @@ -40,6 +42,14 @@ export default function ImageCard({ event.stopPropagation(); }; + const handleSearcherSelect = () => { + if (inSearcher) { + console.log("Searcher weight selected", data.weight_token); + } else { + return; + } + }; + const timeAgo = useTimeAgo(data.created_at); const { label: weightBadgeLabel, color: weightBadgeColor } = @@ -72,153 +82,173 @@ export default function ImageCard({ } } - return ( - - - {type === "media" && ( - <> - {data.weight_name} -
-
+ const card = ( + + {type === "media" && ( + <> + {data.weight_name} +
+
-
-
- -
-
- -
-
-

{timeAgo}

-
- -
- -
- {showCreator && ( -
- -
- )} - -
- -
-
+
+
+
- - )} - {type === "weights" && ( - <> - {data.title} -
- + + )} + + ); + + return ( + <> + {inSearcher ? ( + <>{card} + ) : ( + + {card} + + )} + ); } diff --git a/packages/fakeyou.com/src/components/common/LoadingSpinner/LoadingSpinner.tsx b/packages/fakeyou.com/src/components/common/LoadingSpinner/LoadingSpinner.tsx new file mode 100644 index 0000000000..e5d1697afa --- /dev/null +++ b/packages/fakeyou.com/src/components/common/LoadingSpinner/LoadingSpinner.tsx @@ -0,0 +1,19 @@ +import React from "react"; + +interface LoadingSpinnerProps { + className?: string; +} + +export default function LoadingSpinner({ className }: LoadingSpinnerProps) { + return ( +
+
+ Loading... +
+
+ ); +} diff --git a/packages/fakeyou.com/src/components/common/LoadingSpinner/index.ts b/packages/fakeyou.com/src/components/common/LoadingSpinner/index.ts new file mode 100644 index 0000000000..443fa62feb --- /dev/null +++ b/packages/fakeyou.com/src/components/common/LoadingSpinner/index.ts @@ -0,0 +1 @@ +export { default } from "./LoadingSpinner"; diff --git a/packages/fakeyou.com/src/components/common/Modal/Modal.scss b/packages/fakeyou.com/src/components/common/Modal/Modal.scss index 13d5e25478..ddaca1ad60 100644 --- a/packages/fakeyou.com/src/components/common/Modal/Modal.scss +++ b/packages/fakeyou.com/src/components/common/Modal/Modal.scss @@ -51,3 +51,15 @@ .modal-footer { border-top: 1px solid lighten($panel, 8%); } + +@media screen and (max-width: 992px) { + .modal-dialog-mobile-fullscreen { + margin: 0; + max-width: 100%; + height: 100%; + + .modal-content { + height: 100%; + } + } +} diff --git a/packages/fakeyou.com/src/components/common/Modal/Modal.tsx b/packages/fakeyou.com/src/components/common/Modal/Modal.tsx index edbbbc1b92..6268bdd253 100644 --- a/packages/fakeyou.com/src/components/common/Modal/Modal.tsx +++ b/packages/fakeyou.com/src/components/common/Modal/Modal.tsx @@ -20,6 +20,7 @@ interface ModalProps { padding?: boolean; large?: boolean; position?: "center" | "top"; + mobileFullscreen?: boolean; } const Modal: React.FC = ({ @@ -37,6 +38,7 @@ const Modal: React.FC = ({ padding = true, large = false, position = "center", + mobileFullscreen = false, }) => { const fadeIn = useSpring({ opacity: show ? 1 : 0, @@ -80,26 +82,27 @@ const Modal: React.FC = ({
-
- { !noHeader &&
+
+ {!noHeader && ( +
{icon && } - { title || "" } + {title || ""}
-
- } -
- { Content && } + )} +
+ {Content && }
{showButtons && (
diff --git a/packages/fakeyou.com/src/components/common/Searcher/Searcher.scss b/packages/fakeyou.com/src/components/common/Searcher/Searcher.scss index 10fd7bdd07..cd4a12b071 100644 --- a/packages/fakeyou.com/src/components/common/Searcher/Searcher.scss +++ b/packages/fakeyou.com/src/components/common/Searcher/Searcher.scss @@ -2,7 +2,16 @@ .searcher-container { &.in-modal { - overflow: hidden; - max-height: 50vh; + overflow-x: hidden; + overflow-y: auto; + max-height: 65vh; + } +} + +@media screen and (max-width: 992px) { + .searcher-container { + &.in-modal { + max-height: 70vh; + } } } diff --git a/packages/fakeyou.com/src/components/common/Searcher/Searcher.tsx b/packages/fakeyou.com/src/components/common/Searcher/Searcher.tsx index f9f8193bd8..e3626d46cf 100644 --- a/packages/fakeyou.com/src/components/common/Searcher/Searcher.tsx +++ b/packages/fakeyou.com/src/components/common/Searcher/Searcher.tsx @@ -1,80 +1,127 @@ -import React, { useRef } from "react"; +import React, { useCallback, useRef, useState } from "react"; import Input from "../Input"; import { faSearch } from "@fortawesome/pro-solid-svg-icons"; import MasonryGrid from "../MasonryGrid/MasonryGrid"; -import MediaCards from "../Card/MediaCards"; import "./Searcher.scss"; +import { Weight } from "@storyteller/components/src/api/weights/GetWeight"; +import { useBookmarks, useRatings } from "hooks"; +import { SearchWeights } from "@storyteller/components/src/api/weights/SearchWeights"; +import debounce from "lodash.debounce"; +import WeightsCards from "../Card/WeightsCards"; +import LoadingSpinner from "../LoadingSpinner"; interface SearcherProps { - data?: any[]; type?: "page" | "modal"; dataType?: "media" | "weights"; + weightType?: string; + onResultSelect?: () => void; + weightTypeFilter?: any; } export default function Searcher({ - data, type = "page", - dataType = "media", + dataType = "weights", + weightType = "all", + onResultSelect, + weightTypeFilter, }: SearcherProps) { const gridContainerRef = useRef(null); + const [searchTerm, setSearchTerm] = useState(""); + const [foundWeights, setFoundWeights] = useState([]); + const [isSearching, setIsSearching] = useState(false); + const [searchCompleted, setSearchCompleted] = useState(0); + const bookmarks = useBookmarks(); + const ratings = useRatings(); + + const handleInputChange = (e: any) => { + const newValue = e.target.value; + setSearchTerm(newValue); + debouncedDoSearch(newValue); + }; + + const doSearch = useCallback( + async (value: string) => { + let request: any = { + search_term: value, + }; + + setIsSearching(true); + + if (weightType !== "all") { + request[weightTypeFilter] = weightType; + } + + let response = await SearchWeights(request); + + if (response.success) { + let weights = [...response.weights]; + setFoundWeights(weights); + setSearchCompleted(prev => prev + 1); + } else { + setFoundWeights([]); + } + + setIsSearching(false); + }, + [setFoundWeights, weightType, setSearchCompleted, weightTypeFilter] + ); + + // eslint-disable-next-line react-hooks/exhaustive-deps + const debouncedDoSearch = useCallback( + debounce(searchTerm => { + doSearch(searchTerm); + }, 250), + [doSearch] + ); return (
- +
{/* Result Cards */} - console.log("Layout complete!")} - > - {data && - dataType === "media" && - data.map((data: any, key: number) => { - let props = { - data, - origin, - type: "media", - showCreator: true, - }; + {isSearching ? ( + + ) : ( + console.log("Layout complete!")} + > + {dataType === "weights" && + foundWeights.map((data: any, key: number) => { + let props = { + data, + bookmarks, + ratings, + showCreator: true, + type: "weights", + inSearcher: true, + onResultSelect, + }; - return ( -
- -
- ); - })} - - {data && - dataType === "weights" && - data.map((data: any, key: number) => { - let props = { - data, - origin, - type: "media", - showCreator: true, - }; - - return ( -
- -
- ); - })} -
+ return ( +
+ +
+ ); + })} +
+ )}
); diff --git a/packages/fakeyou.com/src/components/common/SelectSearcher/SelectSearcher.tsx b/packages/fakeyou.com/src/components/common/SelectSearcher/SelectSearcher.tsx new file mode 100644 index 0000000000..7ab3beec56 --- /dev/null +++ b/packages/fakeyou.com/src/components/common/SelectSearcher/SelectSearcher.tsx @@ -0,0 +1,76 @@ +import React, { useState } from "react"; +import Searcher from "../Searcher"; +import Modal from "../Modal"; +import NonRouteTabs from "../Tabs/NonRouteTabs"; +import Input from "../Input"; +import Button from "../Button"; +import useToken from "hooks/useToken"; + +interface SelectSearcherProps { + label?: string; + weightTypeFilter?: string; +} + +export default function SelectSearcher({ + label, + weightTypeFilter, +}: SelectSearcherProps) { + const [isModalOpen, setIsModalOpen] = useState(false); + const { weightTitle } = useToken(); + + const openModal = () => { + setIsModalOpen(true); + }; + + const closeModal = () => { + setIsModalOpen(false); + }; + + const searchTabs = [ + { + label: "All LoRA Weights", + content: ( + + ), + padding: true, + }, + { + label: "Bookmarked", + content: , + padding: true, + }, + ]; + return ( + <> +
+ {label && } + +
+ +
+
+ + } + showButtons={false} + padding={false} + large={true} + position="top" + mobileFullscreen={true} + /> + + ); +} diff --git a/packages/fakeyou.com/src/hooks/useToken/index.ts b/packages/fakeyou.com/src/hooks/useToken/index.ts new file mode 100644 index 0000000000..340992423f --- /dev/null +++ b/packages/fakeyou.com/src/hooks/useToken/index.ts @@ -0,0 +1 @@ +export { default } from "./useToken"; diff --git a/packages/fakeyou.com/src/hooks/useToken/useToken.tsx b/packages/fakeyou.com/src/hooks/useToken/useToken.tsx new file mode 100644 index 0000000000..31eb2940e7 --- /dev/null +++ b/packages/fakeyou.com/src/hooks/useToken/useToken.tsx @@ -0,0 +1,17 @@ +import { create } from "zustand"; + +interface TokenState { + token: string | null; + setToken: (newToken: string | null) => void; + weightTitle?: string | null; + setWeightTitle?: (newWeightTitle: string | null) => void; +} + +const useToken = create(set => ({ + token: null, + setToken: newToken => set({ token: newToken }), + weightTitle: null, + setWeightTitle: newWeightTitle => set({ weightTitle: newWeightTitle }), +})); + +export default useToken; diff --git a/packages/fakeyou.com/src/v2/view/pages/dev_upload/DevUpload.tsx b/packages/fakeyou.com/src/v2/view/pages/dev_upload/DevUpload.tsx index ee7197177e..e674ac038d 100644 --- a/packages/fakeyou.com/src/v2/view/pages/dev_upload/DevUpload.tsx +++ b/packages/fakeyou.com/src/v2/view/pages/dev_upload/DevUpload.tsx @@ -4,36 +4,40 @@ import PageHeader from "components/layout/PageHeader"; import React, { useState } from "react"; import { Button } from "components/common"; import { faUpload } from "@fortawesome/pro-solid-svg-icons"; -import { UploadMedia, UploadMediaResponse } from "@storyteller/components/src/api/media_files/UploadMedia"; +import { + UploadMedia, + UploadMediaResponse, +} from "@storyteller/components/src/api/media_files/UploadMedia"; import { v4 as uuidv4 } from "uuid"; -import { Link } from 'react-router-dom'; +import { Link } from "react-router-dom"; +import SelectSearcher from "components/common/SelectSearcher/SelectSearcher"; interface DevUploadProps {} export default function DevUpload(props: DevUploadProps) { const [file, fileSet] = useState(null); - const [tokens,tokensSet] = useState([]); + const [tokens, tokensSet] = useState([]); const handleFileChange = (event: any) => { fileSet(event.target.files[0]); }; - const handleUpload = () => { - if (file) UploadMedia({ - uuid_idempotency_token: uuidv4(), - file, - source: "file", - }) // if there an audio file it uploads here - .then((res: UploadMediaResponse) => { - if ("media_file_token" in res) { - console.log("📁 upload response:", res); - tokensSet([res.media_file_token, ...tokens]); - fileSet(null); - } - }); + if (file) + UploadMedia({ + uuid_idempotency_token: uuidv4(), + file, + source: "file", + }) // if there an audio file it uploads here + .then((res: UploadMediaResponse) => { + if ("media_file_token" in res) { + console.log("📁 upload response:", res); + tokensSet([res.media_file_token, ...tokens]); + fileSet(null); + } + }); else console.log("🥺 no file"); - } + }; return ( @@ -59,12 +63,15 @@ export default function DevUpload(props: DevUploadProps) { />

Your uploads

- { - tokens.map((token: string, key: number) => - { token }) - } + {tokens.map((token: string, key: number) => ( + {token} + ))}
+ +
+ +
); } diff --git a/packages/fakeyou.com/src/v2/view/pages/search/SearchPage.tsx b/packages/fakeyou.com/src/v2/view/pages/search/SearchPage.tsx index b720c788e5..11c2c10397 100644 --- a/packages/fakeyou.com/src/v2/view/pages/search/SearchPage.tsx +++ b/packages/fakeyou.com/src/v2/view/pages/search/SearchPage.tsx @@ -2,7 +2,6 @@ import React, { useCallback, useEffect, useRef, useState } from "react"; import Container from "components/common/Container"; import PageHeader from "components/layout/PageHeader"; import Panel from "components/common/Panel"; -// import ModelTags from "components/common/ModelTags"; import { SearchWeights } from "@storyteller/components/src/api/weights/SearchWeights"; import { Weight } from "@storyteller/components/src/api/weights/GetWeight"; import { useLocation } from "react-router-dom"; @@ -25,6 +24,7 @@ import Select from "components/common/Select"; export default function SearchPage() { const [foundWeights, setFoundWeights] = useState([]); const [weightType, setWeightType] = useState("all"); + const [searchCompleted, setSearchCompleted] = useState(0); const bookmarks = useBookmarks(); const ratings = useRatings(); @@ -50,6 +50,7 @@ export default function SearchPage() { if (response.success) { let weights = [...response.weights]; setFoundWeights(weights); + setSearchCompleted(prev => prev + 1); } else { setFoundWeights([]); } @@ -130,7 +131,7 @@ export default function SearchPage() { panel={false} /> -
+
-
-
+ {/* Checkpoint Use weight token */} {/*
- - {/* Additional LoRA Weight Modal */} - } - showButtons={false} - padding={false} - large={true} - position="top" - /> ); }