import React, { useMemo, useState } from "react"; import * as GQL from "src/core/generated-graphql"; import { useGroupCreate } from "src/core/StashService"; import { useHistory, useLocation } from "react-router-dom"; import { useIntl } from "react-intl"; import { LoadingIndicator } from "src/components/Shared/LoadingIndicator"; import { useToast } from "src/hooks/Toast"; import { GroupEditPanel } from "./GroupEditPanel"; const GroupCreate: React.FC = () => { const history = useHistory(); const intl = useIntl(); const Toast = useToast(); const location = useLocation(); const query = useMemo(() => new URLSearchParams(location.search), [location]); const group = { name: query.get("q") ?? undefined, }; // Editing group state const [frontImage, setFrontImage] = useState(); const [backImage, setBackImage] = useState(); const [encodingImage, setEncodingImage] = useState(false); const [createGroup] = useGroupCreate(); async function onSave(input: GQL.GroupCreateInput) { const result = await createGroup({ variables: { input }, }); if (result.data?.groupCreate?.id) { history.push(`/groups/${result.data.groupCreate.id}`); Toast.success( intl.formatMessage( { id: "toast.created_entity" }, { entity: intl.formatMessage({ id: "group" }).toLocaleLowerCase() } ) ); } } function renderFrontImage() { if (frontImage) { return (
Front Cover
); } } function renderBackImage() { if (backImage) { return (
Back Cover
); } } // TODO: CSS class return (
{encodingImage ? ( ) : (
{renderFrontImage()} {renderBackImage()}
)}
history.push("/groups")} onDelete={() => {}} setFrontImage={setFrontImage} setBackImage={setBackImage} setEncodingImage={setEncodingImage} />
); }; export default GroupCreate;