diff --git a/main/background.ts b/main/background.ts index c95cef5..5160fef 100644 --- a/main/background.ts +++ b/main/background.ts @@ -10,6 +10,7 @@ import { createPlaylist, getAlbumWithSongs, getAlbums, + getLibraryStats, getPlaylistWithSongs, getPlaylists, getSettings, @@ -191,6 +192,11 @@ ipcMain.handle("createPlaylist", async (_, data: any) => { return playlist; }); +ipcMain.handle("getLibraryStats", async () => { + const stats = await getLibraryStats(); + return stats; +}); + ipcMain.handle("updatePlaylist", async (_, data: any) => { const playlist = await updatePlaylist(data); return playlist; diff --git a/main/helpers/db/connectDB.ts b/main/helpers/db/connectDB.ts index e99e0f9..fa61d4d 100644 --- a/main/helpers/db/connectDB.ts +++ b/main/helpers/db/connectDB.ts @@ -1,4 +1,4 @@ -import { and, eq, ilike, like } from "drizzle-orm"; +import { and, eq, ilike, like, sql } from "drizzle-orm"; import { albums, songs, settings, playlistSongs, playlists } from "./schema"; import fs from "fs"; import { parseFile, selectCover } from "music-metadata"; @@ -11,6 +11,20 @@ const db: BetterSQLite3Database = drizzle(sqlite, { schema, }); +export const getLibraryStats = async () => { + const songCount = await db.select({ count: sql`count(*)` }).from(songs); + const albumCount = await db.select({ count: sql`count(*)` }).from(albums); + const playlistCount = await db + .select({ count: sql`count(*)` }) + .from(playlists); + + return { + songs: songCount[0].count, + albums: albumCount[0].count, + playlists: playlistCount[0].count, + }; +}; + export const getSettings = async () => { const throwSettings = await db.select().from(settings).limit(1); return throwSettings[0]; diff --git a/renderer/components/ui/actions.tsx b/renderer/components/ui/actions.tsx index 3888a43..482a82f 100644 --- a/renderer/components/ui/actions.tsx +++ b/renderer/components/ui/actions.tsx @@ -11,7 +11,7 @@ function Actions() { width={16} height={16} /> - Wora v0.1.0-alpha + Wora v0.1.0 diff --git a/renderer/pages/_app.tsx b/renderer/pages/_app.tsx index e817fa2..eb9db91 100644 --- a/renderer/pages/_app.tsx +++ b/renderer/pages/_app.tsx @@ -10,38 +10,34 @@ import { Toaster } from "@/components/ui/sonner"; export default function App({ Component, pageProps }) { const router = useRouter(); - if (["/setup"].includes(router.pathname)) { - return ( -
- -
- ); - } - return (
Wora - -
-
- - -
-
- -
-
-
- - + {["/setup"].includes(router.pathname) ? ( + + ) : ( + +
+
+ + +
+
+ +
+
+
+ + +
-
- + + )}
); } diff --git a/renderer/pages/settings.tsx b/renderer/pages/settings.tsx index 7c1b6bf..2777555 100644 --- a/renderer/pages/settings.tsx +++ b/renderer/pages/settings.tsx @@ -22,6 +22,7 @@ import { Button } from "@/components/ui/button"; import Spinner from "@/components/ui/spinner"; import { Avatar, AvatarImage } from "@/components/ui/avatar"; import { toast } from "sonner"; +import { Label } from "@/components/ui/label"; const formSchema = z.object({ name: z.string().min(2, { @@ -39,10 +40,25 @@ export default function Settings() { const [settings, setSettings] = useState(null); const [loading, setLoading] = useState(false); const [musicLoading, setMusicLoading] = useState(false); + const [previewUrl, setPreviewUrl] = useState(""); + const [stats, setStats] = useState<{ + songs: number; + albums: number; + playlists: number; + } | null>(null); useEffect(() => { window.ipc.invoke("getSettings").then((response) => { setSettings(response); + setPreviewUrl( + response?.profilePicture + ? `wora://${response.profilePicture}` + : "/userPicture.png", + ); + }); + + window.ipc.invoke("getLibraryStats").then((response) => { + setStats(response); }); }, []); @@ -129,6 +145,14 @@ export default function Settings() { .catch(() => setMusicLoading(false)); }; + useEffect(() => { + return () => { + if (previewUrl.startsWith("blob:")) { + URL.revokeObjectURL(previewUrl); + } + }; + }, [previewUrl]); + return (
@@ -139,66 +163,81 @@ export default function Settings() {
-
+
-
- - - -
-
-
- ( - +
+ + { + const fileInputRef = useRef(null); + return ( + - )} - /> - { - const fileInputRef = useRef(null); - return ( - - - { - const files = e.target.files; - if (files && files.length > 0) { - onChange(files); - } - }} - ref={fileInputRef} - {...rest} - /> - - - - ); - }} - /> + ); + }} + /> +
+

+ {settings && settings.name} +

+

A great listner of music.

+
+
+ ( + + + + + + + )} + />
-
-
-
- Logo +
+
+
+
+
+ Songs +

+ {stats && stats.songs} +

+
+
+ Albums +

+ {stats && stats.albums} +

+
+
+ Playlists +

+ {stats && stats.playlists} +

+
+
-
- Made with - - by hiaaryan. +
+
+ {settings && settings.musicFolder} +
+
-
- -
-
+
Logo @@ -253,6 +306,20 @@ export default function Settings() { by hiaaryan.
+ Logo + Logo
diff --git a/renderer/public/assets/Screenshot 1.png b/renderer/public/assets/Screenshot 1.png deleted file mode 100644 index 66333b8..0000000 Binary files a/renderer/public/assets/Screenshot 1.png and /dev/null differ