Fix tsc linter!

This commit is contained in:
wvffle 2022-08-31 17:33:52 +00:00 committed by Georg Krause
parent 2c364ce201
commit 95e3dcb130
3 changed files with 21 additions and 18 deletions

View File

@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import type { BackendError, Channel, Upload } from '~/types' import type { BackendError, Channel, Upload, Track } from '~/types'
import type { VueUploadItem } from 'vue-upload-component' import type { VueUploadItem } from 'vue-upload-component'
import { computed, ref, reactive, watchEffect, watch } from 'vue' import { computed, ref, reactive, watchEffect, watch } from 'vue'
@ -44,7 +44,7 @@ interface UploadStatus {
interface UploadedFile extends VueUploadItem { interface UploadedFile extends VueUploadItem {
_fileObj?: VueUploadItem _fileObj?: VueUploadItem
removed: boolean removed: boolean
metadata: Record<string, string> metadata: Metadata
} }
const emit = defineEmits<Events>() const emit = defineEmits<Events>()
@ -134,6 +134,7 @@ whenever(() => values.channel !== null, async () => {
draftUploads.value = response.data.results as Upload[] draftUploads.value = response.data.results as Upload[]
for (const upload of response.data.results as Upload[]) { for (const upload of response.data.results as Upload[]) {
// @ts-expect-error TODO (wvffle): Resolve type errors when API client is done
uploadImportData[upload.uuid] = upload.import_metadata ?? {} uploadImportData[upload.uuid] = upload.import_metadata ?? {}
} }
} catch (error) { } catch (error) {
@ -211,10 +212,11 @@ const uploadedFilesById = computed(() => uploadedFiles.value.reduce((acc: Record
// //
// Metadata // Metadata
// //
const uploadImportData = reactive({} as Record<string, Record<string, string>>) type Metadata = Pick<Track, 'title' | 'description' | 'position' | 'tags'> & { cover: string }
const uploadImportData = reactive({} as Record<string, Metadata>)
const audioMetadata = reactive({} as Record<string, Record<string, string>>) const audioMetadata = reactive({} as Record<string, Record<string, string>>)
const uploadData = reactive({} as Record<string, { import_metadata: Record<string, string> }>) const uploadData = reactive({} as Record<string, { import_metadata: Metadata }>)
const patchUpload = async (id: string, data: Record<string, Record<string, string>>) => { const patchUpload = async (id: string, data: Record<string, Metadata>) => {
const response = await axios.patch(`uploads/${id}/`, data) const response = await axios.patch(`uploads/${id}/`, data)
uploadData[id] = response.data uploadData[id] = response.data
uploadImportData[id] = response.data.import_metadata uploadImportData[id] = response.data.import_metadata
@ -232,9 +234,9 @@ const fetchAudioMetadata = async (uuid: string) => {
uploadImportData[uuid].title = response.data.title uploadImportData[uuid].title = response.data.title
} }
for (const key of ['title', 'position', 'tags']) { for (const key of ['title', 'position', 'tags'] as const) {
if (uploadImportData[uuid][key] === undefined) { if (uploadImportData[uuid][key] === undefined) {
uploadImportData[uuid][key] = response.data[key] uploadImportData[uuid][key] = response.data[key] as never
} }
} }
@ -248,7 +250,7 @@ const fetchAudioMetadata = async (uuid: string) => {
watchEffect(async () => { watchEffect(async () => {
for (const file of files.value) { for (const file of files.value) {
if (file.response?.uuid && audioMetadata[file.response.uuid] === undefined) { if (file.response?.uuid && audioMetadata[file.response.uuid] === undefined) {
uploadData[file.response.uuid] = file.response as { import_metadata: Record<string, string> } uploadData[file.response.uuid] = file.response as { import_metadata: Metadata }
uploadImportData[file.response.uuid] = file.response.import_metadata uploadImportData[file.response.uuid] = file.response.import_metadata
fetchAudioMetadata(file.response.uuid) fetchAudioMetadata(file.response.uuid)
} }

View File

@ -1,35 +1,36 @@
<script setup lang="ts"> <script setup lang="ts">
import type { Upload, Tag } from '~/types' import type { Upload, Tag, Track } from '~/types'
import { reactive, computed, watch } from 'vue' import { reactive, computed, watch } from 'vue'
import { useVModel } from '@vueuse/core'
import TagsSelector from '~/components/library/TagsSelector.vue' import TagsSelector from '~/components/library/TagsSelector.vue'
import AttachmentInput from '~/components/common/AttachmentInput.vue' import AttachmentInput from '~/components/common/AttachmentInput.vue'
type Values = Pick<Track, 'title' | 'description' | 'position' | 'tags'> & { cover: string }
interface Events { interface Events {
(e: 'update:values', values: Values): void (e: 'update:values', values: Values): void
} }
interface Props { interface Props {
upload: Upload upload: Upload
values: Values values: Values | null
} }
type Values = (Record<string, string> & { tags?: Tag[] }) | null
const emit = defineEmits<Events>() const emit = defineEmits<Events>()
const props = withDefaults(defineProps<Props>(), { const props = withDefaults(defineProps<Props>(), {
values: null values: null
}) })
const newValues = reactive<Exclude<Values, null>>({ const newValues = reactive<Omit<Values, 'tags'> & { tags: Tag[] }>({
...(props.values ?? props.upload.import_metadata), ...(props.values ?? props.upload.import_metadata ?? {}) as Values,
tags: (props.values ?? props.upload.import_metadata)?.tags ?? [] as Tag[] tags: ((props.values ?? props.upload.import_metadata)?.tags?.map(name => ({ name })) ?? []) as Tag[]
}) })
const isLoading = computed(() => !props.upload) const isLoading = computed(() => !props.upload)
watch(newValues, (values) => emit('update:values', values), { immediate: true }) watch(newValues, (values) => emit('update:values', {
...values,
tags: values.tags?.map(({ name }) => name)
}), { immediate: true })
</script> </script>
<template> <template>

View File

@ -294,7 +294,7 @@ export interface Upload {
error_code: string error_code: string
} }
import_metadata?: Record<string, string> & { tags?: Tag[] } import_metadata?: Record<string, string> & { tags?: string[] }
} }
// Profile stuff // Profile stuff