Skip to content

Commit 68923b3

Browse files
committed
Refactor view wrappers into a <View> component
1 parent 2749df0 commit 68923b3

11 files changed

Lines changed: 102 additions & 83 deletions
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.view {
2+
height: 100%;
3+
max-height: 100%;
4+
background-color: var(--background);
5+
flex: 1 1 auto;
6+
overflow: auto;
7+
position: relative;
8+
}
9+
10+
.centered {
11+
display: flex;
12+
justify-content: center;
13+
scrollbar-gutter: stable;
14+
}
15+
16+
.hasPadding {
17+
padding: 40px;
18+
}
19+
20+
.viewWithSideNav {
21+
display: flex;
22+
overflow: hidden;
23+
}
24+
25+
.viewContent {
26+
flex: 1;
27+
}

src/components/View/View.tsx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import cx from 'classnames';
2+
3+
import type SideNav from '../SideNav/SideNav';
4+
5+
import styles from './View.module.css';
6+
7+
type Props = {
8+
children: React.ReactNode;
9+
sideNav?: React.ReactElement<typeof SideNav>;
10+
layout?: 'centered';
11+
hasPadding?: boolean;
12+
className?: string;
13+
};
14+
15+
/**
16+
* Default View to be used by all route components
17+
*/
18+
export default function View(props: Props) {
19+
const viewClassNames = cx(styles.view, {
20+
[styles.viewWithSideNav]: props.sideNav,
21+
[styles.centered]: props.layout === 'centered',
22+
});
23+
24+
const contentClassNames = cx(props.className, {
25+
[styles.hasPadding]: props.hasPadding,
26+
});
27+
28+
if (props.sideNav) {
29+
return (
30+
<div className={viewClassNames}>
31+
{props.sideNav}
32+
<div className={`${contentClassNames} ${styles.viewContent}`}>
33+
{props.children}
34+
</div>
35+
</div>
36+
);
37+
}
38+
39+
return (
40+
<div className={cx(viewClassNames, contentClassNames)}>
41+
{props.children}
42+
</div>
43+
);
44+
}

src/views/Root.module.css

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,3 @@
1212
flex-direction: column;
1313
min-height: 0;
1414
}
15-
16-
.content {
17-
position: absolute;
18-
height: 100%;
19-
width: 100%;
20-
padding: 0;
21-
}
22-
23-
.view,
24-
.columns {
25-
height: 100%;
26-
max-height: 100%;
27-
}
28-
29-
.view {
30-
background-color: var(--background);
31-
flex: 1 1 auto;
32-
overflow: auto;
33-
position: relative;
34-
}

src/views/ViewLibrary.module.css

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/views/ViewLibrary.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ import config from '../lib/config';
1010
import database from '../lib/database';
1111
import useLibraryStore from '../stores/useLibraryStore';
1212

13+
import View from '../components/View/View';
1314
import type { LoaderData } from '../types/museeks';
14-
import appStyles from './Root.module.css';
15-
import styles from './ViewLibrary.module.css';
1615

1716
export default function ViewLibrary() {
1817
const trackPlayingID = usePlayingTrackID();
@@ -99,11 +98,7 @@ export default function ViewLibrary() {
9998
isLoading,
10099
]);
101100

102-
return (
103-
<div className={`${appStyles.view} ${styles.viewLibrary}`}>
104-
{getLibraryComponent}
105-
</div>
106-
);
101+
return <View>{getLibraryComponent}</View>;
107102
}
108103

109104
export type LibraryLoaderData = LoaderData<typeof ViewLibrary.loader>;

src/views/ViewPlaylists.module.css

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/views/ViewPlaylists.tsx

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import type {
2+
MenuItemOptions,
3+
PredefinedMenuItemOptions,
4+
} from '@tauri-apps/api/menu';
15
import { useCallback, useMemo } from 'react';
26
import {
37
type LoaderFunctionArgs,
@@ -14,17 +18,11 @@ import * as ViewMessage from '../elements/ViewMessage/ViewMessage';
1418
import database from '../lib/database';
1519
import PlaylistsAPI from '../stores/PlaylistsAPI';
1620

17-
import type {
18-
MenuItemOptions,
19-
PredefinedMenuItemOptions,
20-
} from '@tauri-apps/api/menu';
2121
import SideNavLink from '../components/SideNavLink/SideNavLink';
22+
import View from '../components/View/View';
2223
import useInvalidate from '../hooks/useInvalidate';
2324
import type { LoaderData } from '../types/museeks';
2425

25-
import appStyles from './Root.module.css';
26-
import styles from './ViewPlaylists.module.css';
27-
2826
export default function ViewPlaylists() {
2927
const { playlists } = useLoaderData() as PlaylistsLoaderData;
3028
const invalidate = useInvalidate();
@@ -121,21 +119,24 @@ export default function ViewPlaylists() {
121119
}
122120

123121
return (
124-
<div className={`${appStyles.view} ${styles.viewPlaylists}`}>
125-
<SideNav
126-
title="Playlists"
127-
actions={
128-
<ButtonIcon
129-
icon="plus"
130-
onClick={createPlaylist}
131-
title="New Playlist"
132-
/>
133-
}
134-
>
135-
{sideNavItems}
136-
</SideNav>
137-
<div className={styles.playlist}>{playlistContent}</div>
138-
</div>
122+
<View
123+
sideNav={
124+
<SideNav
125+
title="Playlists"
126+
actions={
127+
<ButtonIcon
128+
icon="plus"
129+
onClick={createPlaylist}
130+
title="New Playlist"
131+
/>
132+
}
133+
>
134+
{sideNavItems}
135+
</SideNav>
136+
}
137+
>
138+
{playlistContent}
139+
</View>
139140
);
140141
}
141142

src/views/ViewSettings.module.css

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
.viewSettings {
2-
display: flex;
3-
justify-content: center;
4-
padding-top: 50px;
5-
scrollbar-gutter: stable;
6-
}
7-
81
.settings__nav {
92
padding: 0 30px;
103
width: 150px;

src/views/ViewSettings.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ import { getTauriVersion, getVersion } from '@tauri-apps/api/app';
22
import { invoke } from '@tauri-apps/api/core';
33
import { Navigate, Outlet, useMatch } from 'react-router-dom';
44

5+
import View from '../components/View/View';
56
import * as SettingNav from '../elements/SettingsNav/SettingsNav';
67
import config from '../lib/config';
78
import type { LoaderData } from '../types/museeks';
89

9-
import appStyles from './Root.module.css';
1010
import styles from './ViewSettings.module.css';
1111

1212
export default function ViewSettingsView() {
1313
const match = useMatch('/settings');
1414

1515
return (
16-
<div className={`${appStyles.view} ${styles.viewSettings}`}>
16+
<View hasPadding layout="centered">
1717
<div className={styles.settings__nav}>
1818
<SettingNav.Wrap vertical>
1919
<SettingNav.Link to="/settings/library">Library</SettingNav.Link>
@@ -28,7 +28,7 @@ export default function ViewSettingsView() {
2828
</div>
2929

3030
{match && <Navigate to="/settings/library" />}
31-
</div>
31+
</View>
3232
);
3333
}
3434

src/views/ViewTrackDetails.module.css

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
.viewDetails {
2-
/* nothing */
3-
}
4-
51
.detailsForm {
6-
width: 400px;
7-
padding: 10px 15px;
8-
margin: auto;
92
display: flex;
103
flex-direction: column;
114
}

0 commit comments

Comments
 (0)