Skip to content

Commit

Permalink
Merge pull request #151 from tsirysndr/refactor/webui
Browse files Browse the repository at this point in the history
chore(webui): refactor all components
  • Loading branch information
tsirysndr authored Mar 10, 2023
2 parents 14bb896 + b51cbda commit 8c5bfc3
Show file tree
Hide file tree
Showing 64 changed files with 622 additions and 1,350 deletions.
Binary file added webui/chromecast/bun.lockb
Binary file not shown.
17 changes: 10 additions & 7 deletions webui/musicplayer/.storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Client as Styletron } from "styletron-engine-atomic";
import { Provider as StyletronProvider } from "styletron-react";
import { MemoryRouter, Routes, Route } from "react-router-dom";
import { PLACEMENT, SnackbarProvider } from "baseui/snackbar";
import { MockedProvider } from "@apollo/client/testing";
import Providers from "../src/Providers";
import "../src/index.css";

Expand Down Expand Up @@ -33,12 +34,14 @@ const reactRouterDecorator = (Story) => {
export const decorators = [
reactRouterDecorator,
(Story) => (
<StyletronProvider value={engine}>
<Providers>
<SnackbarProvider placement={PLACEMENT.bottom}>
<Story />
</SnackbarProvider>
</Providers>
</StyletronProvider>
<MockedProvider mocks={[]} addTypename={false}>
<StyletronProvider value={engine}>
<Providers>
<SnackbarProvider placement={PLACEMENT.bottom}>
<Story />
</SnackbarProvider>
</Providers>
</StyletronProvider>
</MockedProvider>
),
];
6 changes: 3 additions & 3 deletions webui/musicplayer/build/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"files": {
"main.css": "/static/css/main.6215da36.css",
"main.js": "/static/js/main.610fbbe1.js",
"main.js": "/static/js/main.20e29918.js",
"static/js/787.26bf0a29.chunk.js": "/static/js/787.26bf0a29.chunk.js",
"static/media/RockfordSans-ExtraBold.otf": "/static/media/RockfordSans-ExtraBold.1513e8fd97078bfb7708.otf",
"static/media/RockfordSans-Bold.otf": "/static/media/RockfordSans-Bold.c9f599ae01b13e565598.otf",
Expand All @@ -10,11 +10,11 @@
"static/media/RockfordSans-Light.otf": "/static/media/RockfordSans-Light.b4a12e8abb38f7d105c4.otf",
"index.html": "/index.html",
"main.6215da36.css.map": "/static/css/main.6215da36.css.map",
"main.610fbbe1.js.map": "/static/js/main.610fbbe1.js.map",
"main.20e29918.js.map": "/static/js/main.20e29918.js.map",
"787.26bf0a29.chunk.js.map": "/static/js/787.26bf0a29.chunk.js.map"
},
"entrypoints": [
"static/css/main.6215da36.css",
"static/js/main.610fbbe1.js"
"static/js/main.20e29918.js"
]
}
2 changes: 1 addition & 1 deletion webui/musicplayer/build/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>Music Player</title><script defer="defer" src="/static/js/main.610fbbe1.js"></script><link href="/static/css/main.6215da36.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>Music Player</title><script defer="defer" src="/static/js/main.20e29918.js"></script><link href="/static/css/main.6215da36.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions webui/musicplayer/build/static/js/main.20e29918.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object-assign
*/

/**
* @remix-run/router v1.0.2
* @remix-run/router v1.4.0
*
* Copyright (c) Remix Software Inc.
*
Expand All @@ -27,7 +27,7 @@ object-assign
*/

/**
* React Router DOM v6.4.2
* React Router DOM v6.9.0
*
* Copyright (c) Remix Software Inc.
*
Expand All @@ -38,7 +38,7 @@ object-assign
*/

