Kucinako - Wordbook of Arzhanai languages
@@ -199,6 +226,7 @@ const App = (_props) => {
{ langSelectDropdown }
+
{
const {entry} = props;
+ console.log(entry);
+
+ const [editing, setEditing] = useState(false);
+ const [english, setEnglish] = useState(entry.eng);
+
const synCategory = entry.syn_category;
const isNominal = synCategory === "nominal";
+
+ const mainEntryStyle = {
+ display: "flex",
+ justifyContent: "space-between",
+ flexDirection: "row",
+ };
+
+ const controlStyle = {
+ display: "flex",
+ justifyContent: "space-between",
+ flexDirection: "row",
+ minWidth: "20%",
+ };
+
+ const edit = (evt) => {
+ evt.preventDefault();
+ setEditing(true);
+ };
+
+ 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 (
-
{ entry.sai } - { entry.eng }
-
-
- { entry.syn_category }
- { entry.morph_type ? `\t\t${entry.morph_type}` : null }
-
- { isNominal ? formatMorphology(entry) : null }
-
+
+
{ entry.sai } - { engTranslation }
+
+ Expand
+ { editButton }
+
+
+
+
+ { entry.syn_category }
+ { entry.morph_type ? `\t\t${entry.morph_type}` : null }
+
+ { isNominal ? formatMorphology(entry) : null }
+
+
);
};
diff --git a/src/requests.ts b/src/requests.ts
new file mode 100644
index 0000000..52a40d1
--- /dev/null
+++ b/src/requests.ts
@@ -0,0 +1,34 @@
+import jwt from "jsonwebtoken";
+
+const backendUrl = "https://kucinakobackend.ichigo.everydayimshuflin.com";
+
+const getPassword = (): string | null => window.sessionStorage.getItem("password");
+
+const setPassword = (password: string) => {
+ window.sessionStorage.setItem("password", password);
+};
+
+const makeAuthorizationHeader = (key: string): string => {
+ const unixTime = Date.now() / 1000;
+ const token = jwt.sign({role: "conlang_postgrest_rw", exp: unixTime + 60}, key);
+ return `Bearer ${token}`;
+};
+
+const updateEntry = (conlangDb: string, id: number, english: string) => {
+ const url = `${backendUrl}/${conlangDb}?id=eq.${id}`;
+
+ const request = new Request(url, {
+ method: "PATCH",
+ headers: {
+ Authorization: makeAuthorizationHeader(getPassword()),
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ eng: english,
+ }),
+ });
+
+ fetch(request).then((resp) => console.log(resp));
+};
+
+export {backendUrl, updateEntry, getPassword, setPassword};