feishin/src/renderer/layouts/default-layout.tsx

76 lines
2 KiB
TypeScript
Raw Normal View History

2023-03-28 23:59:51 -07:00
import { lazy } from 'react';
2022-12-19 15:59:14 -08:00
import isElectron from 'is-electron';
import styled from 'styled-components';
2023-05-18 02:15:03 -07:00
import {
useWindowSettings,
useSettingsStore,
useHotkeySettings,
} from '/@/renderer/store/settings.store';
2023-03-28 23:59:51 -07:00
import { Platform, PlaybackType } from '/@/renderer/types';
import { MainContent } from '/@/renderer/layouts/default-layout/main-content';
import { PlayerBar } from '/@/renderer/layouts/default-layout/player-bar';
2023-05-18 02:15:03 -07:00
import { useHotkeys } from '@mantine/hooks';
import { CommandPalette } from '/@/renderer/features/search/components/command-palette';
import { useCommandPalette } from '/@/renderer/store';
2022-12-19 15:59:14 -08:00
if (!isElectron()) {
useSettingsStore.getState().actions.setSettings({
2023-03-30 06:44:33 -07:00
playback: {
...useSettingsStore.getState().playback,
2022-12-19 15:59:14 -08:00
type: PlaybackType.WEB,
},
});
}
2023-03-28 23:59:51 -07:00
const Layout = styled.div<{ windowBarStyle: Platform }>`
2022-12-19 15:59:14 -08:00
display: grid;
grid-template-areas:
2023-03-28 23:59:51 -07:00
'window-bar'
'main-content'
2022-12-19 15:59:14 -08:00
'player';
2023-03-30 04:57:51 -07:00
grid-template-rows: ${(props) =>
props.windowBarStyle === Platform.WINDOWS || props.windowBarStyle === Platform.MACOS
2023-03-30 04:57:51 -07:00
? '30px calc(100vh - 120px) 90px'
: '0px calc(100vh - 90px) 90px'};
2022-12-19 15:59:14 -08:00
grid-template-columns: 1fr;
gap: 0;
height: 100%;
2023-06-03 17:36:12 -07:00
overflow: hidden;
2022-12-19 15:59:14 -08:00
`;
2023-03-28 23:59:51 -07:00
const WindowBar = lazy(() =>
import('/@/renderer/layouts/window-bar').then((module) => ({
default: module.WindowBar,
})),
);
2022-12-19 15:59:14 -08:00
interface DefaultLayoutProps {
shell?: boolean;
}
export const DefaultLayout = ({ shell }: DefaultLayoutProps) => {
2023-03-30 06:44:33 -07:00
const { windowBarStyle } = useWindowSettings();
2023-05-18 02:15:03 -07:00
const { opened, ...handlers } = useCommandPalette();
const { bindings } = useHotkeySettings();
useHotkeys([[bindings.globalSearch.hotkey, () => handlers.open()]]);
2022-12-19 15:59:14 -08:00
return (
2023-03-28 23:59:51 -07:00
<>
<Layout
id="default-layout"
windowBarStyle={windowBarStyle}
>
2023-03-28 23:59:51 -07:00
{windowBarStyle !== Platform.WEB && <WindowBar />}
<MainContent shell={shell} />
<PlayerBar />
</Layout>
2023-05-18 02:15:03 -07:00
<CommandPalette modalProps={{ handlers, opened }} />
2023-03-28 23:59:51 -07:00
</>
2022-12-19 15:59:14 -08:00
);
};
DefaultLayout.defaultProps = {
shell: false,
};