Skip to content

Commit d617353

Browse files
committed
fix: lyrics editor cannot reset all fields
1 parent a93b261 commit d617353

3 files changed

Lines changed: 18 additions & 4 deletions

File tree

app/Http/Controllers/Api/V1/MetadataController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ public function updateLyrics(LyricsUpdateRequest $request, Metadata $metadata) {
7676
throw new ModelNotFoundException('Song does not exist');
7777
}
7878

79-
unset($validated['track']);
80-
79+
$validated['title'] = $validated['track']; // Track is unused
8180
$validated['editor_id'] = Auth::id();
8281
$metadata->update($validated);
8382

app/Http/Requests/LyricsUpdateRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function authorize(): bool {
2020
*/
2121
public function rules(): array {
2222
return [
23-
'track' => 'required|max:255',
23+
'track' => 'required|max:255|min:1',
2424
'artist' => 'nullable|max:255',
2525
'album' => 'nullable|max:255',
2626
'lyrics' => 'nullable',

resources/js/components/forms/EditLyrics.vue

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,20 @@ const handleLoadLyricInfo = () => {
122122
form.fields.lyrics = stateLyrics.value;
123123
};
124124
125+
const handleResetFields = () => {
126+
form.fields = { ...form.fields, ...buildDefaultData() };
127+
resetLyrics();
128+
};
129+
130+
const buildDefaultData = () => {
131+
return {
132+
track: props.video.metadata?.title ?? props.video.title ?? '',
133+
lyrics: props.video.metadata?.lyrics ?? '',
134+
artist: props.video.metadata?.artist ?? '',
135+
album: props.video.metadata?.album ?? '',
136+
};
137+
};
138+
125139
onMounted(() => {
126140
handleLoadLyricInfo();
127141
});
@@ -195,7 +209,8 @@ watch(
195209
>
196210
Cancel
197211
</ButtonForm>
198-
<ButtonForm @click="handleSubmit" variant="submit" :disabled="form.processing"> Submit Details </ButtonForm>
212+
<ButtonForm @click="handleResetFields" variant="danger" :disabled="form.processing"> Reset </ButtonForm>
213+
<ButtonForm @click="handleSubmit" variant="submit" :disabled="form.processing"> Save </ButtonForm>
199214
</div>
200215
</form>
201216
</template>

0 commit comments

Comments
 (0)