mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
[feature-136] can now search models from the download modal
This commit is contained in:
@@ -12,26 +12,26 @@ import { followCursor } from "tippy.js"
|
||||
import defaultImage from '../../../../assets/images/default-version-img.jpg'
|
||||
import { BsmLocalModel } from "shared/models/models/bsm-local-model.interface";
|
||||
import { BsmIconType } from "../svgs/bsm-icon.component";
|
||||
import { Observable, of } from "rxjs";
|
||||
import { useObservable } from "renderer/hooks/use-observable.hook";
|
||||
import { BsmButton } from "../shared/bsm-button.component";
|
||||
import { BsmBasicSpinner } from "../shared/bsm-basic-spinner/bsm-basic-spinner.component";
|
||||
import { isValidUrl } from "shared/helpers/url.helpers";
|
||||
|
||||
type Props = {
|
||||
type Props<T> = {
|
||||
selected?: boolean,
|
||||
hash: string,
|
||||
id: number,
|
||||
isDownloading?: Observable<boolean>
|
||||
onDelete?: () => void,
|
||||
onDownload?: () => void,
|
||||
onCancelDownload?: () => void
|
||||
id?: number,
|
||||
isDownloading?: boolean,
|
||||
callbackValue?: T
|
||||
onDelete?: (value: T) => void,
|
||||
onDownload?: (value: T) => void,
|
||||
onCancelDownload?: (value: T) => void
|
||||
} & Partial<MSModel> & Partial<BsmLocalModel> & Omit<React.ComponentProps<"li">, "id">
|
||||
|
||||
export const ModelItem = memo((props: Props) => {
|
||||
function modelItem<T = unknown>(props: Props<T>) {
|
||||
|
||||
const color = useThemeColor("first-color");
|
||||
const [hovered, setHovered] = useState(false);
|
||||
const [idContentCopied, setIdContentCopied] = useState<string>(null);
|
||||
const isDownloading = useObservable(props.isDownloading ?? of(false), false);
|
||||
|
||||
const modelPageUrl = (() => {
|
||||
if(!props.id){ return null; }
|
||||
@@ -41,25 +41,39 @@ export const ModelItem = memo((props: Props) => {
|
||||
})();
|
||||
|
||||
const authorPageUrl = (() => {
|
||||
if(!props.discordid){ return null; }
|
||||
if(!props.discord){ return null; }
|
||||
const url = new URL("Profile", MODEL_SABER_URL);
|
||||
url.searchParams.set("user", props.discord.toString());
|
||||
return url.toString();
|
||||
})();
|
||||
|
||||
const thumbnailUrl = (() => {
|
||||
if(!props.thumbnail){ return null; }
|
||||
if(isValidUrl(props.thumbnail)){ return props.thumbnail; }
|
||||
const [file, ext] = props.thumbnail.split(".");
|
||||
return props.download.split("/").slice(0, -1).join("/") + `/${file}.${ext.toLowerCase()}`;
|
||||
})();
|
||||
|
||||
const modelTags = (() => {
|
||||
if(!props.tags){ return null; }
|
||||
return [...new Set(props.tags)];
|
||||
})();
|
||||
|
||||
console.log(thumbnailUrl, "la");
|
||||
|
||||
const actionButtons = (): {text: string, icon: BsmIconType, action: () => void}[] => {
|
||||
const buttons: {text: string, icon: BsmIconType, action: () => void}[] = [];
|
||||
|
||||
if(props.onDownload){
|
||||
buttons.push({ text: "Download", icon: "download", action: props.onDownload }); // TODO TRANSLATE
|
||||
buttons.push({ text: "Download", icon: "download", action: () => props.onDownload(props.callbackValue) }); // TODO TRANSLATE
|
||||
}
|
||||
|
||||
if(props.onDelete){
|
||||
buttons.push({ text: "Delete", icon: "trash", action: props.onDelete }); // TODO TRANSLATE
|
||||
buttons.push({ text: "Delete", icon: "trash", action: () => props.onDelete(props.callbackValue) }); // TODO TRANSLATE
|
||||
}
|
||||
|
||||
if(props.onCancelDownload){
|
||||
buttons.push({ text: "Cancel download", icon: "cross", action: props.onCancelDownload }); // TODO TRANSLATE
|
||||
buttons.push({ text: "Cancel download", icon: "cross", action: () => props.onCancelDownload(props.callbackValue) }); // TODO TRANSLATE
|
||||
}
|
||||
|
||||
return buttons;
|
||||
@@ -77,28 +91,22 @@ export const ModelItem = memo((props: Props) => {
|
||||
// TODO TRANSLATE ALL TEXT
|
||||
<motion.li className={`relative flex-grow min-w-[13rem] h-52 cursor-pointer ${props.className ?? ""}`} onHoverStart={() => setHovered(() => true)} onHoverEnd={() => setHovered(() => false)} onClick={props.onClick}>
|
||||
<GlowEffect visible={props.selected || hovered}/>
|
||||
<div>
|
||||
{!isDownloading ? (
|
||||
<div>
|
||||
{actionButtons().map((button, index) => (
|
||||
<Tippy key={index} placement="top" content={button.text} followCursor="horizontal" plugins={[followCursor]} hideOnClick={false}>
|
||||
<BsmButton className="absolute top-0 right-0 w-6 h-6 p-1 bg-main-color-3 bg-opacity-60 backdrop-blur-md rounded-md text-white" onClick={e => {e.stopPropagation(); e.preventDefault(); button.action();}}/>
|
||||
</Tippy>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div>
|
||||
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="absolute top-0 left-0 w-full h-full rounded-lg overflow-hidden blur-none">
|
||||
<BsmImage className={`absolute top-0 left-0 w-full h-full object-cover ${props.type === MSModelType.Avatar ? "object-top" : ""}`} image={props.thumbnail} placeholder={defaultImage} loading="lazy"/>
|
||||
<motion.div className="absolute cursor-default top-[80%] left-0 w-full h-full p-2 flex flex-col gap-1.5 bg-main-color-3 bg-opacity-60 backdrop-blur-md transition-all hover:top-0" onClick={e =>{e.stopPropagation(); e.preventDefault()}}>
|
||||
<div className="absolute top-0 left-0 w-full h-full rounded-lg overflow-hidden blur-none bg-black">
|
||||
<BsmImage className={`absolute top-0 left-0 w-full h-full object-cover ${props.type === MSModelType.Avatar ? "object-top" : ""}`} image={thumbnailUrl} placeholder={defaultImage} loading="lazy"/>
|
||||
<div className="absolute top-0 right-0 h-full w-0 flex flex-col items-end gap-1 pt-1.5 pr-1.5">
|
||||
{!props.isDownloading ? (
|
||||
actionButtons().map((button, index) => (
|
||||
<BsmButton key={index} className="w-7 h-7 p-1 rounded-md transition-transform duration-150 shadow-black shadow-sm" style={{transitionDelay: `${index * 50}ms`, transform: hovered ? "translate(0%)" : "translate(150%)"}} icon={button.icon} onClick={e => {e.stopPropagation(); e.preventDefault(); button.action();}} withBar={false}/>
|
||||
))
|
||||
): (
|
||||
<BsmBasicSpinner className="w-7 h-7 p-1 rounded-md bg-main-color-2 flex items-center justify-center shadow-black shadow-sm" spinnerClassName="brightness-200" thikness="3.5px" style={{color}}/>
|
||||
)}
|
||||
</div>
|
||||
<motion.div className="absolute cursor-default top-[80%] left-0 w-full h-full p-2 flex flex-col gap-1.5 bg-main-color-3 bg-opacity-60 backdrop-blur-md transition-all delay-150 hover:top-0" onClick={e =>{e.stopPropagation(); e.preventDefault()}}>
|
||||
<BsmLink className={`block w-fit max-w-full overflow-hidden font-bold whitespace-nowrap text-ellipsis ${props.id ? "cursor-pointer hover:underline" : ""}`} href={modelPageUrl}>{props.name}</BsmLink>
|
||||
<BsmLink className={`block w-fit max-w-full overflow-hidden whitespace-nowrap text-ellipsis brightness-200 ${authorPageUrl ? "cursor-pointer hover:underline" : ""}`} style={{color}} href={authorPageUrl}>{props.author ?? ''}</BsmLink>
|
||||
<ul className="flex flex-row flex-wrap gap-1">
|
||||
{props.tags?.map(tag => (
|
||||
{modelTags?.map(tag => (
|
||||
<li key={tag} className="inline-block mr-1 text-xs bg-white text-black px-1 rounded-full p-0.5">{tag}</li>
|
||||
))}
|
||||
</ul>
|
||||
@@ -121,4 +129,8 @@ export const ModelItem = memo((props: Props) => {
|
||||
</div>
|
||||
</motion.li>
|
||||
)
|
||||
}, equal);
|
||||
};
|
||||
|
||||
const typedMemo: <T, P>(c: T, propsAreEqual?: (prevProps: Readonly<P>, nextProps: Readonly<P>) => boolean) => T = memo;
|
||||
|
||||
export const ModelItem = typedMemo(modelItem, equal);
|
||||
|
||||
@@ -126,6 +126,13 @@ export const ModelsGrid = forwardRef(({className, version, type, search, active}
|
||||
})
|
||||
}
|
||||
|
||||
const handleDelete = (model: BsmLocalModel) => {
|
||||
modelsManager.deleteModels([model], version).then(deleted => {
|
||||
if(!deleted){ return; }
|
||||
setModels(prev => prev.filter(m => m.hash !== model.hash));
|
||||
});
|
||||
}
|
||||
|
||||
const renderContent = () => {
|
||||
if(isLoading){
|
||||
return (
|
||||
@@ -151,19 +158,15 @@ export const ModelsGrid = forwardRef(({className, version, type, search, active}
|
||||
<ul className="flex flex-wrap shrink-0 justify-start content-start w-full h-full overflow-y-scroll overflow-x-hidden p-4 gap-4 scrollbar-thin scrollbar-thumb-rounded-full scrollbar-thumb-neutral-900">
|
||||
{filtredModels().map(localModel => (
|
||||
<ModelItem
|
||||
{...localModel?.model}
|
||||
key={localModel.model?.hash ?? localModel.hash}
|
||||
hash={localModel.model?.hash ?? localModel.hash}
|
||||
id={localModel.model?.id}
|
||||
path={localModel.path}
|
||||
type={localModel.type}
|
||||
name={localModel.model?.name ?? localModel.fileName}
|
||||
thumbnail={localModel.model?.thumbnail}
|
||||
author={localModel.model?.author}
|
||||
discord={localModel.model?.discord}
|
||||
discordid={localModel.model?.discordid}
|
||||
tags={localModel.model?.tags}
|
||||
selected={modelsSelected.some(m => m.hash === localModel.hash)}
|
||||
path={localModel.path}
|
||||
onClick={() => handleModelClick(localModel)}
|
||||
onDelete={() => handleDelete(localModel)}
|
||||
/>
|
||||
))}
|
||||
</ul>
|
||||
|
||||
@@ -8,14 +8,22 @@ import { useConstant } from "renderer/hooks/use-constant.hook";
|
||||
import { ModelsManagerService } from "renderer/services/models-management/models-manager.service";
|
||||
import { BsmLocalModel } from "shared/models/models/bsm-local-model.interface";
|
||||
import { BsmButton } from "../shared/bsm-button.component";
|
||||
import { useService } from "renderer/hooks/use-service.hook";
|
||||
import { ModelsDownloaderService } from "renderer/services/models-management/models-downloader.service";
|
||||
|
||||
export function ModelsPanel({version}: {version?: BSVersion}) {
|
||||
const modelsManager = useConstant(() => ModelsManagerService.getInstance());
|
||||
|
||||
const modelsManager = useService(ModelsManagerService);
|
||||
const modelDownloader = useService(ModelsDownloaderService);
|
||||
|
||||
const [avatarsRef, sabersRef, platformsRef, bloqsRef] = [useRef(null), useRef(null), useRef(null), useRef(null)];
|
||||
const [modelTypeTab, setModelTypeTab] = useState<ModelTabType>(ModelTabType.Avatars);
|
||||
|
||||
const [modelTypeTab, setModelTypeTab] = useState<MSModelType>(MSModelType.Avatar);
|
||||
const [currentTabIndex, setCurrentTabIndex] = useState<number>(0);
|
||||
|
||||
const [search, setSearch] = useState<string>("");
|
||||
|
||||
const getActiveTabRef = () => [avatarsRef, sabersRef, platformsRef, bloqsRef][modelTypeTab];
|
||||
const getActiveTabRef = () => [avatarsRef, sabersRef, platformsRef, bloqsRef][currentTabIndex];
|
||||
|
||||
const exportModels = () => {
|
||||
const selectedModels = [avatarsRef, sabersRef, platformsRef, bloqsRef].map(ref =>(ref.current?.getSelectedModels() as BsmLocalModel[])).flat()
|
||||
@@ -27,6 +35,10 @@ export function ModelsPanel({version}: {version?: BSVersion}) {
|
||||
activeTab.current?.deleteSelectedModels();
|
||||
}
|
||||
|
||||
const openDownloadModal = () => {
|
||||
modelDownloader.openDownloadModelsModal(version, modelTypeTab);
|
||||
}
|
||||
|
||||
const threeDotsItems: DropDownItem[] = [
|
||||
{text: "TODO TRANSLATE EXPORT", onClick: exportModels, icon: "export"},
|
||||
{text: "TODO TRANSLATE DELETE", onClick: deleteModels, icon: "trash"},
|
||||
@@ -35,29 +47,22 @@ export function ModelsPanel({version}: {version?: BSVersion}) {
|
||||
return (
|
||||
<div className="w-full h-full flex flex-col items-center justify-center">
|
||||
<div className="w-full shrink-0 flex h-9 justify-center px-40 gap-2 mb-3 text-main-color-1 dark:text-white">
|
||||
<BsmButton className="flex items-center justify-center w-fit rounded-full px-2 py-1 font-bold" icon="add" text="misc.add" typeColor="primary" withBar={false}/>
|
||||
<BsmButton className="flex items-center justify-center w-fit rounded-full px-2 py-1 font-bold" icon="add" text="misc.add" typeColor="primary" withBar={false} onClick={e => {e.preventDefault(); openDownloadModal()}}/>
|
||||
<div className="h-full rounded-full bg-light-main-color-2 dark:bg-main-color-2 grow p-[6px]">
|
||||
<input type="text" className="h-full w-full bg-light-main-color-1 dark:bg-main-color-1 rounded-full px-2" placeholder={"TODO TRANSLATE"} onChange={e => setSearch(e.target.value)} tabIndex={-1}/>
|
||||
</div>
|
||||
<BsmDropdownButton items={threeDotsItems} className="h-full flex aspect-square relative rounded-full z-[1] bg-light-main-color-1 dark:bg-main-color-3" buttonClassName="rounded-full h-full w-full p-[6px]" icon="three-dots" withBar={false} menuTranslationY="6px" align="center"/>
|
||||
</div>
|
||||
<div className="w-full h-full flex flex-row bg-light-main-color-3 dark:bg-main-color-2 rounded-md shadow-black shadow-md overflow-hidden">
|
||||
<ModelsTabsNavbar className="flex-shrink-0" version={version} tabIndex={modelTypeTab} onTabChange={setModelTypeTab}/>
|
||||
<ModelsTabsNavbar className="flex-shrink-0" version={version} tabIndex={currentTabIndex} onTabChange={(index, tab) => {setModelTypeTab(() => tab.extra), setCurrentTabIndex(() => index)}}/>
|
||||
|
||||
<div className="flex-grow h-full flex flex-col transition-all duration-300" style={{translate: `0 ${0 - modelTypeTab * 100}%`}}>
|
||||
<ModelsGrid ref={avatarsRef} version={version} type={MSModelType.Avatar} active={modelTypeTab === ModelTabType.Avatars} search={search}/>
|
||||
<ModelsGrid ref={sabersRef} version={version} type={MSModelType.Saber} active={modelTypeTab === ModelTabType.Sabers} search={search}/>
|
||||
<ModelsGrid ref={platformsRef} version={version} type={MSModelType.Platfrom} active={modelTypeTab === ModelTabType.Platforms} search={search}/>
|
||||
<ModelsGrid ref={bloqsRef} version={version} type={MSModelType.Bloq} active={modelTypeTab === ModelTabType.Bloqs} search={search}/>
|
||||
<div className="flex-grow h-full flex flex-col transition-all duration-300" style={{translate: `0 ${0 - currentTabIndex * 100}%`}}>
|
||||
<ModelsGrid ref={avatarsRef} version={version} type={MSModelType.Avatar} active={modelTypeTab === MSModelType.Avatar} search={search}/>
|
||||
<ModelsGrid ref={sabersRef} version={version} type={MSModelType.Saber} active={modelTypeTab === MSModelType.Saber} search={search}/>
|
||||
<ModelsGrid ref={platformsRef} version={version} type={MSModelType.Platfrom} active={modelTypeTab === MSModelType.Platfrom} search={search}/>
|
||||
<ModelsGrid ref={bloqsRef} version={version} type={MSModelType.Bloq} active={modelTypeTab === MSModelType.Bloq} search={search}/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
enum ModelTabType {
|
||||
Avatars = 0,
|
||||
Sabers = 1,
|
||||
Platforms = 2,
|
||||
Bloqs = 3,
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ type Props = {
|
||||
className?: string,
|
||||
version?: BSVersion
|
||||
tabIndex: number,
|
||||
onTabChange: (index: number) => void
|
||||
onTabChange: (index: number, tab: BsContentNavBarTab<MSModelType>) => void
|
||||
}
|
||||
|
||||
export function ModelsTabsNavbar({className, version, tabIndex, onTabChange}: Props) {
|
||||
@@ -70,10 +70,10 @@ function ModelTab({version, modelType, active, onClick}: TabProps){
|
||||
}
|
||||
|
||||
return (
|
||||
<li className={`relative w-full cursor-pointer flex-1 text-center text-lg font-bold hover:backdrop-brightness-75 flex justify-center items-center content-center px-7 ${active ? "backdrop-brightness-75" : ""}`} onClick={onClick}>
|
||||
<div className="flex flex-col gap-0.5 justify-start items-center">
|
||||
<li className={`relative w-full cursor-pointer flex-1 text-center text-lg font-bold flex justify-center items-center content-center px-7 dim-on-hover ${active ? "dim" : ""}`} onClick={onClick}>
|
||||
<div className="flex flex-col gap-0.5 justify-start items-center text-main-color-1 dark:text-gray-200">
|
||||
<BsmIcon icon={modelType} className="w-7 h-7"/>
|
||||
<span className="text-main-color-1 dark:text-gray-200 font-thin italic text-xs">{modelType}</span>
|
||||
<span className=" font-thin italic text-xs">{modelType}</span>
|
||||
</div>
|
||||
<div className="flex items-center absolute top-1.5 left-1.5">
|
||||
{!!version && (
|
||||
|
||||
Reference in New Issue
Block a user