From 16cb50614794d43ffb0bf0d693b8aafb4a82ea22 Mon Sep 17 00:00:00 2001 From: Anon Date: Thu, 30 Mar 2023 15:36:57 -0500 Subject: [PATCH] Optimize Tagline Form page (#972) * Move taglines to its own tab. Optimize for editing. * Small fix * null -> undefined --- src/shared/components/home/admin-settings.tsx | 19 ++ src/shared/components/home/site-form.tsx | 53 +---- src/shared/components/home/tagline-form.tsx | 190 ++++++++++++++++++ 3 files changed, 211 insertions(+), 51 deletions(-) create mode 100644 src/shared/components/home/tagline-form.tsx diff --git a/src/shared/components/home/admin-settings.tsx b/src/shared/components/home/admin-settings.tsx index 5b16d2e..6d2707e 100644 --- a/src/shared/components/home/admin-settings.tsx +++ b/src/shared/components/home/admin-settings.tsx @@ -30,6 +30,7 @@ import { Spinner } from "../common/icon"; import { PersonListing } from "../person/person-listing"; import { EmojiForm } from "./emojis-form"; import { SiteForm } from "./site-form"; +import { TaglineForm } from "./tagline-form"; interface AdminSettingsState { siteRes: GetSiteResponse; @@ -134,6 +135,19 @@ export class AdminSettings extends Component { {i18n.t("site")} +
  • + +
  • - - +
    +
    +
    + +
    +
    + +
    +
    + + + ); + } + + handleTaglineChange(i: TaglineForm, index: number, val: string) { + let taglines = i.state.siteForm.taglines; + if (taglines) { + taglines[index] = val; + i.setState(i.state); + } + } + + handleDeleteTaglineClick( + props: { form: TaglineForm; index: number }, + event: any + ) { + event.preventDefault(); + let taglines = props.form.state.siteForm.taglines; + if (taglines) { + taglines.splice(props.index, 1); + props.form.state.siteForm.taglines = undefined; + props.form.setState(props.form.state); + props.form.state.siteForm.taglines = taglines; + props.form.setState({ ...props.form.state, editingRow: undefined }); + } + } + + handleEditTaglineClick( + props: { form: TaglineForm; index: number }, + event: any + ) { + event.preventDefault(); + if (this.state.editingRow == props.index) { + props.form.setState({ editingRow: undefined }); + } else { + props.form.setState({ editingRow: props.index }); + } + } + + handleSaveClick(i: TaglineForm) { + i.setState({ loading: true }); + let auth = myAuth() ?? "TODO"; + i.setState(s => ((s.siteForm.auth = auth), s)); + WebSocketService.Instance.send(wsClient.editSite(i.state.siteForm)); + i.setState({ ...i.state, editingRow: undefined }); + } + + handleAddTaglineClick( + i: TaglineForm, + event: InfernoMouseEvent + ) { + event.preventDefault(); + if (!i.state.siteForm.taglines) { + i.state.siteForm.taglines = []; + } + i.state.siteForm.taglines.push(""); + i.setState({ + ...i.state, + editingRow: i.state.siteForm.taglines.length - 1, + }); + } +} -- 2.44.1