mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
add possibility to edit and clone versions
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
import { useState } from "react";
|
||||
import SettingColorChooser from "renderer/components/settings/setting-color-chooser.component";
|
||||
import { BsmButton } from "renderer/components/shared/bsm-button.component";
|
||||
import { BsmIcon } from "renderer/components/svgs/bsm-icon.component";
|
||||
import { DefaultConfigKey } from "renderer/config/default-configuration.config";
|
||||
import { useTranslation } from "renderer/hooks/use-translation.hook";
|
||||
import { ConfigurationService } from "renderer/services/configuration.service";
|
||||
import { ModalExitCode, ModalResponse, ModalService } from "renderer/services/modale.service";
|
||||
import { BSVersion } from "shared/bs-version.interface";
|
||||
|
||||
export function EditVersionModal({resolver, clone = false}: {resolver: (x: ModalResponse<{name: string, color: string}>) => void, clone?: boolean}) {
|
||||
|
||||
const configService = ConfigurationService.getInstance();
|
||||
const modalService = ModalService.getInsance();
|
||||
|
||||
const modalData: BSVersion = modalService.getModalData();
|
||||
|
||||
const [name, setName] = useState(modalData.name || modalData.BSVersion);
|
||||
const [color, setColor] = useState(modalData.color ?? configService.get<string>("second-color" as DefaultConfigKey));
|
||||
const t = useTranslation();
|
||||
|
||||
const rename = () => {
|
||||
if(!name){ return; }
|
||||
resolver({exitCode: ModalExitCode.COMPLETED, data: {name, color}})
|
||||
}
|
||||
|
||||
const resetColor = () => {
|
||||
setColor(configService.get("second-color" as DefaultConfigKey))
|
||||
}
|
||||
|
||||
return (
|
||||
<form className="static" onSubmit={(e) => {e.preventDefault(); rename();}}>
|
||||
<h1 className="text-3xl uppercase tracking-wide w-full text-center text-gray-800 dark:text-gray-200">{t(!clone ? "Editer la version" : "Cloner_la_version")}</h1>
|
||||
<BsmIcon className="w-full h-11 my-3" icon="bsNote" style={{color: color}}/>
|
||||
{ clone && (
|
||||
<p className="max-w-sm mb-2 text-gray-800 dark:text-gray-200">Cloner la version te permet de séparer le contenu additionnel de BeatSaber entre deux même versions</p>
|
||||
)}
|
||||
<div className="mb-3">
|
||||
<label className="block font-bold cursor-pointer tracking-wide text-gray-800 dark:text-gray-200" htmlFor="name">{t("Nom")}</label>
|
||||
<input className="w-full bg-light-main-color-1 dark:bg-main-color-1 px-1 py-[2px] rounded-md outline-none" onChange={e => setName(e.target.value)} value={name} type="text" name="name" id="name" minLength={2} maxLength={15} placeholder={t("Nom de la version")}/>
|
||||
</div>
|
||||
<div>
|
||||
<span className="block font-bold tracking-wide text-gray-800 dark:text-gray-200">Couleur</span>
|
||||
<div className="relative w-full h-7 mb-4 bg-light-main-color-1 dark:bg-main-color-1 flex justify-center rounded-md py-1 z-[1]">
|
||||
<SettingColorChooser color={color} onChange={setColor} pickerClassName="!h-32 !w-32"/>
|
||||
<div className="absolute right-2 top-0 h-full flex items-center">
|
||||
<BsmButton onClick={resetColor} className="px-2 font-bold italic text-sm rounded-md bg-light-main-color-2 dark:bg-main-color-2 hover:bg-light-main-color-3 dark:hover:bg-main-color-3" text="pages.settings.appearance.reset" withBar={false}/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="grid grid-flow-col grid-cols-2 gap-4">
|
||||
<BsmButton className="rounded-md text-center bg-gray-500 hover:brightness-110 transition-all" onClick={() => {resolver({exitCode: ModalExitCode.CANCELED})}} withBar={false} text="misc.cancel"/>
|
||||
<BsmButton typeColor="primary" className="z-0 px-1 rounded-md text-center hover:brightness-110 transition-all" type="submit" withBar={false} text={t("Editer")}/>
|
||||
</div>
|
||||
</form>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import { LoginModal } from "./modal-types/login-modal.component";
|
||||
import { GuardModal } from "./modal-types/guard-modal.component";
|
||||
import { UninstallModal } from "./modal-types/uninstall-modal.component";
|
||||
import { InstallationFolderModal } from "./modal-types/installation-folder-modal.component";
|
||||
import { EditVersionModal } from "./modal-types/edit-version-modal.component";
|
||||
|
||||
export function Modal() {
|
||||
|
||||
@@ -41,6 +42,8 @@ export function Modal() {
|
||||
{modalType === ModalType.GUARD_CODE && <GuardModal resolver={modalSevice.getResolver()}/>}
|
||||
{modalType === ModalType.UNINSTALL && <UninstallModal resolver={modalSevice.getResolver()}/>}
|
||||
{modalType === ModalType.INSTALLATION_FOLDER && <InstallationFolderModal resolver={modalSevice.getResolver()}/>}
|
||||
{modalType === ModalType.EDIT_VERSION && <EditVersionModal resolver={modalSevice.getResolver()}/>}
|
||||
{modalType === ModalType.CLONE_VERSION && <EditVersionModal resolver={modalSevice.getResolver()} clone/>}
|
||||
</div>
|
||||
</motion.div>
|
||||
</div>
|
||||
|
||||
@@ -2,29 +2,32 @@ import { BSVersion } from 'shared/bs-version.interface';
|
||||
import { Link, useLocation } from "react-router-dom";
|
||||
import { BsDownloaderService } from "renderer/services/bs-downloader.service";
|
||||
import { useEffect, useState } from "react";
|
||||
import { combineLatest } from "rxjs";
|
||||
import { combineLatest, Subscription } from "rxjs";
|
||||
import { BSLauncherService, LaunchMods } from "renderer/services/bs-launcher.service";
|
||||
import { ConfigurationService } from "renderer/services/configuration.service";
|
||||
import { BsmButton } from "../shared/bsm-button.component";
|
||||
import { BSUninstallerService } from "renderer/services/bs-uninstaller.service";
|
||||
import { BSVersionManagerService } from "renderer/services/bs-version-manager.service";
|
||||
import { BsmIcon } from "../svgs/bsm-icon.component";
|
||||
import { ReactFitty } from "react-fitty";
|
||||
import { DefaultConfigKey } from 'renderer/config/default-configuration.config';
|
||||
|
||||
export function BsVersionItem(props: {version: BSVersion}) {
|
||||
|
||||
const { state } = useLocation() as { state: BSVersion};
|
||||
|
||||
const [downloading, setDownloading] = useState(true);
|
||||
const [downloadPercent, setDownloadPercent] = useState(0);
|
||||
|
||||
const downloaderService = BsDownloaderService.getInstance();
|
||||
const verionManagerService = BSVersionManagerService.getInstance();
|
||||
const launcherService = BSLauncherService.getInstance();
|
||||
const configService = ConfigurationService.getInstance();
|
||||
const bsUninstallerService = BSUninstallerService.getInstance();
|
||||
|
||||
const { state } = useLocation() as { state: BSVersion};
|
||||
|
||||
const [downloading, setDownloading] = useState(false);
|
||||
const [downloadPercent, setDownloadPercent] = useState(0);
|
||||
const [color, setColor] = useState("");
|
||||
|
||||
const isActive = (): boolean => {
|
||||
return props.version?.BSVersion === state?.BSVersion && props?.version.steam === state?.steam;
|
||||
return props.version?.BSVersion === state?.BSVersion && props?.version.steam === state?.steam && props?.version.name === state?.name;
|
||||
}
|
||||
|
||||
const handleDoubleClick = () => {
|
||||
@@ -46,28 +49,39 @@ export function BsVersionItem(props: {version: BSVersion}) {
|
||||
});
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
combineLatest([downloaderService.currentBsVersionDownload$, downloaderService.downloadProgress$]).subscribe(vals => {
|
||||
if(vals[0]?.BSVersion === props.version.BSVersion && vals[0]?.steam === props.version.steam){
|
||||
setDownloading(true);
|
||||
setDownloadPercent(vals[1]);
|
||||
}
|
||||
useEffect(() => {
|
||||
const subs: Subscription[] = [];
|
||||
const downloadSub = combineLatest([downloaderService.currentBsVersionDownload$, downloaderService.downloadProgress$]).subscribe(vals => {
|
||||
if(vals[0]?.BSVersion === props.version.BSVersion && vals[0]?.steam === props.version.steam && vals[0]?.name === props.version.name){
|
||||
setDownloading(true);
|
||||
setDownloadPercent(vals[1]);
|
||||
}
|
||||
else{
|
||||
setDownloading(false);
|
||||
setDownloadPercent(0);
|
||||
}
|
||||
});
|
||||
subs.push(downloadSub);
|
||||
if(props.version?.color){ setColor(props.version.color); }
|
||||
else{
|
||||
setDownloading(false);
|
||||
setDownloadPercent(0);
|
||||
const colorSub = configService.watch<string>("second-color" as DefaultConfigKey).subscribe(color => setColor(color));
|
||||
subs.push(colorSub);
|
||||
}
|
||||
})
|
||||
|
||||
return () => { subs.forEach(s => s.unsubscribe()); }
|
||||
}, []);
|
||||
|
||||
|
||||
return (
|
||||
<div className={`outline-none relative p-[1px] overflow-hidden rounded-xl flex justify-center content-center items-center mb-1 ${downloading && "nav-item-download"} active:translate-y-[1px]`}>
|
||||
<div className={`outline-none relative p-[1px] overflow-hidden rounded-xl flex justify-center items-center mb-1 ${downloading && "nav-item-download"} active:translate-y-[1px]`}>
|
||||
<div className="progress absolute top-0 w-full h-full" style={{transform: `translate(${-(100 - downloadPercent)}%, 0)`}}></div>
|
||||
<div className={`wrapper z-[1] px-2 py-[3px] w-full rounded-xl ${downloading && 'bg-black'} ${!downloading && "hover:bg-light-main-color-3 dark:hover:bg-main-color-3"} ${(isActive() && !downloading) && "bg-light-main-color-3 dark:bg-main-color-3"}`}>
|
||||
<Link onDoubleClick={handleDoubleClick} to={`/bs-version/${props.version.BSVersion}`} state={props.version} className="flex justify-center items-center">
|
||||
{props.version.steam && <BsmIcon icon="steam" className="w-[19px] h-[19px] mr-1"/>}
|
||||
{!props.version.steam && <BsmIcon icon="bsNote" className="w-[19px] h-[19px] mr-1 text-red-600"/>}
|
||||
<span className="flex items-center justify-center content-center shrink-0 grow text-lg dark:text-gray-200 text-gray-800 font-bold min-w-0 tracking-wide">{props.version.BSVersion}</span>
|
||||
<div className={`wrapper z-[1] px-1 py-[3px] w-full rounded-xl ${downloading && 'bg-black'} ${!downloading && "hover:bg-light-main-color-3 dark:hover:bg-main-color-3"} ${(isActive() && !downloading) && "bg-light-main-color-3 dark:bg-main-color-3"}`}>
|
||||
<Link onDoubleClick={handleDoubleClick} to={`/bs-version/${props.version.BSVersion}`} state={props.version} title={props.version.name && `${props.version.BSVersion} - ${props.version.name}`} className="w-full flex items-center justify-start content-center max-w-full">
|
||||
{props.version.steam && <BsmIcon icon="steam" className="w-[19px] h-[19px] mr-[5px] shrink-0"/>}
|
||||
{!props.version.steam && <BsmIcon icon="bsNote" className="w-[19px] h-[19px] mr-[5px] shrink-0" style={{color: color}}/>}
|
||||
<div className="overflow-hidden whitespace-nowrap text-xl dark:text-gray-200 text-gray-800 font-bold tracking-wide">
|
||||
<ReactFitty maxSize={19} minSize={10} className='align-middle pb-[2px] max-w-full overflow-hidden text-ellipsis'>{props.version.name || props.version.BSVersion}</ReactFitty>
|
||||
</div>
|
||||
</Link>
|
||||
{downloading && <BsmButton onClick={cancel} className="my-1 text-xs text-white rounded-md text-center hover:brightness-125" withBar={false} text="misc.cancel" typeColor="error"/>}
|
||||
</div>
|
||||
|
||||
@@ -24,7 +24,7 @@ export function NavBar() {
|
||||
<span id='logo-top' className='bg-red-500 aspect-square w-16' style={{backgroundColor: secondColor}}> </span>
|
||||
</div>
|
||||
</div>
|
||||
<div id='versions' className='w-fit relative left-[2px] grow overflow-y-hidden scrollbar-track-transparent scrollbar-thin scrollbar-thumb-neutral-900 hover:overflow-y-scroll'>
|
||||
<div id='versions' className='w-fit max-w-[120px] relative left-[2px] grow overflow-y-hidden scrollbar-track-transparent scrollbar-thin scrollbar-thumb-neutral-900 hover:overflow-y-scroll'>
|
||||
{installedVersions && installedVersions.map((version) => <BsVersionItem key={JSON.stringify(version)} version={version}/>)}
|
||||
</div>
|
||||
<div className='w-full p-2 flex flex-col items-center content-center justify-start'>
|
||||
|
||||
@@ -3,7 +3,7 @@ import { HexColorPicker } from "react-colorful";
|
||||
import { motion, AnimatePresence } from "framer-motion"
|
||||
import OutsideClickHandler from "react-outside-click-handler";
|
||||
|
||||
export default function SettingColorChooser({color, onChange}: {color?: string, onChange?: (color: string) => void}) {
|
||||
export default function SettingColorChooser({color, onChange, pickerClassName}: {color?: string, onChange?: (color: string) => void, pickerClassName?: string}) {
|
||||
|
||||
const [colorVisible, setColorVisible] = useState(false);
|
||||
|
||||
@@ -13,9 +13,9 @@ export default function SettingColorChooser({color, onChange}: {color?: string,
|
||||
<span className="z-[1] block h-full w-full border-2 border-white rounded-full" onClick={() => setColorVisible(!colorVisible)} style={{backgroundColor: color}}/>
|
||||
<AnimatePresence>
|
||||
{colorVisible &&
|
||||
<motion.div initial={{opacity: 0}} animate={{opacity: 1}} transition={{duration: .1}} exit={{opacity: 0}} className="absolute flex items-center justify-center translate-y-9 shadow-lg rounded-lg shadow-black">
|
||||
<motion.div initial={{opacity: 0}} animate={{opacity: 1}} transition={{duration: .1}} exit={{opacity: 0}} className="fixed flex items-center justify-center translate-y-9 shadow-lg rounded-lg shadow-black">
|
||||
<div className="absolute w-2/4 aspect-square rotate-45 bg-light-main-color-3 dark:bg-main-color-3 -translate-y-12"></div>
|
||||
<HexColorPicker color={color} onChange={onChange} className="" />
|
||||
<HexColorPicker color={color} onChange={onChange} className={pickerClassName} />
|
||||
</motion.div>
|
||||
}
|
||||
</AnimatePresence>
|
||||
|
||||
@@ -12,7 +12,7 @@ export function BsmButton({className, style, imgClassName, icon, image, text, ty
|
||||
|
||||
return (
|
||||
<OutsideClickHandler onOutsideClick={e => onClickOutside && onClickOutside(e)}>
|
||||
<div onClick={e => onClick && onClick(e)} className={`${className} overflow-hidden cursor-pointer group ${disabled && "brightness-75 cursor-not-allowed"} ${typeColor == "error" && 'bg-red-500'}`} style={style}>
|
||||
<div onClick={e => onClick && onClick(e)} className={`${className} overflow-hidden cursor-pointer group ${disabled && "brightness-75 cursor-not-allowed"} ${typeColor === "error" && 'bg-red-500'} ${typeColor == "primary" && 'bg-blue-500'}`} style={style}>
|
||||
{ image && <BsmImage image={image} className={imgClassName}/> }
|
||||
{ icon && <BsmIcon icon={icon} className="h-full w-full text-gray-800 dark:text-white"/> }
|
||||
{text && (type === "submit" ? <button className="w-full h-full">{t(text)}</button> : <span>{t(text)}</span>)}
|
||||
|
||||
Reference in New Issue
Block a user