diff --git a/src/Entries.tsx b/src/Entries.tsx index a8396b6..d67cf43 100644 --- a/src/Entries.tsx +++ b/src/Entries.tsx @@ -1,18 +1,21 @@ import React, {useState} from "react"; +import {Conlang} from "./dbtypes"; import {updateEntry, getPassword} from "./requests"; import {declineSaimiar} from "./saimiar_morphology"; import {SaiEntryProps, JutEntryProps, ElesuEntryProps, TukEntryProps} from "./dbtypes"; -const SaiEntry = (props: {entry: SaiEntryProps}) => { - const {entry} = props; - console.log(entry); +interface BaseProps { + id: number; + conlang: Conlang; + conlangEntry: string; + english: string; + langSpecific: React.ReactNode; +} +const EntryBase = (props: BaseProps) => { const [editing, setEditing] = useState(false); - const [english, setEnglish] = useState(entry.eng); - - const synCategory = entry.syn_category; - const isNominal = synCategory === "nominal"; + const [english, setEnglish] = useState(props.english); const mainEntryStyle = { display: "flex", @@ -27,56 +30,69 @@ const SaiEntry = (props: {entry: SaiEntryProps}) => { minWidth: "20%", }; - const edit = (evt) => { - evt.preventDefault(); - setEditing(true); + const save = () => { + updateEntry(props.conlang, props.id, english); + }; + + const engTranslation = editing ? setEnglish(evt.target.value) }/> + : english; + + const EditControls = ({onSave}: { onSave: () => void }) => { + const cancel = () => setEditing(false); + const edit = (evt) => { + evt.preventDefault(); + setEditing(true); + }; + + if (!getPassword()) { + return null; + } + + return (editing ? ( + + + ) + : Edit); }; const expand = (evt) => { evt.preventDefault(); }; - const save = () => { - updateEntry("saimiar", entry.id, english); - }; - - const cancel = () => { - setEditing(false); - }; - - const engTranslation = editing ? setEnglish(evt.target.value) }/> - : english; - - let editButton = null; - if (getPassword()) { - editButton = editing ? ( - - - ) - : Edit; - } - return ( -