diff --git a/web/src/App.vue b/web/src/App.vue index f2997b3..e0acf22 100644 --- a/web/src/App.vue +++ b/web/src/App.vue @@ -1,7 +1,7 @@ diff --git a/web/src/components/DropDown.vue b/web/src/components/DropDown.vue index ec74bd5..16b1814 100644 --- a/web/src/components/DropDown.vue +++ b/web/src/components/DropDown.vue @@ -1,14 +1,115 @@ + + diff --git a/web/src/components/HelloWorld.vue b/web/src/components/HelloWorld.vue deleted file mode 100644 index eff59f1..0000000 --- a/web/src/components/HelloWorld.vue +++ /dev/null @@ -1,44 +0,0 @@ - - - - - diff --git a/web/src/components/LibraryCard.vue b/web/src/components/LibraryCard.vue index 32e87b8..5196423 100644 --- a/web/src/components/LibraryCard.vue +++ b/web/src/components/LibraryCard.vue @@ -1,9 +1,12 @@ - - diff --git a/web/src/components/TheWelcome.vue b/web/src/components/TheWelcome.vue deleted file mode 100644 index 68a970a..0000000 --- a/web/src/components/TheWelcome.vue +++ /dev/null @@ -1,95 +0,0 @@ - - - diff --git a/web/src/components/WelcomeItem.vue b/web/src/components/WelcomeItem.vue deleted file mode 100644 index ac366d0..0000000 --- a/web/src/components/WelcomeItem.vue +++ /dev/null @@ -1,86 +0,0 @@ - - - diff --git a/web/src/components/__tests__/HelloWorld.spec.js b/web/src/components/__tests__/HelloWorld.spec.js deleted file mode 100644 index 2533202..0000000 --- a/web/src/components/__tests__/HelloWorld.spec.js +++ /dev/null @@ -1,11 +0,0 @@ -import { describe, it, expect } from 'vitest' - -import { mount } from '@vue/test-utils' -import HelloWorld from '../HelloWorld.vue' - -describe('HelloWorld', () => { - it('renders properly', () => { - const wrapper = mount(HelloWorld, { props: { msg: 'Hello Vitest' } }) - expect(wrapper.text()).toContain('Hello Vitest') - }) -}) diff --git a/web/src/components/icons/IconCommunity.vue b/web/src/components/icons/IconCommunity.vue deleted file mode 100644 index 2dc8b05..0000000 --- a/web/src/components/icons/IconCommunity.vue +++ /dev/null @@ -1,7 +0,0 @@ - diff --git a/web/src/components/icons/IconDocumentation.vue b/web/src/components/icons/IconDocumentation.vue deleted file mode 100644 index 6d4791c..0000000 --- a/web/src/components/icons/IconDocumentation.vue +++ /dev/null @@ -1,7 +0,0 @@ - diff --git a/web/src/components/icons/IconEcosystem.vue b/web/src/components/icons/IconEcosystem.vue deleted file mode 100644 index c3a4f07..0000000 --- a/web/src/components/icons/IconEcosystem.vue +++ /dev/null @@ -1,7 +0,0 @@ - diff --git a/web/src/components/icons/IconSupport.vue b/web/src/components/icons/IconSupport.vue deleted file mode 100644 index 7452834..0000000 --- a/web/src/components/icons/IconSupport.vue +++ /dev/null @@ -1,7 +0,0 @@ - diff --git a/web/src/components/icons/IconTooling.vue b/web/src/components/icons/IconTooling.vue deleted file mode 100644 index 660598d..0000000 --- a/web/src/components/icons/IconTooling.vue +++ /dev/null @@ -1,19 +0,0 @@ - - diff --git a/web/src/router/index.js b/web/src/router/index.js index 61ab587..3eea61f 100644 --- a/web/src/router/index.js +++ b/web/src/router/index.js @@ -1,13 +1,11 @@ import { createRouter, createWebHistory } from 'vue-router' -import HomeView from '../views/HomeView.vue' const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), routes: [ { path: '/', - name: 'home', - component: HomeView, + redirect: '/music', }, { path: '/music', @@ -27,9 +25,6 @@ const router = createRouter({ { path: '/about', name: 'about', - // route level code-splitting - // this generates a separate chunk (About.[hash].js) for this route - // which is lazy-loaded when the route is visited. component: () => import('../views/AboutView.vue'), }, ], diff --git a/web/src/stores/butterfliu.js b/web/src/stores/butterfliu.js index d3fe9d4..d91c711 100644 --- a/web/src/stores/butterfliu.js +++ b/web/src/stores/butterfliu.js @@ -3,63 +3,102 @@ import { defineStore } from 'pinia' export const useButterfliuStore = defineStore('butterfliu', () => { const libraries = ref([]) + const error = ref(null) + async function fetchLibraries() { - libraries.value = await (await fetch('/api/libraries')).json() + try { + error.value = null + const resp = await fetch('/api/libraries') + if (!resp.ok) throw new Error(`HTTP ${resp.status}`) + libraries.value = await resp.json() + } catch (e) { + error.value = e.message + console.error('Failed to fetch libraries:', e) + } } async function scanLibrary(id) { - const resp = await fetch('/api/libraries/' + id + '/scan', { - method: 'POST', - }) - const result = await resp.json() - - console.log(result) + try { + error.value = null + const resp = await fetch(`/api/libraries/${id}/scan`, { + method: 'POST', + }) + if (!resp.ok) throw new Error(`HTTP ${resp.status}`) + const result = await resp.json() + return result + } catch (e) { + error.value = e.message + console.error('Failed to scan library:', e) + } } - async function addLibrary(name, path) { - const resp = await fetch('/api/libraries', { - method: 'POST', - body: JSON.stringify({ - name, - path, - }), - }) - const result = await resp.json() - console.log(result) + async function addLibrary(name, path) { + try { + error.value = null + const resp = await fetch('/api/libraries', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ name, path }), + }) + if (!resp.ok) throw new Error(`HTTP ${resp.status}`) + const result = await resp.json() + return result + } catch (e) { + error.value = e.message + console.error('Failed to add library:', e) + } } async function deleteLibrary(id) { - const resp = await fetch('/api/libraries/' + id, { - method: 'DELETE', - }) - const result = await resp.json() - - console.log(result) + try { + error.value = null + const resp = await fetch(`/api/libraries/${id}`, { + method: 'DELETE', + }) + if (!resp.ok) throw new Error(`HTTP ${resp.status}`) + const result = await resp.json() + return result + } catch (e) { + error.value = e.message + console.error('Failed to delete library:', e) + } } async function fetchLibrarySongs(id) { - const resp = await fetch('/api/libraries/' + id + '/songs') - const songs = await resp.json() - return songs - } - - async function fetchArtists() { - const resp = await fetch('/api/artists') - const artists = await resp.json() - return artists - } - - async function fetchAlbums() { - const resp = await fetch('/api/albums') - const albums = await resp.json() - return albums + const resp = await fetch(`/api/libraries/${id}/songs`) + if (!resp.ok) throw new Error(`HTTP ${resp.status}`) + return resp.json() } async function fetchAllSongs() { const resp = await fetch('/api/songs') - const songs = await resp.json() - return songs + if (!resp.ok) throw new Error(`HTTP ${resp.status}`) + return resp.json() } - return { libraries, fetchLibraries, scanLibrary, addLibrary, deleteLibrary, fetchLibrarySongs, fetchArtists, fetchAlbums, fetchAllSongs } + // TODO: 用于未来艺术家/专辑页面 + async function fetchArtists() { + const resp = await fetch('/api/artists') + if (!resp.ok) throw new Error(`HTTP ${resp.status}`) + return resp.json() + } + + async function fetchAlbums() { + const resp = await fetch('/api/albums') + if (!resp.ok) throw new Error(`HTTP ${resp.status}`) + return resp.json() + } + + return { + libraries, + error, + fetchLibraries, + scanLibrary, + addLibrary, + deleteLibrary, + fetchLibrarySongs, + fetchAllSongs, + fetchArtists, + fetchAlbums, + } }) diff --git a/web/src/stores/counter.js b/web/src/stores/counter.js deleted file mode 100644 index b6757ba..0000000 --- a/web/src/stores/counter.js +++ /dev/null @@ -1,12 +0,0 @@ -import { ref, computed } from 'vue' -import { defineStore } from 'pinia' - -export const useCounterStore = defineStore('counter', () => { - const count = ref(0) - const doubleCount = computed(() => count.value * 2) - function increment() { - count.value++ - } - - return { count, doubleCount, increment } -}) diff --git a/web/src/views/AboutView.vue b/web/src/views/AboutView.vue index f8cfde6..7da2d5f 100644 --- a/web/src/views/AboutView.vue +++ b/web/src/views/AboutView.vue @@ -1,7 +1,250 @@ - + + + diff --git a/web/src/views/HomeView.vue b/web/src/views/HomeView.vue deleted file mode 100644 index 6bb706f..0000000 --- a/web/src/views/HomeView.vue +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/web/src/views/MusicView.vue b/web/src/views/MusicView.vue index f3b8481..d8d3fd8 100644 --- a/web/src/views/MusicView.vue +++ b/web/src/views/MusicView.vue @@ -1,15 +1,46 @@