Skip to content

Commit

Permalink
some refactoring 👾
Browse files Browse the repository at this point in the history
  • Loading branch information
hiaaryan committed Jul 3, 2024
1 parent 2fdcdaf commit 8087380
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 138 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
4 changes: 3 additions & 1 deletion main/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ if (isProd) {
}

let settings: any;
let mainWindow: any;

// @hiaaryan: Initialize Database on Startup
(async () => {
Expand All @@ -57,7 +58,7 @@ let settings: any;
callback({ path: request.url.replace("wora://", "") });
});

const mainWindow = createWindow("main", {
mainWindow = createWindow("main", {
width: 1500,
height: 900,
titleBarStyle: "hidden",
Expand Down Expand Up @@ -240,6 +241,7 @@ ipcMain.handle("getSettings", async () => {

ipcMain.handle("updateSettings", async (_, data: any) => {
const settings = await updateSettings(data);
mainWindow.webContents.send("confirmSettingsUpdate", settings);
return settings;
});

Expand Down
5 changes: 3 additions & 2 deletions main/helpers/db/connectDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,11 @@ export const getRandomLibraryItems = async () => {
.select()
.from(albums)
.orderBy(sql`RANDOM()`)
.limit(20);
.limit(10);

const randomSongs = await db.query.songs.findMany({
with: { album: true },
limit: 20,
limit: 10,
orderBy: sql`RANDOM()`,
});

Expand Down Expand Up @@ -429,6 +429,7 @@ export const initializeData = async (musicFolder: string) => {
.select()
.from(playlists)
.where(eq(playlists.id, 1));

if (!defaultPlaylist[0]) {
await db.insert(playlists).values({
name: "Favourites",
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"postinstall": "electron-builder install-app-deps"
},
"dependencies": {
"@hookform/resolvers": "^3.6.0",
"@hookform/resolvers": "^3.7.0",
"@radix-ui/react-avatar": "^1.1.0",
"@radix-ui/react-context-menu": "^2.2.1",
"@radix-ui/react-dialog": "^1.1.1",
Expand All @@ -28,10 +28,10 @@
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-tabs": "^1.1.0",
"@radix-ui/react-tooltip": "^1.1.2",
"@tabler/icons-react": "^3.7.0",
"@types/better-sqlite3": "^7.6.10",
"@tabler/icons-react": "^3.8.0",
"@types/better-sqlite3": "^7.6.11",
"axios": "^1.7.2",
"better-sqlite3": "^11.1.1",
"better-sqlite3": "^11.1.2",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"cmdk": "^1.0.0",
Expand All @@ -45,7 +45,7 @@
"howler": "^2.2.4",
"music-metadata": "^7.14.0",
"next-themes": "^0.3.0",
"react-hook-form": "^7.52.0",
"react-hook-form": "^7.52.1",
"sonner": "^1.5.0",
"tailwind-gradient-mask-image": "^1.2.0",
"tailwind-merge": "^2.3.0",
Expand All @@ -70,7 +70,7 @@
"react-dom": "^18.3.1",
"rebuild": "^0.1.2",
"tailwindcss": "^3.4.4",
"typescript": "^5.5.2"
"typescript": "^5.5.3"
},
"packageManager": "[email protected]"
}
6 changes: 6 additions & 0 deletions renderer/components/ui/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ const Navbar = () => {
window.ipc.invoke("getSettings").then((response) => {
setSettings(response);
});

window.ipc.on("confirmSettingsUpdate", () => {
window.ipc.invoke("getSettings").then((response) => {
setSettings(response);
});
});
}, []);

return (
Expand Down
157 changes: 68 additions & 89 deletions renderer/pages/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export default function Home() {
}}
>
<CarouselPrevious className="absolute left-0 z-50 my-0" />
<div className="w-full gradient-mask-r-70-d">
<div className="w-full gradient-mask-r-80-d">
<CarouselContent className="-ml-8">
{libraryItems.albums &&
libraryItems.albums.map((album: any, index: number) => (
Expand Down Expand Up @@ -124,94 +124,73 @@ export default function Home() {
</div>
<CarouselNext className="absolute right-0 z-50 my-0" />
</Carousel>
<div className="flex flex-col">
<div className="text-base font-medium">Your Tracks</div>
<div className="opacity-50">How about some randomness?</div>
</div>
<div className="grid w-full grid-cols-5 gap-8 pb-[32vh]">
<Carousel
className="relative w-[88vw]"
opts={{
loop: true,
}}
>
<CarouselPrevious className="absolute left-0 z-50 my-0" />
<div className="w-full gradient-mask-r-70-d">
<CarouselContent className="-ml-8">
{libraryItems.songs &&
libraryItems.songs.map((song: any, index: number) => (
<CarouselItem key={index} className="basis-1/5 pl-8">
<ContextMenu key={song.id}>
<ContextMenuTrigger>
<div
className="group/song wora-border wora-transition h-[21rem] cursor-pointer rounded-xl p-5 hover:bg-white/10"
onClick={() => handleMusicClick(index)}
>
<div className="relative flex h-full flex-col justify-between">
<div className="relative h-2/3 w-full overflow-hidden rounded-lg shadow-xl">
<Image
alt={
song.album
? song.album.name
: "Album Cover"
}
src={song.album.coverArt}
fill
loading="lazy"
className="z-10 object-cover"
/>
</div>
<div className="flex w-full flex-col">
<p className="text-nowrap text-sm font-medium gradient-mask-r-70">
{song.name}
</p>
<p className="text-nowrap opacity-50 gradient-mask-r-70">
{song.artist}
</p>
</div>
</div>
</div>
</ContextMenuTrigger>
<ContextMenuContent className="w-64">
<ContextMenuItem
className="flex items-center gap-2"
onClick={() => handleMusicClick(index)}
>
<IconPlayerPlay
className="fill-white"
stroke={2}
size={14}
/>
Play Song
</ContextMenuItem>
<ContextMenuSub>
<ContextMenuSubTrigger className="flex items-center gap-2">
<IconPlus stroke={2} size={14} />
Add to Playlist
</ContextMenuSubTrigger>
<ContextMenuSubContent className="w-52">
{playlists.map((playlist) => (
<ContextMenuItem
key={playlist.id}
onClick={() =>
addSongToPlaylist(playlist.id, song.id)
}
>
<p className="w-full text-nowrap gradient-mask-r-70">
{playlist.name}
</p>
</ContextMenuItem>
))}
</ContextMenuSubContent>
</ContextMenuSub>
</ContextMenuContent>
</ContextMenu>
</CarouselItem>
))}
</CarouselContent>
</div>
<CarouselNext className="absolute right-0 z-50 my-0" />
</Carousel>
<div className="pb-[32vh]">
{libraryItems.songs &&
libraryItems.songs.map((song: any, index: number) => (
<ContextMenu key={song.id}>
<ContextMenuTrigger>
<div
className="wora-transition flex w-full cursor-pointer items-center justify-between rounded-xl px-4 py-3 hover:bg-white/10"
onClick={() => handleMusicClick(index)}
>
<div className="flex items-center gap-4">
<div className="relative h-12 w-12 overflow-hidden rounded shadow-xl transition duration-300">
<Image
alt={song.album && song.album.name}
src={song.album && song.album.coverArt}
fill
loading="lazy"
className="object-cover"
/>
</div>
<div className="flex flex-col">
<p className="text-sm font-medium">{song.name}</p>
<p className="opacity-50">{song.artist}</p>
</div>
</div>
<div>
<p className="flex items-center gap-1 opacity-50">
<IconClock stroke={2} size={15} />
{convertTime(song.duration)}
</p>
</div>
</div>
</ContextMenuTrigger>
<ContextMenuContent className="w-64">
<ContextMenuItem
className="flex items-center gap-2"
onClick={() => handleMusicClick(index)}
>
<IconPlayerPlay
className="fill-white"
stroke={2}
size={14}
/>
Play Song
</ContextMenuItem>
<ContextMenuSub>
<ContextMenuSubTrigger className="flex items-center gap-2">
<IconPlus stroke={2} size={14} />
Add to Playlist
</ContextMenuSubTrigger>
<ContextMenuSubContent className="w-52">
{playlists.map((playlist) => (
<ContextMenuItem
key={playlist.id}
onClick={() =>
addSongToPlaylist(playlist.id, song.id)
}
>
<p className="w-full text-nowrap gradient-mask-r-70">
{playlist.name}
</p>
</ContextMenuItem>
))}
</ContextMenuSubContent>
</ContextMenuSub>
</ContextMenuContent>
</ContextMenu>
))}
</div>
</div>
</div>
Expand Down
1 change: 0 additions & 1 deletion renderer/pages/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ export default function Settings() {
});

useEffect(() => {
console.log("settings", settings);
if (settings) {
form.reset({
name: settings.name,
Expand Down
Loading

0 comments on commit 8087380

Please sign in to comment.