Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f444782ab2 | ||
|
|
326d080e2c | ||
|
|
ffd2c8d3fa | ||
|
|
e622242256 | ||
|
|
15eb38a9d7 |
24
subsonic-ui-svelte/.gitignore
vendored
Normal file
24
subsonic-ui-svelte/.gitignore
vendored
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
pnpm-debug.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
|
||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
dist-ssr
|
||||||
|
*.local
|
||||||
|
|
||||||
|
# Editor directories and files
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/extensions.json
|
||||||
|
.idea
|
||||||
|
.DS_Store
|
||||||
|
*.suo
|
||||||
|
*.ntvs*
|
||||||
|
*.njsproj
|
||||||
|
*.sln
|
||||||
|
*.sw?
|
||||||
3
subsonic-ui-svelte/.vscode/extensions.json
vendored
Normal file
3
subsonic-ui-svelte/.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"recommendations": ["svelte.svelte-vscode"]
|
||||||
|
}
|
||||||
47
subsonic-ui-svelte/README.md
Normal file
47
subsonic-ui-svelte/README.md
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
# Svelte + TS + Vite
|
||||||
|
|
||||||
|
This template should help get you started developing with Svelte and TypeScript in Vite.
|
||||||
|
|
||||||
|
## Recommended IDE Setup
|
||||||
|
|
||||||
|
[VS Code](https://code.visualstudio.com/) + [Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode).
|
||||||
|
|
||||||
|
## Need an official Svelte framework?
|
||||||
|
|
||||||
|
Check out [SvelteKit](https://github.com/sveltejs/kit#readme), which is also powered by Vite. Deploy anywhere with its serverless-first approach and adapt to various platforms, with out of the box support for TypeScript, SCSS, and Less, and easily-added support for mdsvex, GraphQL, PostCSS, Tailwind CSS, and more.
|
||||||
|
|
||||||
|
## Technical considerations
|
||||||
|
|
||||||
|
**Why use this over SvelteKit?**
|
||||||
|
|
||||||
|
- It brings its own routing solution which might not be preferable for some users.
|
||||||
|
- It is first and foremost a framework that just happens to use Vite under the hood, not a Vite app.
|
||||||
|
|
||||||
|
This template contains as little as possible to get started with Vite + TypeScript + Svelte, while taking into account the developer experience with regards to HMR and intellisense. It demonstrates capabilities on par with the other `create-vite` templates and is a good starting point for beginners dipping their toes into a Vite + Svelte project.
|
||||||
|
|
||||||
|
Should you later need the extended capabilities and extensibility provided by SvelteKit, the template has been structured similarly to SvelteKit so that it is easy to migrate.
|
||||||
|
|
||||||
|
**Why `global.d.ts` instead of `compilerOptions.types` inside `jsconfig.json` or `tsconfig.json`?**
|
||||||
|
|
||||||
|
Setting `compilerOptions.types` shuts out all other types not explicitly listed in the configuration. Using triple-slash references keeps the default TypeScript setting of accepting type information from the entire workspace, while also adding `svelte` and `vite/client` type information.
|
||||||
|
|
||||||
|
**Why include `.vscode/extensions.json`?**
|
||||||
|
|
||||||
|
Other templates indirectly recommend extensions via the README, but this file allows VS Code to prompt the user to install the recommended extension upon opening the project.
|
||||||
|
|
||||||
|
**Why enable `allowJs` in the TS template?**
|
||||||
|
|
||||||
|
While `allowJs: false` would indeed prevent the use of `.js` files in the project, it does not prevent the use of JavaScript syntax in `.svelte` files. In addition, it would force `checkJs: false`, bringing the worst of both worlds: not being able to guarantee the entire codebase is TypeScript, and also having worse typechecking for the existing JavaScript. In addition, there are valid use cases in which a mixed codebase may be relevant.
|
||||||
|
|
||||||
|
**Why is HMR not preserving my local component state?**
|
||||||
|
|
||||||
|
HMR state preservation comes with a number of gotchas! It has been disabled by default in both `svelte-hmr` and `@sveltejs/vite-plugin-svelte` due to its often surprising behavior. You can read the details [here](https://github.com/rixo/svelte-hmr#svelte-hmr).
|
||||||
|
|
||||||
|
If you have state that's important to retain within a component, consider creating an external store which would not be replaced by HMR.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// store.ts
|
||||||
|
// An extremely simple external store
|
||||||
|
import { writable } from 'svelte/store'
|
||||||
|
export default writable(0)
|
||||||
|
```
|
||||||
13
subsonic-ui-svelte/index.html
Normal file
13
subsonic-ui-svelte/index.html
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>Discord music bot remote</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="app"></div>
|
||||||
|
<script type="module" src="/src/main.ts"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
1343
subsonic-ui-svelte/package-lock.json
generated
Normal file
1343
subsonic-ui-svelte/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
21
subsonic-ui-svelte/package.json
Normal file
21
subsonic-ui-svelte/package.json
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"name": "subsonic-ui-svelte",
|
||||||
|
"private": true,
|
||||||
|
"version": "0.0.0",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "vite",
|
||||||
|
"build": "vite build",
|
||||||
|
"preview": "vite preview",
|
||||||
|
"check": "svelte-check --tsconfig ./tsconfig.json && tsc -p tsconfig.node.json"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@sveltejs/vite-plugin-svelte": "^5.0.2",
|
||||||
|
"@tsconfig/svelte": "^5.0.4",
|
||||||
|
"svelte": "^5.14.3",
|
||||||
|
"svelte-check": "^4.1.1",
|
||||||
|
"tslib": "^2.8.1",
|
||||||
|
"typescript": "~5.6.2",
|
||||||
|
"vite": "^6.0.3"
|
||||||
|
}
|
||||||
|
}
|
||||||
1
subsonic-ui-svelte/public/vite.svg
Normal file
1
subsonic-ui-svelte/public/vite.svg
Normal file
@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
||||||
|
After Width: | Height: | Size: 1.5 KiB |
12
subsonic-ui-svelte/src/App.svelte
Normal file
12
subsonic-ui-svelte/src/App.svelte
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import ArtistList from "./components/ArtistList.svelte";
|
||||||
|
import Search from './components/Search.svelte'; // Import the Search component
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<h1>Navidrome Frontend</h1>
|
||||||
|
<Search /> <!-- Add the Search component -->
|
||||||
|
<ArtistList />
|
||||||
|
</main>
|
||||||
|
|
||||||
|
|
||||||
80
subsonic-ui-svelte/src/app.css
Normal file
80
subsonic-ui-svelte/src/app.css
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
:root {
|
||||||
|
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
|
||||||
|
line-height: 1.5;
|
||||||
|
font-weight: 400;
|
||||||
|
|
||||||
|
color-scheme: light dark;
|
||||||
|
color: rgba(255, 255, 255, 0.87);
|
||||||
|
background-color: #242424;
|
||||||
|
|
||||||
|
font-synthesis: none;
|
||||||
|
text-rendering: optimizeLegibility;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
-moz-osx-font-smoothing: grayscale;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
font-weight: 500;
|
||||||
|
color: #646cff;
|
||||||
|
text-decoration: inherit;
|
||||||
|
}
|
||||||
|
a:hover {
|
||||||
|
color: #535bf2;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
display: flex;
|
||||||
|
place-items: center;
|
||||||
|
min-width: 320px;
|
||||||
|
min-height: 100vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: 3.2em;
|
||||||
|
line-height: 1.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card {
|
||||||
|
padding: 2em;
|
||||||
|
}
|
||||||
|
|
||||||
|
#app {
|
||||||
|
max-width: 1280px;
|
||||||
|
width: 100%;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 2rem;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
border-radius: 8px;
|
||||||
|
border: 1px solid transparent;
|
||||||
|
padding: 0.6em 1.2em;
|
||||||
|
font-size: 1em;
|
||||||
|
font-weight: 500;
|
||||||
|
font-family: inherit;
|
||||||
|
background-color: #1a1a1a;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: border-color 0.25s;
|
||||||
|
}
|
||||||
|
button:hover {
|
||||||
|
border-color: #646cff;
|
||||||
|
}
|
||||||
|
button:focus,
|
||||||
|
button:focus-visible {
|
||||||
|
outline: 4px auto -webkit-focus-ring-color;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-color-scheme: light) {
|
||||||
|
:root {
|
||||||
|
color: #213547;
|
||||||
|
background-color: #ffffff;
|
||||||
|
}
|
||||||
|
a:hover {
|
||||||
|
color: #747bff;
|
||||||
|
}
|
||||||
|
button {
|
||||||
|
background-color: #f9f9f9;
|
||||||
|
}
|
||||||
|
}
|
||||||
1
subsonic-ui-svelte/src/assets/svelte.svg
Normal file
1
subsonic-ui-svelte/src/assets/svelte.svg
Normal file
@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="26.6" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 308"><path fill="#FF3E00" d="M239.682 40.707C211.113-.182 154.69-12.301 113.895 13.69L42.247 59.356a82.198 82.198 0 0 0-37.135 55.056a86.566 86.566 0 0 0 8.536 55.576a82.425 82.425 0 0 0-12.296 30.719a87.596 87.596 0 0 0 14.964 66.244c28.574 40.893 84.997 53.007 125.787 27.016l71.648-45.664a82.182 82.182 0 0 0 37.135-55.057a86.601 86.601 0 0 0-8.53-55.577a82.409 82.409 0 0 0 12.29-30.718a87.573 87.573 0 0 0-14.963-66.244"></path><path fill="#FFF" d="M106.889 270.841c-23.102 6.007-47.497-3.036-61.103-22.648a52.685 52.685 0 0 1-9.003-39.85a49.978 49.978 0 0 1 1.713-6.693l1.35-4.115l3.671 2.697a92.447 92.447 0 0 0 28.036 14.007l2.663.808l-.245 2.659a16.067 16.067 0 0 0 2.89 10.656a17.143 17.143 0 0 0 18.397 6.828a15.786 15.786 0 0 0 4.403-1.935l71.67-45.672a14.922 14.922 0 0 0 6.734-9.977a15.923 15.923 0 0 0-2.713-12.011a17.156 17.156 0 0 0-18.404-6.832a15.78 15.78 0 0 0-4.396 1.933l-27.35 17.434a52.298 52.298 0 0 1-14.553 6.391c-23.101 6.007-47.497-3.036-61.101-22.649a52.681 52.681 0 0 1-9.004-39.849a49.428 49.428 0 0 1 22.34-33.114l71.664-45.677a52.218 52.218 0 0 1 14.563-6.398c23.101-6.007 47.497 3.036 61.101 22.648a52.685 52.685 0 0 1 9.004 39.85a50.559 50.559 0 0 1-1.713 6.692l-1.35 4.116l-3.67-2.693a92.373 92.373 0 0 0-28.037-14.013l-2.664-.809l.246-2.658a16.099 16.099 0 0 0-2.89-10.656a17.143 17.143 0 0 0-18.398-6.828a15.786 15.786 0 0 0-4.402 1.935l-71.67 45.674a14.898 14.898 0 0 0-6.73 9.975a15.9 15.9 0 0 0 2.709 12.012a17.156 17.156 0 0 0 18.404 6.832a15.841 15.841 0 0 0 4.402-1.935l27.345-17.427a52.147 52.147 0 0 1 14.552-6.397c23.101-6.006 47.497 3.037 61.102 22.65a52.681 52.681 0 0 1 9.003 39.848a49.453 49.453 0 0 1-22.34 33.12l-71.664 45.673a52.218 52.218 0 0 1-14.563 6.398"></path></svg>
|
||||||
|
After Width: | Height: | Size: 1.9 KiB |
230
subsonic-ui-svelte/src/components/ArtistList.svelte
Normal file
230
subsonic-ui-svelte/src/components/ArtistList.svelte
Normal file
@ -0,0 +1,230 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { fetchFromAPI } from "../lib/api";
|
||||||
|
import { onMount } from "svelte";
|
||||||
|
|
||||||
|
type Artist = {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
albumCount: string;
|
||||||
|
coverArt: string;
|
||||||
|
artistImageUrl: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type GroupedArtists = {
|
||||||
|
name: string; // e.g., "A", "B", etc.
|
||||||
|
artists: Artist[];
|
||||||
|
};
|
||||||
|
|
||||||
|
type Album = {
|
||||||
|
id: string;
|
||||||
|
title: string;
|
||||||
|
artist: string;
|
||||||
|
coverArtUrl: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
let artistGroups: GroupedArtists[] = [];
|
||||||
|
let albums: Album[] = [];
|
||||||
|
let selectedArtistId: string | null = null;
|
||||||
|
let error: string | null = null;
|
||||||
|
|
||||||
|
async function fetchAlbumsForArtist(id: string) {
|
||||||
|
try {
|
||||||
|
const response = await fetchFromAPI("getArtist", { id });
|
||||||
|
const albums = response["subsonic-response"]?.artist?.album || [];
|
||||||
|
|
||||||
|
// Fetch the cover art for each album
|
||||||
|
for (const album of albums) {
|
||||||
|
const coverArtUrl = await fetchCoverArt(album.id);
|
||||||
|
album.coverArtUrl = coverArtUrl; // Add the full URL to the album object
|
||||||
|
}
|
||||||
|
|
||||||
|
return albums;
|
||||||
|
} catch (err) {
|
||||||
|
error = (err as Error).message;
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchCoverArt(albumId: string) {
|
||||||
|
try {
|
||||||
|
const blob = await fetchFromAPI("getCoverArt", {
|
||||||
|
id: albumId,
|
||||||
|
size: "150",
|
||||||
|
});
|
||||||
|
|
||||||
|
// Convert the Blob into a URL that can be used in an <img> tag
|
||||||
|
const coverArtUrl = URL.createObjectURL(blob);
|
||||||
|
|
||||||
|
return coverArtUrl;
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Error fetching cover art:", err);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let showAlbums = false;
|
||||||
|
|
||||||
|
const toggleView = () => {
|
||||||
|
showAlbums = !showAlbums;
|
||||||
|
};
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
try {
|
||||||
|
const data = await fetchFromAPI("getArtists", {});
|
||||||
|
artistGroups = (
|
||||||
|
data["subsonic-response"]?.artists?.index || []
|
||||||
|
).map((group: any) => ({
|
||||||
|
name: group.name,
|
||||||
|
artists: group.artist || [],
|
||||||
|
}));
|
||||||
|
} catch (err) {
|
||||||
|
error = (err as Error).message;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
async function handleArtistClick(artistId: string) {
|
||||||
|
selectedArtistId = artistId;
|
||||||
|
albums = await fetchAlbumsForArtist(artistId);
|
||||||
|
albums.length > 0 && (showAlbums = true);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if error}
|
||||||
|
<p>Error: {error}</p>
|
||||||
|
{:else if artistGroups.length === 0}
|
||||||
|
<p>Loading artists...</p>
|
||||||
|
{:else}
|
||||||
|
<div>
|
||||||
|
<button on:click={toggleView}>Toggle Albums/Artists</button>
|
||||||
|
{#if showAlbums}
|
||||||
|
{#if selectedArtistId && albums.length > 0}
|
||||||
|
<h3>Albums for {albums[0].artist}</h3>
|
||||||
|
<div class="album-list">
|
||||||
|
{#each albums as album}
|
||||||
|
<div class="album-card">
|
||||||
|
{#if album.coverArtUrl}
|
||||||
|
<img
|
||||||
|
src={album.coverArtUrl}
|
||||||
|
alt={album.title}
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
<h3>{album.title}</h3>
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
{:else}
|
||||||
|
{#each artistGroups as group}
|
||||||
|
<section>
|
||||||
|
<h2>{group.name}</h2>
|
||||||
|
<!-- Group name (e.g., A, B, etc.) -->
|
||||||
|
<div class="artist-container">
|
||||||
|
{#each group.artists as artist}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="artist-card"
|
||||||
|
on:click={() => handleArtistClick(artist.id)}
|
||||||
|
on:keydown={(e) =>
|
||||||
|
e.key === "Enter" &&
|
||||||
|
handleArtistClick(artist.id)}
|
||||||
|
aria-label="View albums by {artist.name}"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
src={artist.artistImageUrl}
|
||||||
|
alt={artist.name}
|
||||||
|
/>
|
||||||
|
<h3>{artist.name}</h3>
|
||||||
|
<p>{artist.albumCount} album(s)</p>
|
||||||
|
</button>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
{/each}
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.artist-container {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(
|
||||||
|
auto-fill,
|
||||||
|
minmax(150px, 1fr)
|
||||||
|
); /* Responsive grid */
|
||||||
|
gap: 16px;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0 auto;
|
||||||
|
width: 100%;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.artist-card {
|
||||||
|
width: 100%; /* Ensure cards take up full width of the column */
|
||||||
|
height: auto; /* Let the height adjust automatically */
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 8px;
|
||||||
|
overflow: hidden;
|
||||||
|
text-align: center;
|
||||||
|
background-color: #f9f9f9;
|
||||||
|
transition:
|
||||||
|
transform 0.2s,
|
||||||
|
box-shadow 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.artist-card:hover {
|
||||||
|
transform: translateY(-4px);
|
||||||
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.artist-card img {
|
||||||
|
width: 100%;
|
||||||
|
height: 150px;
|
||||||
|
object-fit: cover;
|
||||||
|
border-bottom: 1px solid #ddd;
|
||||||
|
}
|
||||||
|
|
||||||
|
.artist-card h3 {
|
||||||
|
margin: 8px 0;
|
||||||
|
font-size: 1.2rem;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.artist-card p {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
color: #555;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
margin-top: 24px;
|
||||||
|
font-size: 1.5rem;
|
||||||
|
color: #222;
|
||||||
|
}
|
||||||
|
|
||||||
|
.album-list {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(
|
||||||
|
auto-fill,
|
||||||
|
minmax(150px, 1fr)
|
||||||
|
); /* Flexible column layout */
|
||||||
|
gap: 1rem; /* Space between items */
|
||||||
|
justify-content: center;
|
||||||
|
padding: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.album-card {
|
||||||
|
text-align: center;
|
||||||
|
color: black;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 1rem;
|
||||||
|
background-color: #f9f9f9;
|
||||||
|
}
|
||||||
|
|
||||||
|
.album-card img {
|
||||||
|
width: 100%; /* Makes the image responsive within the card */
|
||||||
|
height: auto;
|
||||||
|
border-radius: 4px;
|
||||||
|
object-fit: cover; /* Ensures the image covers the area without distortion */
|
||||||
|
}
|
||||||
|
</style>
|
||||||
180
subsonic-ui-svelte/src/components/Search.svelte
Normal file
180
subsonic-ui-svelte/src/components/Search.svelte
Normal file
@ -0,0 +1,180 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { onMount } from "svelte";
|
||||||
|
import { fetchFromAPI } from "../lib/api"; // Assuming you have the `fetchFromAPI` function available
|
||||||
|
import { debounce } from "../lib/api";
|
||||||
|
|
||||||
|
let query = ""; // Search query input by user
|
||||||
|
let searchResults: any[] = []; // Store search results
|
||||||
|
let loading = false; // Loading state
|
||||||
|
let error: string = ""; // Error message
|
||||||
|
let coverArtUrls: Record<string, string> = {}; // Map to store cover art URLs for each album
|
||||||
|
|
||||||
|
// Function to handle search
|
||||||
|
const searchTracks = async () => {
|
||||||
|
if (!query.trim()) return; // Don't search if the query is empty
|
||||||
|
|
||||||
|
loading = true;
|
||||||
|
error = "";
|
||||||
|
try {
|
||||||
|
const params = { query }; // Search query parameter
|
||||||
|
const response = await fetchFromAPI("search2", params); // Use 'search2' endpoint to search for tracks
|
||||||
|
const songs = response["subsonic-response"].searchResult2.song; // Assuming 'searchResult2.song' contains the song list
|
||||||
|
|
||||||
|
// Map the search results to the component
|
||||||
|
searchResults = songs;
|
||||||
|
|
||||||
|
// For each song, fetch the cover art if not already loaded
|
||||||
|
for (const song of songs) {
|
||||||
|
if (!coverArtUrls[song.albumId]) {
|
||||||
|
// Fetch cover art for the album (we'll assume the albumId exists)
|
||||||
|
const coverArtUrl = await fetchCoverArt(song.albumId);
|
||||||
|
coverArtUrls[song.albumId] = coverArtUrl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
error = "Error fetching search results";
|
||||||
|
console.error(err);
|
||||||
|
} finally {
|
||||||
|
loading = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Fetch the cover art image URL for the given album ID
|
||||||
|
const fetchCoverArt = async (albumId: string): Promise<string> => {
|
||||||
|
const params = { id: albumId, size: "50" }; // Size parameter for resizing
|
||||||
|
const response = await fetchFromAPI("getCoverArt", params);
|
||||||
|
const coverArtUrl = URL.createObjectURL(response);
|
||||||
|
return coverArtUrl;
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatDuration = (seconds: number): string => {
|
||||||
|
const minutes = Math.floor(seconds / 60); // Get the full minutes
|
||||||
|
const remainingSeconds = seconds % 60; // Get the remaining seconds
|
||||||
|
return `${minutes}:${remainingSeconds.toString().padStart(2, "0")}`; // Ensure seconds are always 2 digits
|
||||||
|
};
|
||||||
|
|
||||||
|
const onInputChange = () => {
|
||||||
|
debounce(searchTracks, 500); // 500ms debounce delay
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="search-container">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
bind:value={query}
|
||||||
|
placeholder="Search for a song"
|
||||||
|
on:input={onInputChange}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{#if loading}
|
||||||
|
<div class="loading">Loading search results...</div>
|
||||||
|
{:else if error}
|
||||||
|
<div class="error">{error}</div>
|
||||||
|
{:else if searchResults.length > 0}
|
||||||
|
<ul class="search-results">
|
||||||
|
{#each searchResults as result, index}
|
||||||
|
<li class="search-result">
|
||||||
|
<!-- Display the search result number -->
|
||||||
|
<span class="result-number">{index + 1}.</span>
|
||||||
|
<!-- Display the album cover art -->
|
||||||
|
<img
|
||||||
|
src={coverArtUrls[result.albumId] ||
|
||||||
|
"/default-cover.jpg"}
|
||||||
|
alt={result.album}
|
||||||
|
class="album-cover"
|
||||||
|
/>
|
||||||
|
<div class="track-details">
|
||||||
|
<h4>{result.title}</h4>
|
||||||
|
<!-- Track name -->
|
||||||
|
<p>{result.artist}</p>
|
||||||
|
<!-- Artist name -->
|
||||||
|
</div>
|
||||||
|
<!-- Album and duration -->
|
||||||
|
<div class="album-duration">
|
||||||
|
<span>{formatDuration(result.duration)}</span>
|
||||||
|
<span>{result.album}</span>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
{/each}
|
||||||
|
</ul>
|
||||||
|
{:else}
|
||||||
|
<div class="loading">No results found</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.search-container {
|
||||||
|
margin: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
input {
|
||||||
|
padding: 0.5rem;
|
||||||
|
font-size: 1rem;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
width: 100%;
|
||||||
|
max-width: 400px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-result {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 16px; /* Space between elements */
|
||||||
|
padding: 8px 0;
|
||||||
|
border-bottom: 1px solid #ddd; /* Optional: add a separator */
|
||||||
|
position: relative; /* For precise positioning of the result number */
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.result-number {
|
||||||
|
font-weight: normal;
|
||||||
|
width: 40px; /* Fixed width for alignment */
|
||||||
|
text-align: right;
|
||||||
|
align-self: flex-end; /* Align with the bottom of the album image */
|
||||||
|
margin-bottom: 4px; /* Optional: fine-tune spacing */
|
||||||
|
}
|
||||||
|
|
||||||
|
.album-cover {
|
||||||
|
width: 50px;
|
||||||
|
height: 50px;
|
||||||
|
object-fit: cover;
|
||||||
|
border-radius: 4px; /* Optional: rounded corners */
|
||||||
|
}
|
||||||
|
|
||||||
|
.track-details {
|
||||||
|
flex-grow: 1;
|
||||||
|
margin-left: 8px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.track-details h4 {
|
||||||
|
font-weight: bold;
|
||||||
|
margin: 0;
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.track-details p {
|
||||||
|
margin: 4px 0 0;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
color: #555; /* Optional: gray color for artist name */
|
||||||
|
}
|
||||||
|
|
||||||
|
.album-duration {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-end;
|
||||||
|
text-align: right;
|
||||||
|
gap: 4px; /* Space between album name and duration */
|
||||||
|
}
|
||||||
|
|
||||||
|
.album-duration span {
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</style>
|
||||||
10
subsonic-ui-svelte/src/lib/Counter.svelte
Normal file
10
subsonic-ui-svelte/src/lib/Counter.svelte
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
let count: number = $state(0)
|
||||||
|
const increment = () => {
|
||||||
|
count += 1
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={increment}>
|
||||||
|
count is {count}
|
||||||
|
</button>
|
||||||
55
subsonic-ui-svelte/src/lib/api.ts
Normal file
55
subsonic-ui-svelte/src/lib/api.ts
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
const API_URL = "http://10.0.4.100:4534/rest"; // Replace with your server URL
|
||||||
|
const API_VERSION = "1.16.1"; // Replace with the Subsonic API version you're using
|
||||||
|
const API_PASSWORD = "xWPciqjr5VSVDvVS0sAH9L8gKEQm42"; // Replace with your actual token
|
||||||
|
const API_CLIENT = "SvelteApp";
|
||||||
|
|
||||||
|
|
||||||
|
export async function fetchFromAPI(endpoint: string, params: Record<string, string>) {
|
||||||
|
const url = new URL(`${API_URL}/${endpoint}`);
|
||||||
|
|
||||||
|
// If we're requesting an image (cover art), we don't need f: "json"
|
||||||
|
if (endpoint === "getCoverArt") {
|
||||||
|
// Add the parameters for the cover art request, but exclude f: "json"
|
||||||
|
url.search = new URLSearchParams({
|
||||||
|
...params,
|
||||||
|
v: API_VERSION,
|
||||||
|
c: API_CLIENT,
|
||||||
|
u: "drome", // Replace with your username
|
||||||
|
p: API_PASSWORD,
|
||||||
|
// Optionally you can add other params like size if needed
|
||||||
|
}).toString();
|
||||||
|
} else {
|
||||||
|
// For JSON requests, we add f: "json"
|
||||||
|
url.search = new URLSearchParams({
|
||||||
|
...params,
|
||||||
|
v: API_VERSION,
|
||||||
|
c: API_CLIENT,
|
||||||
|
f: "json", // Always request JSON format
|
||||||
|
u: "drome", // Replace with your username
|
||||||
|
p: API_PASSWORD
|
||||||
|
}).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make the fetch request
|
||||||
|
const response = await fetch(url.toString());
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`API request failed: ${response.statusText}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If it's a request for JSON, return the parsed JSON
|
||||||
|
if (endpoint !== "getCoverArt") {
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
// If it's a request for cover art, return the raw image data as a Blob
|
||||||
|
return response.blob();
|
||||||
|
}
|
||||||
|
|
||||||
|
let debounceTimeout: ReturnType<typeof setTimeout>;
|
||||||
|
|
||||||
|
export const debounce = (callback: () => void, delay: number) => {
|
||||||
|
if (debounceTimeout) {
|
||||||
|
clearTimeout(debounceTimeout); // Clear the previous timeout
|
||||||
|
}
|
||||||
|
debounceTimeout = setTimeout(callback, delay);
|
||||||
|
};
|
||||||
9
subsonic-ui-svelte/src/main.ts
Normal file
9
subsonic-ui-svelte/src/main.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import { mount } from 'svelte'
|
||||||
|
import './app.css'
|
||||||
|
import App from './App.svelte'
|
||||||
|
|
||||||
|
const app = mount(App, {
|
||||||
|
target: document.getElementById('app')!,
|
||||||
|
})
|
||||||
|
|
||||||
|
export default app
|
||||||
10400
subsonic-ui-svelte/src/test-files/Untitled-1.json
Normal file
10400
subsonic-ui-svelte/src/test-files/Untitled-1.json
Normal file
File diff suppressed because it is too large
Load Diff
2
subsonic-ui-svelte/src/vite-env.d.ts
vendored
Normal file
2
subsonic-ui-svelte/src/vite-env.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/// <reference types="svelte" />
|
||||||
|
/// <reference types="vite/client" />
|
||||||
7
subsonic-ui-svelte/svelte.config.js
Normal file
7
subsonic-ui-svelte/svelte.config.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
// Consult https://svelte.dev/docs#compile-time-svelte-preprocess
|
||||||
|
// for more information about preprocessors
|
||||||
|
preprocess: vitePreprocess(),
|
||||||
|
}
|
||||||
20
subsonic-ui-svelte/tsconfig.app.json
Normal file
20
subsonic-ui-svelte/tsconfig.app.json
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"extends": "@tsconfig/svelte/tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ESNext",
|
||||||
|
"useDefineForClassFields": true,
|
||||||
|
"module": "ESNext",
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
/**
|
||||||
|
* Typecheck JS in `.svelte` and `.js` files by default.
|
||||||
|
* Disable checkJs if you'd like to use dynamic types in JS.
|
||||||
|
* Note that setting allowJs false does not prevent the use
|
||||||
|
* of JS in `.svelte` files.
|
||||||
|
*/
|
||||||
|
"allowJs": true,
|
||||||
|
"checkJs": true,
|
||||||
|
"isolatedModules": true,
|
||||||
|
"moduleDetection": "force"
|
||||||
|
},
|
||||||
|
"include": ["src/**/*.ts", "src/**/*.js", "src/**/*.svelte"]
|
||||||
|
}
|
||||||
7
subsonic-ui-svelte/tsconfig.json
Normal file
7
subsonic-ui-svelte/tsconfig.json
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"files": [],
|
||||||
|
"references": [
|
||||||
|
{ "path": "./tsconfig.app.json" },
|
||||||
|
{ "path": "./tsconfig.node.json" }
|
||||||
|
]
|
||||||
|
}
|
||||||
24
subsonic-ui-svelte/tsconfig.node.json
Normal file
24
subsonic-ui-svelte/tsconfig.node.json
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
||||||
|
"target": "ES2022",
|
||||||
|
"lib": ["ES2023"],
|
||||||
|
"module": "ESNext",
|
||||||
|
"skipLibCheck": true,
|
||||||
|
|
||||||
|
/* Bundler mode */
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"allowImportingTsExtensions": true,
|
||||||
|
"isolatedModules": true,
|
||||||
|
"moduleDetection": "force",
|
||||||
|
"noEmit": true,
|
||||||
|
|
||||||
|
/* Linting */
|
||||||
|
"strict": true,
|
||||||
|
"noUnusedLocals": true,
|
||||||
|
"noUnusedParameters": true,
|
||||||
|
"noFallthroughCasesInSwitch": true,
|
||||||
|
"noUncheckedSideEffectImports": true
|
||||||
|
},
|
||||||
|
"include": ["vite.config.ts"]
|
||||||
|
}
|
||||||
7
subsonic-ui-svelte/vite.config.ts
Normal file
7
subsonic-ui-svelte/vite.config.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import { defineConfig } from 'vite'
|
||||||
|
import { svelte } from '@sveltejs/vite-plugin-svelte'
|
||||||
|
|
||||||
|
// https://vite.dev/config/
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [svelte()],
|
||||||
|
})
|
||||||
Loading…
Reference in New Issue
Block a user