Skip to content

Commit

Permalink
ui: artist/media editor nullify empty fields
Browse files Browse the repository at this point in the history
  • Loading branch information
NextFire committed Aug 24, 2024
1 parent 2601480 commit c7ea499
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
8 changes: 6 additions & 2 deletions ui/src/components/ArtistEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ export default function ArtistEditor(props: {
}) {
const [getName, setName] = createSignal(props.artist?.Name ?? "");
const [getAdditionalNames, setAdditionalNames] = createSignal(
props.artist?.AdditionalNames?.join("\n") ?? "",
props.artist?.AdditionalNames?.map((n) => n.Name).join("\n") ?? "",
);

const onsubmit: JSX.EventHandler<HTMLElement, SubmitEvent> = (e) => {
e.preventDefault();
const additionalNamesStr = getAdditionalNames().trim();
const additionalNames = additionalNamesStr
? additionalNamesStr.split("\n")
: null;
props.onSubmit({
name: getName(),
additional_names: getAdditionalNames().trim().split("\n"),
additional_names: additionalNames,
});
if (props.reset) {
(e.target as HTMLFormElement).reset();
Expand Down
10 changes: 6 additions & 4 deletions ui/src/components/KaraEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ export default function KaraEditor(props: {
const [getSourceMedia, setSourceMedia] = createSignal<
components["schemas"]["MediaDB"] | undefined
>(props.kara?.SourceMedia);
const [getSongOrder, setSongOrder] = createSignal<number | undefined>(
props.kara?.SongOrder,
);
const [getSongOrder, setSongOrder] = createSignal<
components["schemas"]["KaraInfo"]["song_order"] | undefined
>(props.kara?.SongOrder);
const [getMedias, setMedias] = createSignal<
components["schemas"]["MediaDB"][]
>(props.kara?.Medias ?? []);
Expand Down Expand Up @@ -86,9 +86,11 @@ export default function KaraEditor(props: {

const onsubmit: JSX.EventHandler<HTMLElement, SubmitEvent> = (e) => {
e.preventDefault();
const extraTitlesStr = getExtraTitles().trim();
const extraTitles = extraTitlesStr ? extraTitlesStr.split("\n") : null;
props.onSubmit({
title: getTitle(),
title_aliases: getExtraTitles().trim().split("\n") || null,
title_aliases: extraTitles,
authors: getAuthors().map((author) => author.ID) || null,
artists: getArtists().map((artist) => artist.ID) || null,
source_media: getSourceMedia()?.ID || 0,
Expand Down
8 changes: 6 additions & 2 deletions ui/src/components/MediaEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@ export default function MediaEditor(props: {
);
const [getName, setName] = createSignal(props.media?.name ?? "");
const [getAdditionalNames, setAdditionalNames] = createSignal(
props.media?.additional_name?.join("\n") ?? "",
props.media?.additional_name?.map((n) => n.Name).join("\n") ?? "",
);

const onsubmit: JSX.EventHandler<HTMLElement, SubmitEvent> = (e) => {
e.preventDefault();
const additionalNamesStr = getAdditionalNames().trim();
const additionalNames = additionalNamesStr
? additionalNamesStr.split("\n")
: null;
props.onSubmit({
media_type: getMediaType(),
name: getName(),
additional_names: getAdditionalNames().trim().split("\n"),
additional_names: additionalNames,
});
if (props.reset) {
(e.target as HTMLFormElement).reset();
Expand Down

0 comments on commit c7ea499

Please sign in to comment.