Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds note editor (#177) #181

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion arches_lingo/src/arches_lingo/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import arches from "arches";
import Cookies from "js-cookie";
import type { AppellativeStatus, SchemeInstance } from "@/arches_lingo/types";
import type {
AppellativeStatus,
SchemeInstance,
SchemeStatement,
} from "@/arches_lingo/types";

function getToken() {
const token = Cookies.get("csrftoken");
Expand Down Expand Up @@ -100,6 +104,26 @@ export const createSchemeLabel = async (
return parsed;
};

export const createSchemeNote = async (
schemeId: string,
statement: SchemeStatement,
) => {
const response = await fetch(arches.urls.api_scheme_note_create, {
method: "POST",
headers: {
"X-CSRFTOKEN": getToken(),
"Content-Type": "application/json",
},
body: JSON.stringify({
resourceinstance: schemeId,
...statement,
}),
});
const parsed = await response.json();
if (!response.ok) throw new Error(parsed.message || response.statusText);
return parsed;
};

export const deleteSchemeLabelTile = async (
schemeId: string,
tileId: string,
Expand Down Expand Up @@ -151,6 +175,27 @@ export const fetchSchemeNotes = async (schemeId: string) => {
return parsed;
};

export const updateSchemeNote = async (
schemeId: string,
tileId: string,
schemeStatement: SchemeStatement,
) => {
const response = await fetch(
arches.urls.api_scheme_note_tile(schemeId, tileId),
{
method: "PATCH",
headers: {
"X-CSRFTOKEN": getToken(),
"Content-Type": "application/json",
},
body: JSON.stringify(schemeStatement),
},
);
const parsed = await response.json();
if (!response.ok) throw new Error(parsed.message || response.statusText);
return parsed;
};

export const deleteSchemeNoteTile = async (
schemeId: string,
tileId: string,
Expand Down
Loading
Loading