/**
* React Router v6.4.2
* React Router v6.9.0
*
* Copyright (c) Remix Software Inc.
*
Expand Down
1 change: 1 addition & 0 deletions webui/musicplayer/build/static/js/main.20e29918.js.map

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions webui/musicplayer/build/static/js/main.610fbbe1.js

This file was deleted.

1 change: 0 additions & 1 deletion webui/musicplayer/build/static/js/main.610fbbe1.js.map

This file was deleted.

Binary file added webui/musicplayer/bun.lockb
Binary file not shown.
22 changes: 11 additions & 11 deletions webui/musicplayer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"tauri:dev": "cross-env BROWSER=none REACT_APP_NATIVE_WRAPPER=tauri react-scripts start",
"test": "react-scripts test",
"eject": "react-scripts eject",
"storybook": "start-storybook -p 6006 -s public",
"storybook": "start-storybook -p 6007 -s public",
"build-storybook": "build-storybook -s public",
"graphql:generate": "graphql-codegen --config codegen.yml"
},
Expand Down Expand Up @@ -87,22 +87,22 @@
"@graphql-codegen/typescript": "2.7.5",
"@graphql-codegen/typescript-operations": "2.5.5",
"@graphql-codegen/typescript-react-apollo": "3.3.5",
"@storybook/addon-actions": "^6.5.12",
"@storybook/addon-essentials": "^6.5.12",
"@storybook/addon-interactions": "^6.5.12",
"@storybook/addon-links": "^6.5.12",
"@storybook/builder-webpack5": "^6.5.12",
"@storybook/manager-webpack5": "^6.5.12",
"@storybook/node-logger": "^6.5.12",
"@storybook/addon-actions": "^6.5.16",
"@storybook/addon-essentials": "^6.5.16",
"@storybook/addon-interactions": "^6.5.16",
"@storybook/addon-links": "^6.5.16",
"@storybook/builder-webpack5": "^6.5.16",
"@storybook/manager-webpack5": "^6.5.16",
"@storybook/node-logger": "^6.5.16",
"@storybook/preset-create-react-app": "^4.1.2",
"@storybook/react": "^6.5.12",
"@storybook/react": "^6.5.16",
"@storybook/testing-library": "^0.0.13",
"@types/react-custom-scrollbars": "^4.0.10",
"babel-plugin-named-exports-order": "^0.0.2",
"cross-env": "^7.0.3",
"msw": "^0.47.4",
"msw-storybook-addon": "^1.6.3",
"prop-types": "^15.8.1",
"webpack": "^5.74.0"
"webpack": "^5.75.0"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { linkTo } from "@storybook/addon-links";
import { ComponentMeta, ComponentStory } from "@storybook/react";
import _ from "lodash";
import AlbumDetails from "../Components/AlbumDetails";
import AlbumDetails from "./AlbumDetails";

export default {
title: "Components/AlbumDetails",
Expand Down Expand Up @@ -193,18 +192,5 @@ Default.args = {
],
},
onBack: linkTo("Components/Albums", "Default"),
onClickLibraryItem(item) {
linkTo(
`Components/${item
.split("-")
.map((x) => _.capitalize(x))
.join("")}`,
"Default"
)();
},
nowPlaying: {},
devices: [],
currentDevice: undefined,
connectToDevice: (_id) => {},
disconnectFromDevice: () => {},
};
37 changes: 2 additions & 35 deletions webui/musicplayer/src/Components/AlbumDetails/AlbumDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import Sidebar from "../Sidebar";
import TracksTable from "../TracksTable";
import AlbumIcon from "../Icons/AlbumCover";
import _ from "lodash";
import { Track } from "../../Types";
import { resourceUriResolver } from "../../ResourceUriResolver";
import { Device } from "../../Types/Device";
import { useTheme } from "@emotion/react";
Expand Down Expand Up @@ -131,47 +130,15 @@ const Tracks = styled.div`
`;

export type AlbumDetailsProps = {
onClickAlbum: (album: any) => void;
onBack: () => void;
onClickLibraryItem: (item: string) => void;
album: any;
onPlay: () => void;
onPause: () => void;
onNext: () => void;
onPrevious: () => void;
onShuffle: () => void;
onRepeat: () => void;
nowPlaying: any;
nextTracks: Track[];
previousTracks: Track[];
onPlayAlbum: (id: string, shuffle: boolean, position?: number) => void;
onPlayNext: (id: string) => void;
onPlayTrackAt: (position: number) => void;
onRemoveTrackAt: (position: number) => void;
onSearch: (query: string) => void;
folders: any[];
playlists: any[];
onCreateFolder: (name: string) => void;
onCreatePlaylist: (name: string, description?: string) => void;
onDeleteFolder: (id: string) => void;
onDeletePlaylist: (id: string) => void;
onEditFolder: (id: string, name: string) => void;
onEditPlaylist: (id: string, name: string, description?: string) => void;
recentPlaylists: any[];
onAddTrackToPlaylist: (playlistId: string, trackId: string) => void;
onPlayPlaylist: (
playlistId: string,
shuffle: boolean,
position?: number
) => void;
devices: Device[];
castDevices: Device[];
currentDevice?: Device;
currentCastDevice?: Device;
connectToDevice: (deviceId: string) => void;
disconnectFromDevice: () => void;
connectToCastDevice: (deviceId: string) => void;
disconnectFromCastDevice: () => void;
};

const AlbumDetails: FC<AlbumDetailsProps> = (props) => {
Expand All @@ -195,9 +162,9 @@ const AlbumDetails: FC<AlbumDetailsProps> = (props) => {
<>
{currentCastDevice && <ListeningOn deviceName={currentCastDevice.name} />}
<Container>
<Sidebar active="albums" {...props} />
<Sidebar active="albums" />
<Content>
<ControlBar {...props} />
<ControlBar />
<MainContent displayHeader={false}>
<Scrollable>
<BackButton onClick={onBack}>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { FC, useEffect } from "react";
import AlbumDetails from "./AlbumDetails";
import { useGetAlbumQuery } from "../../Hooks/GraphQL";
import { useTimeFormat } from "../../Hooks/useFormat";
import { usePlayback } from "../../Hooks/usePlayback";
import { usePlaylist } from "../../Hooks/usePlaylist";
import { useNavigate, useParams } from "react-router-dom";

const AlbumDetailsWithData: FC = () => {
const params = useParams();
const { data, loading, refetch } = useGetAlbumQuery({
variables: {
id: params.id!,
},
fetchPolicy: "network-only",
});

useEffect(() => {
params.id && refetch();
}, [params.id, refetch]);

const navigate = useNavigate();
const { formatTime } = useTimeFormat();
const { nowPlaying, playAlbum, playNext } = usePlayback();
const album =
!loading && data
? {
...data.album,
tracks: data.album.tracks.map((track, index) => ({
"#": track.trackNumber,
id: track.id,
title: track.title,
artist: track.artists.map((artist) => artist.name).join(", "),
time: formatTime(track.duration! * 1000),
artistId: track.artists[0].id,
albumId: data.album.id,
index,
})),
}
: { tracks: [] };
const { recentPlaylists, createPlaylist, addTrackToPlaylist } = usePlaylist();
return (
<AlbumDetails
onBack={() => navigate(-1)}
album={album}
nowPlaying={nowPlaying}
onPlayAlbum={(albumId, shuffle, position) =>
playAlbum({ variables: { albumId, position, shuffle } })
}
onPlayNext={(trackId) => playNext({ variables: { trackId } })}
onCreatePlaylist={(name) => createPlaylist({ variables: { name } })}
onAddTrackToPlaylist={(playlistId, trackId) =>
addTrackToPlaylist({ variables: { playlistId, trackId } })
}
recentPlaylists={recentPlaylists}
/>
);
};

export default AlbumDetailsWithData;
4 changes: 2 additions & 2 deletions webui/musicplayer/src/Components/AlbumDetails/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import AlbumDetails from "./AlbumDetails";
import AlbumDetailsWithData from "./AlbumDetailsWithData";

export default AlbumDetails;
export default AlbumDetailsWithData;
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ComponentMeta, ComponentStory } from "@storybook/react";
import { linkTo } from "@storybook/addon-links";
import Albums from "../Components/Albums/Albums";
import _ from "lodash";
import Albums from "./Albums";

export default {
title: "Components/Albums",
Expand Down Expand Up @@ -86,17 +85,5 @@ Default.args = {
onClickAlbum(album) {
linkTo("Components/AlbumDetails", "Default")();
},
onClickLibraryItem(item) {
linkTo(
`Components/${item
.split("-")
.map((x) => _.capitalize(x))
.join("")}`,
"Default"
)();
},
devices: [],
currentDevice: undefined,
connectToDevice: (_id) => {},
disconnectFromDevice: () => {},
currentCastDevice: undefined,
};
40 changes: 3 additions & 37 deletions webui/musicplayer/src/Components/Albums/Albums.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import ControlBar from "../ControlBar";
import MainContent from "../MainContent";
import Sidebar from "../Sidebar";
import AlbumIcon from "../Icons/AlbumCover";
import { Track } from "../../Types";
import { Device } from "../../Types/Device";
import ListeningOn from "../ListeningOn";

Expand Down Expand Up @@ -72,46 +71,13 @@ const Scrollable = styled.div`
export type AlbumsProps = {
albums: any[];
onClickAlbum: (album: any) => void;
onClickLibraryItem: (item: string) => void;
onPlay: () => void;
onPause: () => void;
onNext: () => void;
onPrevious: () => void;
onShuffle: () => void;
onRepeat: () => void;
nowPlaying: any;
nextTracks: Track[];
previousTracks: Track[];
onPlayNext: (id: string) => void;
onPlayTrackAt: (position: number) => void;
onRemoveTrackAt: (position: number) => void;
onSearch: (query: string) => void;
folders: any[];
playlists: any[];
onCreateFolder: (name: string) => void;
onCreatePlaylist: (name: string, description?: string) => void;
onDeleteFolder: (id: string) => void;
onDeletePlaylist: (id: string) => void;
onEditFolder: (id: string, name: string) => void;
onEditPlaylist: (id: string, name: string, description?: string) => void;
onPlayPlaylist: (
playlistId: string,
shuffle: boolean,
position?: number
) => void;
devices: Device[];
castDevices: Device[];
currentDevice?: Device;
currentCastDevice?: Device;
connectToDevice: (deviceId: string) => void;
disconnectFromDevice: () => void;
connectToCastDevice: (deviceId: string) => void;
disconnectFromCastDevice: () => void;
};

export type AlbumProps = {
onClick: (item: any) => void;
album: any;
currentCastDevice?: Device;
};

const Album: FC<AlbumProps> = ({ onClick, album }) => {
Expand All @@ -136,9 +102,9 @@ const Albums: FC<AlbumsProps> = (props) => {
<>
{currentCastDevice && <ListeningOn deviceName={currentCastDevice.name} />}
<Container>
<Sidebar active="albums" {...props} />
<Sidebar active="albums" />
<Content>
<ControlBar {...props} />
<ControlBar />
<Scrollable>
<MainContent title="Albums" placeholder="Filter Albums">
<Wrapper>
Expand Down
Loading

0 comments on commit 8c5bfc3

Please sign in to comment.