Sha256: 707ebad0d758c17f048d4b6bec94b2fc28fcf2b7f5e9033bfc17f64d2bf9009c
Contents?: true
Size: 1.68 KB
Versions: 1
Compression:
Stored size: 1.68 KB
Contents
import { useState } from "react"; import * as Tree from "./tree"; import { updatePage } from "./usePageTree"; import usePageTreeContext from "./usePageTreeContext"; import Button from "./Button"; type Props = { id: Tree.Id; }; export default function EditPageName({ id }: Props) { const { state, dispatch } = usePageTreeContext(); const { dir, locale } = state; const node = state.nodes[id]; const page = node.record; const [name, setName] = useState(page.blocks.name[locale]); const handleCancel = () => { if ("id" in page && page.id) { dispatch({ type: "update", id: id, payload: { editing: false } }); } else { dispatch({ type: "remove", id: id }); } }; const handleChange = (evt: React.ChangeEvent<HTMLInputElement>) => { setName(evt.target.value); }; const handleSubmit = (evt: React.FormEvent) => { evt.preventDefault(); updatePage(state, id, dispatch, { blocks: { ...page.blocks, name: { ...page.blocks.name, [locale]: name } }, editing: false }); }; return ( <div className="page edit"> <i className="fa-regular fa-file icon"></i> <form className="edit-name" onSubmit={handleSubmit}> <input className="tight" type="text" value={name} dir={dir} lang={locale} autoFocus onChange={handleChange} /> <button className="save primary" type="submit"> <i className="fa-solid fa-cloud icon"></i> Save </button> <Button label="Cancel" className="cancel" icon="ban" onClick={handleCancel} /> </form> </div> ); }
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
pages_core-3.15.5 | app/javascript/components/PageTree/EditPageName.tsx |