-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dba34fc
commit 41d173c
Showing
7 changed files
with
161 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<script setup lang="ts"> | ||
import type { MaruSongDataParsed } from '@marure/schema' | ||
import type { Reactive } from 'vue' | ||
const props = defineProps<{ | ||
stateRef: Reactive<MaruSongDataParsed> | ||
errors: Reactive<ValidationErrors> | ||
}>() | ||
const stateRef = toRef(props.stateRef) | ||
const { title, artists, tags } = toRefs(props.errors) | ||
const artistsString = computed({ | ||
get: () => (stateRef.value.artists || []).join(', '), | ||
set: (value: string) => { | ||
stateRef.value.artists = value.split(',').map(v => v.trim()) | ||
}, | ||
}) | ||
const tagsString = computed({ | ||
get: () => (stateRef.value.tags || []).join(', '), | ||
set: (value: string) => { | ||
stateRef.value.tags = value.split(',').map(v => v.trim()) | ||
}, | ||
}) | ||
const offsetString = computed({ | ||
get: () => String(stateRef.value.offset || ''), | ||
set: (value: string) => { | ||
stateRef.value.offset = Number(value) | ||
}, | ||
}) | ||
const notesString = computed({ | ||
get: () => (stateRef.value.notes || []).join('\n'), | ||
set: (value: string) => { | ||
stateRef.value.notes = value.split('\n') | ||
}, | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div flex="~ col gap-2" max-w-150> | ||
<h1 my4 text-2xl> | ||
{{ $t("lyrics.editLyrics") }} | ||
</h1> | ||
<TextInput :model-value="stateRef.youtube" label="YouTube ID" input-class="font-mono" disabled /> | ||
<div> | ||
<TextInput v-model="stateRef.title" :label="$t('song.title')" /> | ||
<span class="text-sm text-red-500">{{ title }}</span> | ||
</div> | ||
<div> | ||
<TextInput v-model="artistsString" :label="$t('song.artist')" /> | ||
<span v-if="artists" class="text-sm text-red-500">{{ artists }}</span> | ||
</div> | ||
<div> | ||
<TextInput v-model="tagsString" :label="$t('song.tags')" /> | ||
<span v-if="tags" class="text-sm text-red-500">{{ tags }}</span> | ||
</div> | ||
<TextInput v-model="offsetString" :label="$t('song.offset')" /> | ||
<TextInput | ||
v-model="notesString" | ||
:label="$t('common.notes')" | ||
type="textarea" | ||
input-class="h-30" | ||
/> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import type { MaruSongDataParsed } from '@marure/schema' | ||
import { useNuxtApp } from 'nuxt/app' | ||
import { reactive } from 'vue' | ||
|
||
export interface ValidationErrors { | ||
youtube: string | ||
title: string | ||
artists: string | ||
tags: string | ||
offset?: string | ||
notes?: string | ||
} | ||
|
||
export function useValidation(stateRef: MaruSongDataParsed) { | ||
const errors = reactive<ValidationErrors>({ | ||
youtube: '', | ||
title: '', | ||
artists: '', | ||
tags: '', | ||
}) | ||
const nuxtApp = useNuxtApp() | ||
const { t } = nuxtApp.$i18n | ||
|
||
const validate = (): boolean => { | ||
let isValid = true | ||
|
||
errors.youtube = '' | ||
errors.title = '' | ||
errors.artists = '' | ||
errors.tags = '' | ||
|
||
if (!stateRef.youtube || !stateRef.youtube.trim()) { | ||
errors.youtube = t('editor.validator.youtube') | ||
isValid = false | ||
} | ||
|
||
if (!stateRef.title || !stateRef.title.trim()) { | ||
errors.title = t('editor.validator.title') | ||
isValid = false | ||
} | ||
if (!stateRef.artists || stateRef.artists?.includes('')) { | ||
errors.artists = t('editor.validator.artists') | ||
isValid = false | ||
} | ||
|
||
if (!stateRef.tags || stateRef.tags?.includes('')) { | ||
errors.tags = t('editor.validator.tags') | ||
isValid = false | ||
} | ||
return isValid | ||
} | ||
|
||
return { | ||
errors, | ||
validate, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters