diff --git a/client/api/api.ts b/client/api/api.ts index 27d631a..989202c 100644 --- a/client/api/api.ts +++ b/client/api/api.ts @@ -270,6 +270,19 @@ function setPrimaryAlias( body: form, }); } +function updateMbzId( + type: string, + id: number, + mbzid: string +): Promise { + const form = new URLSearchParams(); + form.append(`${type}_id`, String(id)); + form.append("mbz_id", mbzid); + return fetch(`/apis/web/v1/mbzid`, { + method: "PATCH", + body: form, + }); +} function getAlbum(id: number): Promise { return fetch(`/apis/web/v1/album?id=${id}`).then( (r) => r.json() as Promise @@ -318,6 +331,7 @@ export { createAlias, deleteAlias, setPrimaryAlias, + updateMbzId, getApiKeys, createApiKey, deleteApiKey, diff --git a/client/app/components/modals/EditModal/EditModal.tsx b/client/app/components/modals/EditModal/EditModal.tsx index cbced25..a5c981e 100644 --- a/client/app/components/modals/EditModal/EditModal.tsx +++ b/client/app/components/modals/EditModal/EditModal.tsx @@ -4,6 +4,7 @@ import { deleteAlias, getAliases, setPrimaryAlias, + updateMbzId, type Alias, } from "api/api"; import { Modal } from "../Modal"; @@ -12,6 +13,7 @@ import { useEffect, useState } from "react"; import { Trash } from "lucide-react"; import SetVariousArtists from "./SetVariousArtist"; import SetPrimaryArtist from "./SetPrimaryArtist"; +import UpdateMbzID from "./UpdateMbzID"; interface Props { type: string; @@ -69,7 +71,7 @@ export default function EditModal({ open, setOpen, type, id }: Props) { const handleNewAlias = () => { setError(undefined); if (input === "") { - setError("alias must be provided"); + setError("no input"); return; } setLoading(true); @@ -156,6 +158,7 @@ export default function EditModal({ open, setOpen, type, id }: Props) { {type.toLowerCase() === "track" && ( )} + ); diff --git a/client/app/components/modals/EditModal/UpdateMbzID.tsx b/client/app/components/modals/EditModal/UpdateMbzID.tsx new file mode 100644 index 0000000..d1191a4 --- /dev/null +++ b/client/app/components/modals/EditModal/UpdateMbzID.tsx @@ -0,0 +1,52 @@ +import { updateMbzId } from "api/api"; +import { useState } from "react"; +import { AsyncButton } from "~/components/AsyncButton"; + +interface Props { + type: string; + id: number; +} + +export default function UpdateMbzID({ type, id }: Props) { + const [err, setError] = useState(); + const [input, setInput] = useState(""); + const [loading, setLoading] = useState(false); + const [mbzid, setMbzid] = useState<"">(); + const [success, setSuccess] = useState(""); + + const handleUpdateMbzID = () => { + setError(undefined); + if (input === "") { + setError("no input"); + return; + } + setLoading(true); + updateMbzId(type, id, input).then((r) => { + if (r.ok) { + } else { + r.json().then((r) => setError(r.error)); + } + }); + setLoading(false); + }; + + return ( +
+

Update MusicBrainz ID

+
+ setInput(e.target.value)} + /> + + Submit + + {err &&

{err}

} + {success &&

{success}

} +
+
+ ); +}