From: Anon Date: Thu, 30 Mar 2023 20:36:57 +0000 (-0500) Subject: Optimize Tagline Form page (#972) X-Git-Url: http://these/git/%24%7Bsubmission.url%7D?a=commitdiff_plain;h=16cb50614794d43ffb0bf0d693b8aafb4a82ea22;p=lemmy-ui.git Optimize Tagline Form page (#972) * Move taglines to its own tab. Optimize for editing. * Small fix * null -> undefined --- 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, + }); + } +}