mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-17 07:04:36 +00:00
selectsearcher updates
This commit is contained in:
1 parent
2bc1c27bb6
commit
a3a2473346
15 files changed
+589
-365
No files matched your search
@@ -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;
|
||||
|
||||
@@ -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 (
|
||||
<Link
|
||||
{...{
|
||||
to: linkUrl,
|
||||
state: { origin },
|
||||
}}
|
||||
>
|
||||
<Card padding={true} canHover={true}>
|
||||
{type === "media" && (
|
||||
<>
|
||||
<div className="mb-3">
|
||||
<div className="d-flex align-items-center">
|
||||
<div className="d-flex flex-grow-1 align-items-center gap-2">
|
||||
<Badge label="Audio" color="teal" />
|
||||
</div>
|
||||
const card = (
|
||||
<Card padding={true} canHover={true} onClick={handleSearcherResultSelect}>
|
||||
{type === "media" && (
|
||||
<>
|
||||
<div className="mb-3">
|
||||
<div className="d-flex align-items-center">
|
||||
<div className="d-flex flex-grow-1 align-items-center gap-2">
|
||||
<Badge label="Audio" color="teal" />
|
||||
</div>
|
||||
|
||||
<h6 className="fw-semibold text-white mb-1 mt-3">
|
||||
{data.origin.maybe_model
|
||||
? data.origin.maybe_model.title
|
||||
: "Media Audio"}
|
||||
</h6>
|
||||
<p className="fs-7 opacity-75">{timeAgo}</p>
|
||||
</div>
|
||||
|
||||
<AudioPlayer src={data.public_bucket_path} id={data.token} />
|
||||
<h6 className="fw-semibold text-white mb-1 mt-3">
|
||||
{data.origin.maybe_model
|
||||
? data.origin.maybe_model.title
|
||||
: "Media Audio"}
|
||||
</h6>
|
||||
<p className="fs-7 opacity-75">{timeAgo}</p>
|
||||
</div>
|
||||
|
||||
<hr className="my-3" />
|
||||
<AudioPlayer src={data.public_bucket_path} id={data.token} />
|
||||
|
||||
<div
|
||||
className="d-flex align-items-center gap-2"
|
||||
onClick={handleInnerClick}
|
||||
>
|
||||
{showCreator && (
|
||||
<div className="flex-grow-1">
|
||||
<CreatorName
|
||||
displayName={
|
||||
data.maybe_creator?.display_name || "Anonymous"
|
||||
}
|
||||
gravatarHash={data.maybe_creator?.gravatar_hash || null}
|
||||
avatarIndex={
|
||||
data.maybe_creator?.default_avatar.image_index || 0
|
||||
}
|
||||
backgroundIndex={
|
||||
data.maybe_creator?.default_avatar.color_index || 0
|
||||
}
|
||||
username={data.maybe_creator?.username || "anonymous"}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<hr className="my-3" />
|
||||
|
||||
<div
|
||||
className="d-flex align-items-center gap-2"
|
||||
onClick={handleInnerClick}
|
||||
>
|
||||
{showCreator && (
|
||||
<div className="flex-grow-1">
|
||||
<CreatorName
|
||||
displayName={data.maybe_creator?.display_name || "Anonymous"}
|
||||
gravatarHash={data.maybe_creator?.gravatar_hash || null}
|
||||
avatarIndex={
|
||||
data.maybe_creator?.default_avatar.image_index || 0
|
||||
}
|
||||
backgroundIndex={
|
||||
data.maybe_creator?.default_avatar.color_index || 0
|
||||
}
|
||||
username={data.maybe_creator?.username || "anonymous"}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{ratings && (
|
||||
<div>
|
||||
<LikeButton
|
||||
{...{
|
||||
@@ -133,68 +139,83 @@ export default function AudioCard({
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{type === "weights" && (
|
||||
<>
|
||||
<div className="d-flex">
|
||||
{showCover && (
|
||||
<WeightCoverImage
|
||||
src={coverImage}
|
||||
height={110}
|
||||
width={110}
|
||||
coverIndex={data?.cover_image?.default_cover?.image_index}
|
||||
/>
|
||||
)}
|
||||
{type === "weights" && (
|
||||
<>
|
||||
<div className="d-flex">
|
||||
{showCover && (
|
||||
<WeightCoverImage
|
||||
src={coverImage}
|
||||
height={110}
|
||||
width={110}
|
||||
coverIndex={data?.cover_image?.default_cover?.image_index}
|
||||
/>
|
||||
)}
|
||||
|
||||
<div className="flex-grow-1">
|
||||
<div className="d-flex align-items-center">
|
||||
<div className="d-flex flex-grow-1">
|
||||
<Badge label={weightBadgeLabel} color={weightBadgeColor} />
|
||||
</div>
|
||||
<div className="flex-grow-1">
|
||||
<div className="d-flex align-items-center">
|
||||
<div className="d-flex flex-grow-1">
|
||||
<Badge label={weightBadgeLabel} color={weightBadgeColor} />
|
||||
</div>
|
||||
{inSearcher ? (
|
||||
<Button
|
||||
icon={faArrowRight}
|
||||
iconFlip={true}
|
||||
variant="link"
|
||||
label="Select"
|
||||
className="fs-7"
|
||||
onClick={handleSearcherResultSelect}
|
||||
/>
|
||||
) : (
|
||||
<Button
|
||||
icon={faArrowRight}
|
||||
iconFlip={true}
|
||||
variant="link"
|
||||
label="Use"
|
||||
className="fs-7"
|
||||
to={linkUrl}
|
||||
onClick={() => {
|
||||
history.push(linkUrl);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="d-flex align-items-center mt-3">
|
||||
<div className="flex-grow-1">
|
||||
<h6 className="fw-semibold text-white mb-1">
|
||||
{data.title || data.details.maybe_weight_data.title}
|
||||
</h6>
|
||||
<p className="fs-7 opacity-75">{timeAgo}</p>
|
||||
</div>
|
||||
<div className="d-flex align-items-center mt-3">
|
||||
<div className="flex-grow-1">
|
||||
<h6 className="fw-semibold text-white mb-1">
|
||||
{data.title || data.details.maybe_weight_data.title}
|
||||
</h6>
|
||||
<p className="fs-7 opacity-75">{timeAgo}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr className="my-3" />
|
||||
<hr className="my-3" />
|
||||
|
||||
<div
|
||||
className="d-flex align-items-center gap-2"
|
||||
onClick={handleInnerClick}
|
||||
>
|
||||
{showCreator && (
|
||||
<div className="flex-grow-1">
|
||||
<CreatorName
|
||||
displayName={data.creator?.display_name || "Anonymous"}
|
||||
gravatarHash={data.creator?.gravatar_hash || null}
|
||||
avatarIndex={data.creator?.default_avatar.image_index || 0}
|
||||
backgroundIndex={
|
||||
data.creator?.default_avatar.color_index || 0
|
||||
}
|
||||
username={data.creator?.username || "anonymous"}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div
|
||||
className="d-flex align-items-center gap-2"
|
||||
onClick={handleInnerClick}
|
||||
>
|
||||
{showCreator && (
|
||||
<div className="flex-grow-1">
|
||||
<CreatorName
|
||||
displayName={data.creator?.display_name || "Anonymous"}
|
||||
gravatarHash={data.creator?.gravatar_hash || null}
|
||||
avatarIndex={data.creator?.default_avatar.image_index || 0}
|
||||
backgroundIndex={
|
||||
data.creator?.default_avatar.color_index || 0
|
||||
}
|
||||
username={data.creator?.username || "anonymous"}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{ratings && (
|
||||
<div>
|
||||
<LikeButton
|
||||
{...{
|
||||
@@ -205,6 +226,9 @@ export default function AudioCard({
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{bookmarks && (
|
||||
<BookmarkButton
|
||||
{...{
|
||||
...bookmarks.makeProps({
|
||||
@@ -213,10 +237,27 @@ export default function AudioCard({
|
||||
}),
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</Card>
|
||||
</Link>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</Card>
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
{inSearcher ? (
|
||||
<>{card}</>
|
||||
) : (
|
||||
<Link
|
||||
{...{
|
||||
to: linkUrl,
|
||||
state: { origin },
|
||||
}}
|
||||
>
|
||||
{card}
|
||||
</Link>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -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 (
|
||||
<Link
|
||||
{...{
|
||||
to: linkUrl,
|
||||
state: { origin },
|
||||
}}
|
||||
>
|
||||
<Card padding={false} canHover={true}>
|
||||
{type === "media" && (
|
||||
<>
|
||||
<img src={coverImage} alt={data.weight_name} className="card-img" />
|
||||
<div className="card-img-overlay">
|
||||
<div className="card-img-gradient" />
|
||||
const card = (
|
||||
<Card padding={false} canHover={true}>
|
||||
{type === "media" && (
|
||||
<>
|
||||
<img src={coverImage} alt={data.weight_name} className="card-img" />
|
||||
<div className="card-img-overlay">
|
||||
<div className="card-img-gradient" />
|
||||
|
||||
<div className="d-flex align-items-center">
|
||||
<div className="d-flex flex-grow-1">
|
||||
<Badge label="Image" color="ultramarine" overlay={true} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="card-img-overlay-text">
|
||||
<div>
|
||||
<p className="fs-7 opacity-75 mb-0">{timeAgo}</p>
|
||||
</div>
|
||||
|
||||
<hr className="my-2" />
|
||||
|
||||
<div
|
||||
className="d-flex align-items-center gap-2"
|
||||
onClick={handleInnerClick}
|
||||
>
|
||||
{showCreator && (
|
||||
<div className="flex-grow-1">
|
||||
<CreatorName
|
||||
displayName={
|
||||
data.maybe_creator?.display_name || "Anonymous"
|
||||
}
|
||||
gravatarHash={data.maybe_creator?.gravatar_hash || null}
|
||||
avatarIndex={
|
||||
data.maybe_creator?.default_avatar.image_index || 0
|
||||
}
|
||||
backgroundIndex={
|
||||
data.maybe_creator?.default_avatar.color_index || 0
|
||||
}
|
||||
username={data.maybe_creator?.username || "anonymous"}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div>
|
||||
<LikeButton
|
||||
{...{
|
||||
...ratings.makeProps({
|
||||
entityToken: data.token,
|
||||
entityType: "media_file",
|
||||
}),
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="d-flex align-items-center">
|
||||
<div className="d-flex flex-grow-1">
|
||||
<Badge label="Image" color="ultramarine" overlay={true} />
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{type === "weights" && (
|
||||
<>
|
||||
<img src={coverImage} alt={data.title} className="card-img" />
|
||||
<div className="card-img-overlay">
|
||||
<div className="card-img-gradient" />
|
||||
<div className="d-flex align-items-center">
|
||||
<div className="d-flex flex-grow-1">
|
||||
<Badge
|
||||
label={weightBadgeLabel}
|
||||
color={weightBadgeColor}
|
||||
overlay={true}
|
||||
/>
|
||||
</div>
|
||||
<Button
|
||||
{...{
|
||||
className: "fs-7",
|
||||
icon: faArrowRight,
|
||||
label: "Use",
|
||||
onClick: () => {
|
||||
history.push(linkUrl); // programatically link to avoid "<a> cannot appear as a descendant of <a>" errors
|
||||
},
|
||||
variant: "link",
|
||||
}}
|
||||
/>
|
||||
<div className="card-img-overlay-text">
|
||||
<div>
|
||||
<p className="fs-7 opacity-75 mb-0">{timeAgo}</p>
|
||||
</div>
|
||||
|
||||
<div className="card-img-overlay-text">
|
||||
<div className="d-flex align-items-center mt-3">
|
||||
<hr className="my-2" />
|
||||
|
||||
<div
|
||||
className="d-flex align-items-center gap-2"
|
||||
onClick={handleInnerClick}
|
||||
>
|
||||
{showCreator && (
|
||||
<div className="flex-grow-1">
|
||||
<h6 className="fw-semibold text-white mb-1">
|
||||
{data.title || data.details?.maybe_weight_data?.title}
|
||||
</h6>
|
||||
<p className="fs-7 opacity-75 mb-0">{timeAgo}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr className="my-2" />
|
||||
|
||||
<div
|
||||
className="d-flex align-items-center gap-2"
|
||||
onClick={handleInnerClick}
|
||||
>
|
||||
{showCreator && (
|
||||
<div className="flex-grow-1">
|
||||
<CreatorName
|
||||
displayName={data.creator?.display_name || "Anonymous"}
|
||||
gravatarHash={data.creator?.gravatar_hash || null}
|
||||
avatarIndex={
|
||||
data.creator?.default_avatar.image_index || 0
|
||||
}
|
||||
backgroundIndex={
|
||||
data.creator?.default_avatar.color_index || 0
|
||||
}
|
||||
username={data.creator?.username || "anonymous"}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div>
|
||||
<LikeButton
|
||||
{...{
|
||||
...ratings.makeProps({
|
||||
entityToken: data.weight_token,
|
||||
entityType: "model_weight",
|
||||
}),
|
||||
}}
|
||||
<CreatorName
|
||||
displayName={
|
||||
data.maybe_creator?.display_name || "Anonymous"
|
||||
}
|
||||
gravatarHash={data.maybe_creator?.gravatar_hash || null}
|
||||
avatarIndex={
|
||||
data.maybe_creator?.default_avatar.image_index || 0
|
||||
}
|
||||
backgroundIndex={
|
||||
data.maybe_creator?.default_avatar.color_index || 0
|
||||
}
|
||||
username={data.maybe_creator?.username || "anonymous"}
|
||||
/>
|
||||
</div>
|
||||
<BookmarkButton
|
||||
)}
|
||||
|
||||
<div>
|
||||
<LikeButton
|
||||
{...{
|
||||
...bookmarks.makeProps({
|
||||
entityToken: data.weight_token,
|
||||
entityType: "model_weight",
|
||||
...ratings.makeProps({
|
||||
entityToken: data.token,
|
||||
entityType: "media_file",
|
||||
}),
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</Card>
|
||||
</Link>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{type === "weights" && (
|
||||
<>
|
||||
<img src={coverImage} alt={data.title} className="card-img" />
|
||||
<div className="card-img-overlay">
|
||||
<div className="card-img-gradient" />
|
||||
<div className="d-flex align-items-center">
|
||||
<div className="d-flex flex-grow-1">
|
||||
<Badge
|
||||
label={weightBadgeLabel}
|
||||
color={weightBadgeColor}
|
||||
overlay={true}
|
||||
/>
|
||||
</div>
|
||||
{inSearcher ? (
|
||||
<Button
|
||||
icon={faArrowRight}
|
||||
iconFlip={true}
|
||||
variant="link"
|
||||
label="Select"
|
||||
className="fs-7"
|
||||
onClick={handleSearcherSelect}
|
||||
/>
|
||||
) : (
|
||||
<Button
|
||||
icon={faArrowRight}
|
||||
iconFlip={true}
|
||||
variant="link"
|
||||
label="Use"
|
||||
className="fs-7"
|
||||
onClick={() => {
|
||||
history.push(linkUrl);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="card-img-overlay-text">
|
||||
<div className="d-flex align-items-center mt-3">
|
||||
<div className="flex-grow-1">
|
||||
<h6 className="fw-semibold text-white mb-1">
|
||||
{data.title || data.details?.maybe_weight_data?.title}
|
||||
</h6>
|
||||
<p className="fs-7 opacity-75 mb-0">{timeAgo}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr className="my-2" />
|
||||
|
||||
<div
|
||||
className="d-flex align-items-center gap-2"
|
||||
onClick={handleInnerClick}
|
||||
>
|
||||
{showCreator && (
|
||||
<div className="flex-grow-1">
|
||||
<CreatorName
|
||||
displayName={data.creator?.display_name || "Anonymous"}
|
||||
gravatarHash={data.creator?.gravatar_hash || null}
|
||||
avatarIndex={
|
||||
data.creator?.default_avatar.image_index || 0
|
||||
}
|
||||
backgroundIndex={
|
||||
data.creator?.default_avatar.color_index || 0
|
||||
}
|
||||
username={data.creator?.username || "anonymous"}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div>
|
||||
<LikeButton
|
||||
{...{
|
||||
...ratings.makeProps({
|
||||
entityToken: data.weight_token,
|
||||
entityType: "model_weight",
|
||||
}),
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<BookmarkButton
|
||||
{...{
|
||||
...bookmarks.makeProps({
|
||||
entityToken: data.weight_token,
|
||||
entityType: "model_weight",
|
||||
}),
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</Card>
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
{inSearcher ? (
|
||||
<>{card}</>
|
||||
) : (
|
||||
<Link
|
||||
{...{
|
||||
to: linkUrl,
|
||||
state: { origin },
|
||||
}}
|
||||
>
|
||||
{card}
|
||||
</Link>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import React from "react";
|
||||
|
||||
interface LoadingSpinnerProps {
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export default function LoadingSpinner({ className }: LoadingSpinnerProps) {
|
||||
return (
|
||||
<div
|
||||
className={`pt-2 d-flex justify-content-center overflow-hidden ${
|
||||
className ? className : ""
|
||||
}`.trim()}
|
||||
>
|
||||
<div className="spinner-border text-light" role="status">
|
||||
<span className="visually-hidden">Loading...</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export { default } from "./LoadingSpinner";
|
||||
@@ -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%;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ interface ModalProps {
|
||||
padding?: boolean;
|
||||
large?: boolean;
|
||||
position?: "center" | "top";
|
||||
mobileFullscreen?: boolean;
|
||||
}
|
||||
|
||||
const Modal: React.FC<ModalProps> = ({
|
||||
@@ -37,6 +38,7 @@ const Modal: React.FC<ModalProps> = ({
|
||||
padding = true,
|
||||
large = false,
|
||||
position = "center",
|
||||
mobileFullscreen = false,
|
||||
}) => {
|
||||
const fadeIn = useSpring({
|
||||
opacity: show ? 1 : 0,
|
||||
@@ -80,26 +82,27 @@ const Modal: React.FC<ModalProps> = ({
|
||||
<div
|
||||
className={`modal-dialog ${
|
||||
position === "center" ? "modal-dialog-centered" : ""
|
||||
} ${large ? "modal-xl" : ""} ${
|
||||
autoWidth ? "modal-width-auto" : ""
|
||||
} ${large ? "modal-xl" : ""} ${autoWidth ? "modal-width-auto" : ""} ${
|
||||
mobileFullscreen ? "modal-dialog-mobile-fullscreen" : ""
|
||||
}`.trim()}
|
||||
>
|
||||
<div className="modal-content">
|
||||
{ !noHeader && <header className="modal-header">
|
||||
<div className={`modal-content`.trim()}>
|
||||
{!noHeader && (
|
||||
<header className="modal-header">
|
||||
<h5 className="modal-title">
|
||||
{icon && <FontAwesomeIcon icon={icon} className="me-3" />}
|
||||
{ title || "" }
|
||||
{title || ""}
|
||||
</h5>
|
||||
<button
|
||||
<button
|
||||
type="button"
|
||||
className="btn-close"
|
||||
onClick={handleClose}
|
||||
aria-label="Close"
|
||||
/>
|
||||
</header>
|
||||
}
|
||||
<div {...{ className: `modal-body ${padding ? "p-3" : ""}`}}>
|
||||
{ Content && <Content {...{ handleClose }} /> }
|
||||
)}
|
||||
<div {...{ className: `modal-body ${padding ? "p-3" : ""}` }}>
|
||||
{Content && <Content {...{ handleClose }} />}
|
||||
</div>
|
||||
{showButtons && (
|
||||
<div className="modal-footer">
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<HTMLDivElement | null>(null);
|
||||
const [searchTerm, setSearchTerm] = useState("");
|
||||
const [foundWeights, setFoundWeights] = useState<Weight[]>([]);
|
||||
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 (
|
||||
<div>
|
||||
<Input icon={faSearch} placeholder="Search..." />
|
||||
<Input
|
||||
icon={faSearch}
|
||||
placeholder="Search..."
|
||||
value={searchTerm}
|
||||
onChange={handleInputChange}
|
||||
className="mb-3"
|
||||
/>
|
||||
<div
|
||||
className={`searcher-container ${
|
||||
type === "modal" ? "in-modal" : ""
|
||||
}`.trim()}
|
||||
>
|
||||
{/* Result Cards */}
|
||||
<MasonryGrid
|
||||
gridRef={gridContainerRef}
|
||||
onLayoutComplete={() => console.log("Layout complete!")}
|
||||
>
|
||||
{data &&
|
||||
dataType === "media" &&
|
||||
data.map((data: any, key: number) => {
|
||||
let props = {
|
||||
data,
|
||||
origin,
|
||||
type: "media",
|
||||
showCreator: true,
|
||||
};
|
||||
{isSearching ? (
|
||||
<LoadingSpinner />
|
||||
) : (
|
||||
<MasonryGrid
|
||||
key={searchCompleted}
|
||||
gridRef={gridContainerRef}
|
||||
onLayoutComplete={() => 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 (
|
||||
<div
|
||||
{...{
|
||||
className: "col-12 col-sm-6 col-xl-4 grid-item",
|
||||
key,
|
||||
}}
|
||||
>
|
||||
<MediaCards {...{ type: data.media_type, props }} />
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
|
||||
{data &&
|
||||
dataType === "weights" &&
|
||||
data.map((data: any, key: number) => {
|
||||
let props = {
|
||||
data,
|
||||
origin,
|
||||
type: "media",
|
||||
showCreator: true,
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
{...{
|
||||
className: "col-12 col-sm-6 col-xl-4 grid-item",
|
||||
key,
|
||||
}}
|
||||
>
|
||||
<MediaCards {...{ type: data.media_type, props }} />
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</MasonryGrid>
|
||||
return (
|
||||
<div
|
||||
{...{
|
||||
className: "col-12 col-sm-6 col-xl-4 grid-item",
|
||||
key,
|
||||
}}
|
||||
>
|
||||
<WeightsCards {...{ type: data.weight_category, props }} />
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</MasonryGrid>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -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: (
|
||||
<Searcher
|
||||
type="modal"
|
||||
onResultSelect={closeModal}
|
||||
weightTypeFilter={weightTypeFilter}
|
||||
/>
|
||||
),
|
||||
padding: true,
|
||||
},
|
||||
{
|
||||
label: "Bookmarked",
|
||||
content: <Searcher type="modal" onResultSelect={closeModal} />,
|
||||
padding: true,
|
||||
},
|
||||
];
|
||||
return (
|
||||
<>
|
||||
<div>
|
||||
{label && <label className="sub-title">{label}</label>}
|
||||
|
||||
<div className="d-flex gap-2">
|
||||
<Input
|
||||
disabled={true}
|
||||
className="w-100"
|
||||
placeholder="None selected"
|
||||
value={weightTitle ? weightTitle : ""}
|
||||
/>
|
||||
<Button label="Select" onClick={openModal} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Modal
|
||||
show={isModalOpen}
|
||||
handleClose={closeModal}
|
||||
title="Select a LoRA Weight"
|
||||
content={() => <NonRouteTabs tabs={searchTabs} />}
|
||||
showButtons={false}
|
||||
padding={false}
|
||||
large={true}
|
||||
position="top"
|
||||
mobileFullscreen={true}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export { default } from "./useToken";
|
||||
@@ -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<TokenState>(set => ({
|
||||
token: null,
|
||||
setToken: newToken => set({ token: newToken }),
|
||||
weightTitle: null,
|
||||
setWeightTitle: newWeightTitle => set({ weightTitle: newWeightTitle }),
|
||||
}));
|
||||
|
||||
export default useToken;
|
||||
@@ -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<File | null>(null);
|
||||
const [tokens,tokensSet] = useState<string[]>([]);
|
||||
const [tokens, tokensSet] = useState<string[]>([]);
|
||||
|
||||
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 (
|
||||
<Container type="padded" className="pt-4 pt-lg-5">
|
||||
@@ -59,12 +63,15 @@ export default function DevUpload(props: DevUploadProps) {
|
||||
/>
|
||||
</div>
|
||||
<h2>Your uploads</h2>
|
||||
{
|
||||
tokens.map((token: string, key: number) =>
|
||||
<Link {...{ key, to: `/media/${ token }` }}>{ token }</Link>)
|
||||
}
|
||||
{tokens.map((token: string, key: number) => (
|
||||
<Link {...{ key, to: `/media/${token}` }}>{token}</Link>
|
||||
))}
|
||||
</div>
|
||||
</Panel>
|
||||
|
||||
<div className="mt-5">
|
||||
<SelectSearcher label="Additional LoRA Weight" />
|
||||
</div>
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
@@ -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<Weight[]>([]);
|
||||
const [weightType, setWeightType] = useState<string>("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}
|
||||
/>
|
||||
<Panel padding={true}>
|
||||
<div className="d-flex gap-2 mb-4">
|
||||
<div className="d-flex gap-2 mb-3">
|
||||
<Select
|
||||
{...{
|
||||
icon: faLanguage,
|
||||
@@ -156,12 +157,14 @@ export default function SearchPage() {
|
||||
value: weightTypeValue,
|
||||
onChange: args => {
|
||||
setWeightType(args.value);
|
||||
console.log(args.value);
|
||||
},
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<MasonryGrid
|
||||
key={searchCompleted}
|
||||
gridRef={gridContainerRef}
|
||||
onLayoutComplete={() => console.log("Layout complete!")}
|
||||
>
|
||||
|
||||
+4
-46
@@ -15,9 +15,6 @@ import {
|
||||
faRectanglePortrait,
|
||||
faSquare,
|
||||
} from "@fortawesome/pro-solid-svg-icons";
|
||||
import Modal from "components/common/Modal";
|
||||
import NonRouteTabs from "components/common/Tabs/NonRouteTabs";
|
||||
import Searcher from "components/common/Searcher";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import {
|
||||
EnqueueImageGen,
|
||||
@@ -25,6 +22,8 @@ import {
|
||||
EnqueueImageGenIsError,
|
||||
} from "@storyteller/components/src/api/image_generation/EnqueueImageGen";
|
||||
import { FrontendInferenceJobType } from "@storyteller/components/src/jobs/InferenceJob";
|
||||
import useToken from "hooks/useToken";
|
||||
import SelectSearcher from "components/common/SelectSearcher/SelectSearcher";
|
||||
|
||||
interface SdInferencePanelProps {
|
||||
sd_model_token: string;
|
||||
@@ -38,6 +37,7 @@ export default function SdInferencePanel({
|
||||
enqueueInferenceJob,
|
||||
sd_model_token,
|
||||
}: SdInferencePanelProps) {
|
||||
const { token: loraToken } = useToken();
|
||||
const [isEnqueuing, setIsEnqueuing] = useState(false);
|
||||
const [seed, seedSet] = useState("random");
|
||||
const [seedNumber, seedNumberSet] = useState("");
|
||||
@@ -45,7 +45,6 @@ export default function SdInferencePanel({
|
||||
const [aspectRatio, aspectRatioSet] = useState("square");
|
||||
const [cfgScale, cfgScaleSet] = useState(7);
|
||||
const [samples, samplesSet] = useState(8);
|
||||
const [loraToken, loraTokenSet] = useState("");
|
||||
const [batchCount, batchCountSet] = useState(1);
|
||||
const [prompt, setPrompt] = useState("");
|
||||
const [negativePrompt, setNegativePrompt] = useState("");
|
||||
@@ -54,12 +53,10 @@ export default function SdInferencePanel({
|
||||
cfgScaleSet,
|
||||
samplerSet,
|
||||
aspectRatioSet,
|
||||
loraTokenSet,
|
||||
setPrompt,
|
||||
setNegativePrompt,
|
||||
samplesSet,
|
||||
});
|
||||
const [isLoraModalOpen, isLoraModalOpenSet] = useState(false);
|
||||
|
||||
const samplerOpts = [
|
||||
{ label: "DPM++ 2M Karras", value: "DPM++ 2M Karras" },
|
||||
@@ -191,23 +188,6 @@ export default function SdInferencePanel({
|
||||
}
|
||||
};
|
||||
|
||||
const openLoraModal = () => {
|
||||
isLoraModalOpenSet(true);
|
||||
};
|
||||
|
||||
const closeLoraModal = () => {
|
||||
isLoraModalOpenSet(false);
|
||||
};
|
||||
|
||||
const loraSearchTabs = [
|
||||
{
|
||||
label: "All LoRA Weights",
|
||||
content: <Searcher type="modal" />,
|
||||
padding: true,
|
||||
},
|
||||
{ label: "Bookmarked", content: <Searcher type="modal" />, padding: true },
|
||||
];
|
||||
|
||||
const handleEnqueueImageGen = async (
|
||||
ev: React.FormEvent<HTMLButtonElement>
|
||||
) => {
|
||||
@@ -353,17 +333,7 @@ export default function SdInferencePanel({
|
||||
}}
|
||||
/>
|
||||
|
||||
<div>
|
||||
<label className="sub-title">LoRA Weight</label>
|
||||
<div className="d-flex gap-2">
|
||||
<Input
|
||||
disabled={true}
|
||||
className="w-100"
|
||||
placeholder="None selected"
|
||||
/>
|
||||
<Button label="Select" onClick={openLoraModal} />
|
||||
</div>
|
||||
</div>
|
||||
<SelectSearcher label="Additional LoRA Weight" />
|
||||
|
||||
{/* Checkpoint Use weight token */}
|
||||
{/* <TempSelect
|
||||
@@ -405,18 +375,6 @@ export default function SdInferencePanel({
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Additional LoRA Weight Modal */}
|
||||
<Modal
|
||||
show={isLoraModalOpen}
|
||||
handleClose={closeLoraModal}
|
||||
title="Select a LoRA Weight"
|
||||
content={() => <NonRouteTabs tabs={loraSearchTabs} />}
|
||||
showButtons={false}
|
||||
padding={false}
|
||||
large={true}
|
||||
position="top"
|
||||
/>
|
||||
</Panel>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user