import { faEllipsisV } from "@fortawesome/free-solid-svg-icons"; import React, { useState, PropsWithChildren } from "react"; import { Button, Form, Row, Col, Dropdown } from "react-bootstrap"; import { FormattedMessage } from "react-intl"; import { Icon } from "src/components/Shared/Icon"; import * as GQL from "src/core/generated-graphql"; import { FolderSelectDialog } from "../Shared/FolderSelect/FolderSelectDialog"; import { BooleanSetting } from "./Inputs"; import { SettingSection } from "./SettingSection"; interface IStashProps { index: number; stash: GQL.StashConfig; onSave: (instance: GQL.StashConfig) => void; onEdit: () => void; onDelete: () => void; } const Stash: React.FC = ({ index, stash, onSave, onEdit, onDelete, }) => { // eslint-disable-next-line const handleInput = (key: string, value: any) => { const newObj = { ...stash, [key]: value, }; onSave(newObj); }; const classAdd = index % 2 === 1 ? "bg-dark" : ""; return ( {stash.path} {/* NOTE - language is opposite to meaning: internally exclude flags, displayed as include */}
handleInput("excludeVideo", !v)} />
handleInput("excludeImage", !v)} />
onEdit()}> onDelete()}>
); }; interface IStashConfigurationProps { stashes: GQL.StashConfig[]; setStashes: (v: GQL.StashConfig[]) => void; } const StashConfiguration: React.FC = ({ stashes, setStashes, }) => { const [isCreating, setIsCreating] = useState(false); const [editingIndex, setEditingIndex] = useState(); function onEdit(index: number) { setEditingIndex(index); } function onDelete(index: number) { setStashes(stashes.filter((v, i) => i !== index)); } function onNew() { setIsCreating(true); } const handleSave = (index: number, stash: GQL.StashConfig) => setStashes(stashes.map((s, i) => (i === index ? stash : s))); return ( <> {isCreating ? ( { if (v) setStashes([ ...stashes, { path: v, excludeVideo: false, excludeImage: false, }, ]); setIsCreating(false); }} /> ) : undefined} {editingIndex !== undefined ? ( { if (v) setStashes( stashes.map((vv, index) => { if (index === editingIndex) { return { ...vv, path: v, }; } return vv; }) ); setEditingIndex(undefined); }} /> ) : undefined}
{stashes.length > 0 && (
)} {stashes.map((stash, index) => ( handleSave(index, s)} onEdit={() => onEdit(index)} onDelete={() => onDelete(index)} key={stash.path} /> ))}
); }; interface IStashSetting { value: GQL.StashConfigInput[]; onChange: (v: GQL.StashConfigInput[]) => void; } export const StashSetting: React.FC> = ({ value, onChange, children, }) => { return ( onChange(v)} /> {children} ); }; export default StashConfiguration;