diff --git a/src/components/View/View.module.css b/src/components/View/View.module.css new file mode 100644 index 000000000..14986a38e --- /dev/null +++ b/src/components/View/View.module.css @@ -0,0 +1,27 @@ +.view { + height: 100%; + max-height: 100%; + background-color: var(--background); + flex: 1 1 auto; + overflow: auto; + position: relative; +} + +.centered { + display: flex; + justify-content: center; + scrollbar-gutter: stable; +} + +.hasPadding { + padding: 40px; +} + +.viewWithSideNav { + display: flex; + overflow: hidden; +} + +.viewContent { + flex: 1; +} diff --git a/src/components/View/View.tsx b/src/components/View/View.tsx new file mode 100644 index 000000000..5e303ff89 --- /dev/null +++ b/src/components/View/View.tsx @@ -0,0 +1,44 @@ +import cx from 'classnames'; + +import type SideNav from '../SideNav/SideNav'; + +import styles from './View.module.css'; + +type Props = { + children: React.ReactNode; + sideNav?: React.ReactElement; + layout?: 'centered'; + hasPadding?: boolean; + className?: string; +}; + +/** + * Default View to be used by all route components + */ +export default function View(props: Props) { + const viewClassNames = cx(styles.view, { + [styles.viewWithSideNav]: props.sideNav, + [styles.centered]: props.layout === 'centered', + }); + + const contentClassNames = cx(props.className, { + [styles.hasPadding]: props.hasPadding, + }); + + if (props.sideNav) { + return ( +
+ {props.sideNav} +
+ {props.children} +
+
+ ); + } + + return ( +
+ {props.children} +
+ ); +} diff --git a/src/views/Root.module.css b/src/views/Root.module.css index de8c2a3be..9692d5f51 100644 --- a/src/views/Root.module.css +++ b/src/views/Root.module.css @@ -12,23 +12,3 @@ flex-direction: column; min-height: 0; } - -.content { - position: absolute; - height: 100%; - width: 100%; - padding: 0; -} - -.view, -.columns { - height: 100%; - max-height: 100%; -} - -.view { - background-color: var(--background); - flex: 1 1 auto; - overflow: auto; - position: relative; -} diff --git a/src/views/ViewLibrary.module.css b/src/views/ViewLibrary.module.css deleted file mode 100644 index 387e4ed74..000000000 --- a/src/views/ViewLibrary.module.css +++ /dev/null @@ -1,5 +0,0 @@ -.viewLibrary { - overflow: hidden; - display: flex; - flex-direction: column; -} diff --git a/src/views/ViewLibrary.tsx b/src/views/ViewLibrary.tsx index 03fb322d1..fd2279df6 100644 --- a/src/views/ViewLibrary.tsx +++ b/src/views/ViewLibrary.tsx @@ -10,9 +10,8 @@ import config from '../lib/config'; import database from '../lib/database'; import useLibraryStore from '../stores/useLibraryStore'; +import View from '../components/View/View'; import type { LoaderData } from '../types/museeks'; -import appStyles from './Root.module.css'; -import styles from './ViewLibrary.module.css'; export default function ViewLibrary() { const trackPlayingID = usePlayingTrackID(); @@ -99,11 +98,7 @@ export default function ViewLibrary() { isLoading, ]); - return ( -
- {getLibraryComponent} -
- ); + return {getLibraryComponent}; } export type LibraryLoaderData = LoaderData; diff --git a/src/views/ViewPlaylists.module.css b/src/views/ViewPlaylists.module.css deleted file mode 100644 index 1ff774af4..000000000 --- a/src/views/ViewPlaylists.module.css +++ /dev/null @@ -1,9 +0,0 @@ -.viewPlaylists { - display: flex; - overflow: hidden; -} - -.playlist { - flex: 1; - display: flex; -} diff --git a/src/views/ViewPlaylists.tsx b/src/views/ViewPlaylists.tsx index 718c1ec00..a5db49d13 100644 --- a/src/views/ViewPlaylists.tsx +++ b/src/views/ViewPlaylists.tsx @@ -1,3 +1,7 @@ +import type { + MenuItemOptions, + PredefinedMenuItemOptions, +} from '@tauri-apps/api/menu'; import { useCallback, useMemo } from 'react'; import { type LoaderFunctionArgs, @@ -14,17 +18,11 @@ import * as ViewMessage from '../elements/ViewMessage/ViewMessage'; import database from '../lib/database'; import PlaylistsAPI from '../stores/PlaylistsAPI'; -import type { - MenuItemOptions, - PredefinedMenuItemOptions, -} from '@tauri-apps/api/menu'; import SideNavLink from '../components/SideNavLink/SideNavLink'; +import View from '../components/View/View'; import useInvalidate from '../hooks/useInvalidate'; import type { LoaderData } from '../types/museeks'; -import appStyles from './Root.module.css'; -import styles from './ViewPlaylists.module.css'; - export default function ViewPlaylists() { const { playlists } = useLoaderData() as PlaylistsLoaderData; const invalidate = useInvalidate(); @@ -121,21 +119,24 @@ export default function ViewPlaylists() { } return ( -
- - } - > - {sideNavItems} - -
{playlistContent}
-
+ + } + > + {sideNavItems} + + } + > + {playlistContent} + ); } diff --git a/src/views/ViewSettings.module.css b/src/views/ViewSettings.module.css index d42a6c714..03edca6ff 100644 --- a/src/views/ViewSettings.module.css +++ b/src/views/ViewSettings.module.css @@ -1,10 +1,3 @@ -.viewSettings { - display: flex; - justify-content: center; - padding-top: 50px; - scrollbar-gutter: stable; -} - .settings__nav { padding: 0 30px; width: 150px; diff --git a/src/views/ViewSettings.tsx b/src/views/ViewSettings.tsx index 9b99ce172..0ddb1e1bc 100644 --- a/src/views/ViewSettings.tsx +++ b/src/views/ViewSettings.tsx @@ -2,18 +2,18 @@ import { getTauriVersion, getVersion } from '@tauri-apps/api/app'; import { invoke } from '@tauri-apps/api/core'; import { Navigate, Outlet, useMatch } from 'react-router-dom'; +import View from '../components/View/View'; import * as SettingNav from '../elements/SettingsNav/SettingsNav'; import config from '../lib/config'; import type { LoaderData } from '../types/museeks'; -import appStyles from './Root.module.css'; import styles from './ViewSettings.module.css'; export default function ViewSettingsView() { const match = useMatch('/settings'); return ( -
+
Library @@ -28,7 +28,7 @@ export default function ViewSettingsView() {
{match && } -
+ ); } diff --git a/src/views/ViewTrackDetails.module.css b/src/views/ViewTrackDetails.module.css index 1c36685fb..a00d40ee3 100644 --- a/src/views/ViewTrackDetails.module.css +++ b/src/views/ViewTrackDetails.module.css @@ -1,11 +1,4 @@ -.viewDetails { - /* nothing */ -} - .detailsForm { - width: 400px; - padding: 10px 15px; - margin: auto; display: flex; flex-direction: column; } diff --git a/src/views/ViewTrackDetails.tsx b/src/views/ViewTrackDetails.tsx index 6cd79bac1..9a42b80cd 100644 --- a/src/views/ViewTrackDetails.tsx +++ b/src/views/ViewTrackDetails.tsx @@ -12,10 +12,10 @@ import type { Track } from '../generated/typings'; import database from '../lib/database'; import { useLibraryAPI } from '../stores/useLibraryStore'; +import View from '../components/View/View'; import Separator from '../elements/Separator/Separator'; import useInvalidate from '../hooks/useInvalidate'; import type { LoaderData } from '../types/museeks'; -import appStyles from './Root.module.css'; import styles from './ViewTrackDetails.module.css'; // We assume no artist or genre has a comma in its name (fingers crossed) @@ -56,7 +56,7 @@ export default function ViewTrackDetails() { ); return ( -
+

Edit "{formData.title}"

@@ -127,7 +127,7 @@ export default function ViewTrackDetails() { not save it to the original file.

-
+ ); }