import React from "react"; import { IntlShape, useIntl } from "react-intl"; import * as GQL from "src/core/generated-graphql"; import { Button, ButtonGroup } from "react-bootstrap"; import { FilterSelect, SelectObject } from "./Select"; import { GalleryIDSelect, excludeFileBasedGalleries, } from "../Galleries/GallerySelect"; interface IMultiSetProps { type: "performers" | "studios" | "tags" | "groups" | "galleries"; existingIds?: string[]; ids?: string[]; mode: GQL.BulkUpdateIdMode; disabled?: boolean; onUpdate: (ids: string[]) => void; onSetMode: (mode: GQL.BulkUpdateIdMode) => void; } const Select: React.FC = (props) => { const { type, disabled } = props; function onUpdate(items: SelectObject[]) { props.onUpdate(items.map((i) => i.id)); } if (type === "galleries") { return ( ); } return ( ); }; function getModeText(intl: IntlShape, mode: GQL.BulkUpdateIdMode) { switch (mode) { case GQL.BulkUpdateIdMode.Set: return intl.formatMessage({ id: "actions.overwrite", defaultMessage: "Overwrite", }); case GQL.BulkUpdateIdMode.Add: return intl.formatMessage({ id: "actions.add", defaultMessage: "Add" }); case GQL.BulkUpdateIdMode.Remove: return intl.formatMessage({ id: "actions.remove", defaultMessage: "Remove", }); } } export const MultiSetModeButton: React.FC<{ mode: GQL.BulkUpdateIdMode; active: boolean; onClick: () => void; disabled?: boolean; }> = ({ mode, active, onClick, disabled }) => { const intl = useIntl(); return ( ); }; const modes = [ GQL.BulkUpdateIdMode.Set, GQL.BulkUpdateIdMode.Add, GQL.BulkUpdateIdMode.Remove, ]; export const MultiSetModeButtons: React.FC<{ mode: GQL.BulkUpdateIdMode; onSetMode: (mode: GQL.BulkUpdateIdMode) => void; disabled?: boolean; }> = ({ mode, onSetMode, disabled }) => { return ( {modes.map((m) => ( onSetMode(m)} disabled={disabled} /> ))} ); }; export const MultiSet: React.FC = (props) => { const { mode, onUpdate, existingIds } = props; function onSetMode(m: GQL.BulkUpdateIdMode) { if (m === mode) { return; } // if going to Set, set the existing ids if (m === GQL.BulkUpdateIdMode.Set && existingIds) { onUpdate(existingIds); // if going from Set, wipe the ids } else if ( m !== GQL.BulkUpdateIdMode.Set && mode === GQL.BulkUpdateIdMode.Set ) { onUpdate([]); } props.onSetMode(m); } return (