Typing and Density settings

This commit is contained in:
Sean Edmunds
2025-04-21 17:27:26 -05:00
parent d9712974d9
commit c3495bd674
21 changed files with 531 additions and 343 deletions

View File

@@ -1,2 +1,7 @@
export { useQueryAPI, useWeatherAPI, useMutationAPI, useOSMAPI } from './useAPI'; export {
useQueryAPI,
useWeatherAPI,
useMutationAPI,
useOSMAPI,
} from './useAPI';
export { useCommonHooks } from './useCommonHooks'; export { useCommonHooks } from './useCommonHooks';

View File

@@ -2,7 +2,7 @@ import { useLocalStorage } from '@mantine/hooks';
import { appTheme } from 'contexts'; import { appTheme } from 'contexts';
import { useAtom } from 'jotai'; import { useAtom } from 'jotai';
import { useState } from 'react'; import { useState } from 'react';
import type { Theme } from 'types'; import type { Location, Theme, User } from 'types';
import { useMutationAPI } from './useAPI'; import { useMutationAPI } from './useAPI';
export function useCommonHooks() { export function useCommonHooks() {
@@ -21,6 +21,10 @@ export function useCommonHooks() {
key: 'appSort', key: 'appSort',
defaultValue: 'A>Z', defaultValue: 'A>Z',
}); });
const [appDensity, setAppDensity] = useLocalStorage<number>({
key: 'appDensity',
defaultValue: 6,
});
const [bookmarkSort, setBookmarkSort] = useLocalStorage<string>({ const [bookmarkSort, setBookmarkSort] = useLocalStorage<string>({
key: 'bookmarkSort', key: 'bookmarkSort',
defaultValue: 'A>Z', defaultValue: 'A>Z',
@@ -29,6 +33,10 @@ export function useCommonHooks() {
key: 'bookmarkFilter', key: 'bookmarkFilter',
defaultValue: ['All'], defaultValue: ['All'],
}); });
const [bookmarkDensity, setBookmarkDensity] = useLocalStorage<number>({
key: 'bookmarkDensity',
defaultValue: 5,
});
const [currentTheme, setCurrentTheme] = useLocalStorage<string>({ const [currentTheme, setCurrentTheme] = useLocalStorage<string>({
key: 'theme', key: 'theme',
defaultValue: 'blackboard', defaultValue: 'blackboard',
@@ -43,14 +51,16 @@ export function useCommonHooks() {
const [providerLabel, setProviderLabel] = useState('Google Search'); const [providerLabel, setProviderLabel] = useState('Google Search');
const [providerURL, setProviderURL] = useState('https://www.google.com/search?q='); const [providerURL, setProviderURL] = useState('https://www.google.com/search?q=');
const [providerPrefix, setProviderPrefix] = useState('/g'); const [providerPrefix, setProviderPrefix] = useState('/g');
const [currentUser, setCurrentUser] = useLocalStorage<any>({ const [currentUser, setCurrentUser] = useLocalStorage<User>({
key: 'user', key: 'user',
defaultValue: { defaultValue: {
firstName: 'First', firstName: 'First',
lastName: 'Last', lastName: 'Last',
email: 'triggerUser@default.com',
physicalAddress: '1510 Polk St, Houston, TX 77002',
}, },
}); });
const [currentLocation, setCurrentLocation] = useLocalStorage<any>({ const [currentLocation, setCurrentLocation] = useLocalStorage<Location>({
key: 'location', key: 'location',
defaultValue: { defaultValue: {
office: 'HGX', office: 'HGX',
@@ -133,10 +143,14 @@ export function useCommonHooks() {
setAppFilter, setAppFilter,
appSort, appSort,
setAppSort, setAppSort,
appDensity,
setAppDensity,
bookmarkSort, bookmarkSort,
setBookmarkSort, setBookmarkSort,
bookmarkFilter, bookmarkFilter,
setBookmarkFilter, setBookmarkFilter,
bookmarkDensity,
setBookmarkDensity,
currentTheme, currentTheme,
setCurrentTheme, setCurrentTheme,
currentThemePlaylist, currentThemePlaylist,

View File

@@ -9,7 +9,7 @@ function Applications({ contentType }: { contentType: [string] }) {
const { data: apps, isFetching: isAppsFetching } = useQueryAPI({ const { data: apps, isFetching: isAppsFetching } = useQueryAPI({
endpoint: 'api/apps', endpoint: 'api/apps',
}); });
const { isMobile, appSort } = useCommonHooks(); const { isMobile, appSort, appDensity } = useCommonHooks();
const [applicationData, setApplicationData] = useState<Application[]>([]); const [applicationData, setApplicationData] = useState<Application[]>([]);
useEffect(() => { useEffect(() => {
@@ -49,7 +49,9 @@ function Applications({ contentType }: { contentType: [string] }) {
display: 'grid', display: 'grid',
gridColumnGap: '5px', gridColumnGap: '5px',
gridRowGap: '5px', gridRowGap: '5px',
gridTemplateColumns: isMobile ? '1fr 1fr 1fr' : '1fr 1fr 1fr 1fr 1fr 1fr', gridTemplateColumns: isMobile
? '1fr 1fr 1fr'
: `repeat(${appDensity}, 1fr)`,
gridTemplateRows: '64px', gridTemplateRows: '64px',
}} }}
> >

View File

@@ -12,7 +12,7 @@ function Links({ contentType }: { contentType: [string] }) {
const { data: groupData, isFetched: groupsIsFetched } = useQueryAPI({ const { data: groupData, isFetched: groupsIsFetched } = useQueryAPI({
endpoint: 'api/categories', endpoint: 'api/categories',
}); });
const { isMobile, bookmarkSort } = useCommonHooks(); const { isMobile, bookmarkSort, bookmarkDensity } = useCommonHooks();
const [bookmarkData, setBookmarkData] = useState<Bookmark[]>([]); const [bookmarkData, setBookmarkData] = useState<Bookmark[]>([]);
const [groups, setGroups] = useState<BookmarkGroup[]>([]); const [groups, setGroups] = useState<BookmarkGroup[]>([]);
@@ -62,7 +62,9 @@ function Links({ contentType }: { contentType: [string] }) {
flexWrap: 'nowrap', flexWrap: 'nowrap',
gridColumnGap: '20px', gridColumnGap: '20px',
gridRowGap: '0px', gridRowGap: '0px',
gridTemplateColumns: isMobile ? '1fr 1fr' : '1fr 1fr 1fr 1fr 1fr', gridTemplateColumns: isMobile
? '1fr 1fr'
: `repeat(${bookmarkDensity}, 1fr)`,
gridTemplateRows: 'auto', gridTemplateRows: 'auto',
}} }}
> >

View File

@@ -12,7 +12,13 @@ import { useCommonHooks, useMutationAPI, useQueryAPI } from 'hooks';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { FiEdit, FiTrash } from 'react-icons/fi'; import { FiEdit, FiTrash } from 'react-icons/fi';
import { actionIconClasses, selectClasses } from 'styles'; import { actionIconClasses, selectClasses } from 'styles';
import type { Application, CurrentWeather, ExtendedForecast, Provider } from 'types'; import type {
Application,
CurrentWeather,
ExtendedForecast,
Provider,
SearchHistoryItem,
} from 'types';
export default function Search({ export default function Search({
current, current,
@@ -38,8 +44,8 @@ export default function Search({
const { data: history, isFetched: historyIsFetched } = useQueryAPI({ const { data: history, isFetched: historyIsFetched } = useQueryAPI({
endpoint: 'api/searchHistory', endpoint: 'api/searchHistory',
}); });
const [searchHistory, setSearchHistory] = useState<any>([]); const [searchHistory, setSearchHistory] = useState<SearchHistoryItem[]>([]);
const [filteredHistory, setFilteredHistory] = useState<any>([]); const [filteredHistory, setFilteredHistory] = useState<SearchHistoryItem[]>([]);
const { mutateAsync } = useMutationAPI(); const { mutateAsync } = useMutationAPI();
const [providerModalOpened, { open: openProviderModal, close: closeProviderModal }] = const [providerModalOpened, { open: openProviderModal, close: closeProviderModal }] =
useDisclosure(false); useDisclosure(false);
@@ -169,7 +175,7 @@ export default function Search({
? `${searchHistory[listIndex].prefix} ${searchHistory[listIndex].searchTerm}` ? `${searchHistory[listIndex].prefix} ${searchHistory[listIndex].searchTerm}`
: '', : '',
); );
setValue(searchHistory.length > 0 ? searchHistory[listIndex].id : 0); setValue(searchHistory[listIndex].id ?? 0);
} }
} else if (searchValue !== '') { } else if (searchValue !== '') {
if (item.code === 'ArrowUp') { if (item.code === 'ArrowUp') {
@@ -193,7 +199,7 @@ export default function Search({
setSearchValue( setSearchValue(
`${filteredHistory[listIndex].prefix} ${filteredHistory[listIndex].searchTerm}`, `${filteredHistory[listIndex].prefix} ${filteredHistory[listIndex].searchTerm}`,
); );
setValue(filteredHistory[listIndex].id); setValue(filteredHistory[listIndex].id ?? 0);
} }
} }
} }

View File

@@ -6,13 +6,15 @@ import {
MultiSelect, MultiSelect,
Overlay, Overlay,
Select, Select,
Slider,
Stack, Stack,
Text, Text,
Tooltip, Tooltip,
} from '@mantine/core'; } from '@mantine/core';
import { useQueryClient } from '@tanstack/react-query';
import { useCommonHooks, useMutationAPI, useQueryAPI } from 'hooks'; import { useCommonHooks, useMutationAPI, useQueryAPI } from 'hooks';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { FaDice } from 'react-icons/fa'; import { FaDice, FaSync } from 'react-icons/fa';
import { FiMenu, FiPower, FiSettings, FiShuffle } from 'react-icons/fi'; import { FiMenu, FiPower, FiSettings, FiShuffle } from 'react-icons/fi';
import { useNavigate } from 'react-router-dom'; import { useNavigate } from 'react-router-dom';
import { toast } from 'react-toastify'; import { toast } from 'react-toastify';
@@ -22,6 +24,7 @@ import {
menuClasses, menuClasses,
multiSelectClasses, multiSelectClasses,
selectClasses, selectClasses,
sliderClasses,
stackClasses, stackClasses,
} from 'styles'; } from 'styles';
import type { AppCategory, Theme, ThemePlaylist, WolClient } from 'types'; import type { AppCategory, Theme, ThemePlaylist, WolClient } from 'types';
@@ -55,10 +58,14 @@ function SettingsButton() {
setAppFilter, setAppFilter,
appSort, appSort,
setAppSort, setAppSort,
appDensity,
setAppDensity,
bookmarkSort, bookmarkSort,
setBookmarkSort, setBookmarkSort,
bookmarkFilter, bookmarkFilter,
setBookmarkFilter, setBookmarkFilter,
bookmarkDensity,
setBookmarkDensity,
isMobile, isMobile,
currentThemePlaylist, currentThemePlaylist,
setCurrentThemePlaylist, setCurrentThemePlaylist,
@@ -71,6 +78,23 @@ function SettingsButton() {
}); });
}; };
const marks = [
{ value: 1, label: '1' },
{ value: 2, label: '2' },
{ value: 3, label: '3' },
{ value: 4, label: '4' },
{ value: 5, label: '5' },
{ value: 6, label: '6' },
{ value: 7, label: '7' },
{ value: 8, label: '8' },
];
const queryClient = useQueryClient();
const handleRefresh = () => {
queryClient.refetchQueries();
};
useEffect(() => { useEffect(() => {
if (data) { if (data) {
const list: [any] = data.map((category: AppCategory) => { const list: [any] = data.map((category: AppCategory) => {
@@ -97,7 +121,7 @@ function SettingsButton() {
{overlayOpened && <Overlay pos={'fixed'} />} {overlayOpened && <Overlay pos={'fixed'} />}
<Menu <Menu
classNames={menuClasses} classNames={menuClasses}
width={isMobile ? '98%' : '500px'} width={isMobile ? '98%' : 'auto'}
withinPortal={false} withinPortal={false}
withArrow withArrow
shadow='md' shadow='md'
@@ -119,25 +143,14 @@ function SettingsButton() {
: theme.backgroundColor, : theme.backgroundColor,
}} }}
> >
<Stack gap={0} display={'flex'} pb={'1rem'} pt={'2rem'} align='center'> <Group p={'1rem'} gap={24}>
<Tooltip label='Settings' color={theme.primaryColor} withArrow> <Stack display={'flex'} align='center'>
<FiSettings
size={20}
onClick={() => navigate(`/${import.meta.env.VITE_BASE_URL}/settings`)}
style={{
cursor: 'pointer',
position: 'absolute',
top: '.5rem',
right: '.5rem',
}}
/>
</Tooltip>
<Group w={'100%'} justify='center'>
<Stack <Stack
gap={0} gap={0}
align='center' align='center'
className={stackClasses.menuStack} className={stackClasses.menuStack}
classNames={stackClasses} classNames={stackClasses}
style={{ aspectRatio: '1/1' }}
> >
<Menu.Label>Wake on LAN</Menu.Label> <Menu.Label>Wake on LAN</Menu.Label>
<Button <Button
@@ -186,6 +199,7 @@ function SettingsButton() {
align='center' align='center'
className={stackClasses.menuStack} className={stackClasses.menuStack}
classNames={stackClasses} classNames={stackClasses}
style={{ aspectRatio: '1/1' }}
> >
<Menu.Label pb={'.25rem'}>Themes</Menu.Label> <Menu.Label pb={'.25rem'}>Themes</Menu.Label>
<Group mt={'-1rem'} mb={'-.75rem'} w={'95%'} justify='space-between'> <Group mt={'-1rem'} mb={'-.75rem'} w={'95%'} justify='space-between'>
@@ -281,118 +295,188 @@ function SettingsButton() {
onLoad={(option: any) => setCurrentThemePlaylist(option)} onLoad={(option: any) => setCurrentThemePlaylist(option)}
/> />
</Stack> </Stack>
</Group>
<Menu.Divider
w={'85%'}
m={'.75rem'}
style={{ borderColor: theme.accentColor }}
/>
<Stack
gap={0}
align='center'
w={'85%'}
h={'100px'}
className={stackClasses.menuStack}
classNames={stackClasses}
>
<Menu.Label>Filters</Menu.Label>
<Group justify='space-between' px={'.5rem'}>
<MultiSelect
label='Apps'
data={
categories.toSorted((a: any, b: any) =>
a.label.localeCompare(b.label),
) ?? []
}
placeholder={
appFilter.length > 0
? appFilter.length === 1
? appFilter[0]
: `${appFilter.length} apps selected`
: 'No apps selected'
}
defaultValue={appFilter}
onChange={(data: any) => {
setAppFilter(data);
}}
classNames={multiSelectClasses}
comboboxProps={{ withinPortal: false }}
/>
<MultiSelect
label='Bookmarks'
data={
categories.toSorted((a: any, b: any) =>
a.label.localeCompare(b.label),
) ?? []
}
placeholder={
bookmarkFilter.length > 0
? bookmarkFilter.length === 1
? bookmarkFilter[0]
: `${bookmarkFilter.length} bookmarks selected`
: 'No bookmarks selected'
}
defaultValue={bookmarkFilter}
onChange={(data: any) => {
setBookmarkFilter(data);
}}
classNames={multiSelectClasses}
comboboxProps={{ withinPortal: false }}
/>
</Group>
</Stack> </Stack>
<Menu.Divider <Stack display={'flex'} align='center'>
w={'85%'} <Stack
m={'.75rem'} gap={0}
style={{ borderColor: theme.accentColor }} align='center'
/> className={stackClasses.menuStack}
<Stack classNames={stackClasses}
gap={0} pos={'relative'}
align='center' >
w={'85%'} <Text
h={'100px'} style={{
className={stackClasses.menuStack} fontSize: 12,
classNames={stackClasses} paddingLeft: 8,
> paddingRight: 8,
<Menu.Label>Sorting</Menu.Label> paddingTop: 2,
<Group justify='space-between' px={'.5rem'}> paddingBottom: 2,
<Select borderRadius: 8,
label={'Apps'} position: 'absolute',
placeholder='Sort Applications...' left: '-20px',
value={appSort} top: '-8px',
data={['Custom', 'A>Z', 'Z>A', 'Newest', 'Oldest']} backgroundColor: theme.primaryColor,
w={'45%'} color: theme.backgroundColor,
classNames={{
input: selectClasses.menuSelectInput,
label: selectClasses.menuSelectLabel,
options: selectClasses.menuSelectOptions,
option: selectClasses.menuSelectOption,
}} }}
comboboxProps={{ withinPortal: false }} >
onChange={(_value, option: any) => { Apps
setAppSort(option.value); </Text>
<Stack m={0} p={0} gap={0} w={'90%'}>
<Text fz={14} mt={16}>
Density
</Text>
<Slider
className={sliderClasses.default}
classNames={sliderClasses}
restrictToMarks
value={appDensity}
onChange={(value) => setAppDensity(value)}
min={1}
max={8}
marks={marks}
/>
</Stack>
<Group justify='space-between' px={'.5rem'}>
<MultiSelect
label='Filter'
data={
categories.toSorted((a: any, b: any) =>
a.label.localeCompare(b.label),
) ?? []
}
placeholder={
appFilter.length > 0
? appFilter.length === 1
? appFilter[0]
: `${appFilter.length} apps selected`
: 'No apps selected'
}
defaultValue={appFilter}
onChange={(data: any) => {
setAppFilter(data);
}}
classNames={multiSelectClasses}
comboboxProps={{ withinPortal: false }}
/>
<Select
label={'Sorting'}
placeholder='Sort Applications...'
value={appSort}
data={['Custom', 'A>Z', 'Z>A', 'Newest', 'Oldest']}
w={'45%'}
classNames={{
input: selectClasses.menuSelectInput,
label: selectClasses.menuSelectLabel,
options: selectClasses.menuSelectOptions,
option: selectClasses.menuSelectOption,
}}
comboboxProps={{ withinPortal: false }}
onChange={(_value, option: any) => {
setAppSort(option.value);
}}
/>
</Group>
</Stack>
<Stack
gap={0}
align='center'
className={stackClasses.menuStack}
classNames={stackClasses}
pos={'relative'}
>
<Text
style={{
fontSize: 12,
paddingLeft: 8,
paddingRight: 8,
paddingTop: 2,
paddingBottom: 2,
borderRadius: 8,
position: 'absolute',
left: '-20px',
top: '-8px',
backgroundColor: theme.primaryColor,
color: theme.backgroundColor,
}} }}
/> >
<Select Bookmarks
label={'Bookmarks'} </Text>
placeholder='Sort Bookmarks...' <Stack m={0} p={0} gap={0} w={'90%'}>
value={bookmarkSort} <Text fz={14} mt={16}>
data={['Custom', 'A>Z', 'Z>A', 'Newest', 'Oldest']} Density
w={'45%'} </Text>
classNames={{ <Slider
input: selectClasses.menuSelectInput, className={sliderClasses.default}
label: selectClasses.menuSelectLabel, classNames={sliderClasses}
options: selectClasses.menuSelectOptions, restrictToMarks
option: selectClasses.menuSelectOption, value={bookmarkDensity}
}} onChange={(value) => setBookmarkDensity(value)}
comboboxProps={{ withinPortal: false }} min={1}
onChange={(_value, option: any) => { max={8}
setBookmarkSort(option.value); marks={marks}
}} />
/> </Stack>
</Group> <Group justify='space-between' px={'.5rem'}>
<MultiSelect
label='Filter'
data={
categories.toSorted((a: any, b: any) =>
a.label.localeCompare(b.label),
) ?? []
}
placeholder={
bookmarkFilter.length > 0
? bookmarkFilter.length === 1
? bookmarkFilter[0]
: `${bookmarkFilter.length} bookmarks selected`
: 'No bookmarks selected'
}
defaultValue={bookmarkFilter}
onChange={(data: any) => {
setBookmarkFilter(data);
}}
classNames={multiSelectClasses}
comboboxProps={{ withinPortal: false }}
/>
<Select
label={'Sorting'}
placeholder='Sort Bookmarks...'
value={bookmarkSort}
data={['Custom', 'A>Z', 'Z>A', 'Newest', 'Oldest']}
w={'45%'}
classNames={{
input: selectClasses.menuSelectInput,
label: selectClasses.menuSelectLabel,
options: selectClasses.menuSelectOptions,
option: selectClasses.menuSelectOption,
}}
comboboxProps={{ withinPortal: false }}
onChange={(_value, option: any) => {
setBookmarkSort(option.value);
}}
/>
</Group>
</Stack>
</Stack> </Stack>
</Stack> </Group>
<Group w={'100%'} align='center' justify='center'>
<Button
leftSection={<FiSettings />}
onClick={() => navigate(`/${import.meta.env.VITE_BASE_URL}/settings`)}
className={buttonClasses.settingsMenuButton}
classNames={buttonClasses}
>
Settings
</Button>
<Button
leftSection={<FaSync />}
onClick={handleRefresh}
className={buttonClasses.settingsMenuButton}
classNames={buttonClasses}
>
Refresh
</Button>
</Group>
</Menu.Dropdown> </Menu.Dropdown>
</Menu> </Menu>
</> </>

View File

@@ -263,7 +263,7 @@ const ApplicationSettings = () => {
'filter', 'filter',
], ],
description: description:
'Applications contain a name, base url, url, icon and filter. Currently the icon must be the mdi icon name. URLs can contain either http(s):// or not. Base URLs should start with /, otherwise they will cause errors.', 'Applications contain a name, base url, url, icon and filter. URLs can contain either http(s):// or not. Base URLs should start with /, otherwise they will cause errors.',
}} }}
searchValue={searchValue} searchValue={searchValue}
setSearchValue={setSearchValue} setSearchValue={setSearchValue}

View File

@@ -33,9 +33,9 @@ function SettingsHeader({
openModal: () => void; openModal: () => void;
title: string; title: string;
tooltip: any; tooltip: any;
searchValue: string; searchValue: string | undefined;
setSearchValue: (searchValue: string) => void; setSearchValue: (searchValue: string) => void;
searchPlaceholder: string; searchPlaceholder: string | undefined;
}) { }) {
const { isMobile, theme, modalStyle } = useCommonHooks(); const { isMobile, theme, modalStyle } = useCommonHooks();
return ( return (
@@ -123,7 +123,7 @@ function SettingsHeader({
className={textInputClasses.settingsItem} className={textInputClasses.settingsItem}
classNames={textInputClasses} classNames={textInputClasses}
autoFocus={!isMobile} autoFocus={!isMobile}
placeholder={searchPlaceholder || 'Search...'} placeholder={searchPlaceholder ?? 'Search...'}
value={searchValue} value={searchValue}
onInput={(event: any) => { onInput={(event: any) => {
setSearchValue(event.target.value); setSearchValue(event.target.value);

View File

@@ -221,7 +221,7 @@ function ThemePlaylistCard({
)} )}
<Button <Button
w={'275px'} w={'275px'}
h={'310px'} h={'320px'}
style={{ style={{
backgroundSize: 'cover', backgroundSize: 'cover',
backgroundColor: theme.searchColor, backgroundColor: theme.searchColor,
@@ -234,7 +234,7 @@ function ThemePlaylistCard({
}} }}
> >
{hover && <Overlay opacity={0.5} zIndex={1} />} {hover && <Overlay opacity={0.5} zIndex={1} />}
<Stack h={'100%'} w={'100%'} align='center'> <Stack h={'100%'} w={'100%'} align='center' mt={12}>
{cardPlaylist.name !== 'Time of Day' ? ( {cardPlaylist.name !== 'Time of Day' ? (
<> <>
<Text <Text

View File

@@ -3,17 +3,16 @@ import {
Divider, Divider,
Group, Group,
Modal, Modal,
Select,
SimpleGrid, SimpleGrid,
Stack,
Text, Text,
TextInput, TextInput,
} from '@mantine/core'; } from '@mantine/core';
import { useCommonHooks } from 'hooks'; import { useCommonHooks } from 'hooks';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { modalClasses, selectClasses, textInputClasses } from 'styles'; import { modalClasses, textInputClasses } from 'styles';
import type { Theme } from 'types'; import type { Theme } from 'types';
import ThemeMiniCard from './ThemeMiniCard'; import ThemeMiniCard from './ThemeMiniCard';
import TimeOfDay from './TimeOfDay';
function ThemePlaylistModal({ function ThemePlaylistModal({
opened, opened,
@@ -35,12 +34,12 @@ function ThemePlaylistModal({
const { theme, isMobile, modalStyle } = useCommonHooks(); const { theme, isMobile, modalStyle } = useCommonHooks();
const [themeList, setThemeList] = useState<any>('[]'); const [themeList, setThemeList] = useState<any>('[]');
useEffect(() => { useEffect(() => {
if (selectedPlaylist.themeList) { if (selectedPlaylist?.themeList) {
setThemeList(JSON.parse(selectedPlaylist?.themeList)); setThemeList(JSON.parse(selectedPlaylist?.themeList));
} }
}, [selectedPlaylist]); }, [selectedPlaylist]);
if (selectedPlaylist.name === undefined) { if (selectedPlaylist?.name === undefined) {
setSelectedPlaylist({ setSelectedPlaylist({
name: 'New Playlist', name: 'New Playlist',
themeList: '[]', themeList: '[]',
@@ -69,8 +68,8 @@ function ThemePlaylistModal({
<TextInput <TextInput
className={textInputClasses.default} className={textInputClasses.default}
classNames={textInputClasses} classNames={textInputClasses}
value={selectedPlaylist.name} value={selectedPlaylist?.name}
disabled={selectedPlaylist.name === 'Time of Day'} disabled={selectedPlaylist?.name === 'Time of Day'}
onChange={(e) => onChange={(e) =>
setSelectedPlaylist({ ...selectedPlaylist, name: e.target.value }) setSelectedPlaylist({ ...selectedPlaylist, name: e.target.value })
} }
@@ -89,194 +88,71 @@ function ThemePlaylistModal({
<Modal.CloseButton /> <Modal.CloseButton />
</Modal.Header> </Modal.Header>
<Modal.Body pt={8}> <Modal.Body pt={8}>
{selectedPlaylist.name === 'Time of Day' ? ( {selectedPlaylist?.name === 'Time of Day' ? (
<Stack> <TimeOfDay
<Group> createPlaylist={createPlaylist}
<Text w={'100px'}>00:00-05:59</Text> themeList={themeList}
<Select allThemes={allThemes}
labelProps={{ display: 'none' }} selectedPlaylist={selectedPlaylist}
placeholder='Select Theme' />
defaultValue={themeList['0']}
data={allThemes?.map((theme: Theme) => {
return {
value: `${theme.id}`,
label: theme.name,
};
})}
classNames={{
input: selectClasses.menuSelectInput,
label: selectClasses.menuSelectLabel,
options: selectClasses.menuSelectOptions,
option: selectClasses.menuSelectOption,
}}
onChange={(data) => {
const newThemeList = themeList;
newThemeList['0'] = data;
createPlaylist({
method: 'PATCH',
endpoint: 'api/themePlaylists',
body: {
id: selectedPlaylist.id,
name: selectedPlaylist.name,
themeList: JSON.stringify(newThemeList),
},
});
}}
/>
</Group>
<Group w={'100%'}>
<Text w={'100px'}>06:00-11:59</Text>
<Select
labelProps={{ display: 'none' }}
placeholder='Select Theme'
defaultValue={themeList['1']}
data={allThemes?.map((theme: Theme) => {
return {
value: `${theme.id}`,
label: theme.name,
};
})}
classNames={{
input: selectClasses.menuSelectInput,
label: selectClasses.menuSelectLabel,
options: selectClasses.menuSelectOptions,
option: selectClasses.menuSelectOption,
}}
onChange={(data) => {
const newThemeList = themeList;
newThemeList['1'] = data;
createPlaylist({
method: 'PATCH',
endpoint: 'api/themePlaylists',
body: {
id: selectedPlaylist.id,
name: selectedPlaylist.name,
themeList: JSON.stringify(newThemeList),
},
});
}}
/>
</Group>
<Group w={'100%'}>
<Text w={'100px'}>12:00-17:59</Text>
<Select
labelProps={{ display: 'none' }}
placeholder='Select Theme'
defaultValue={themeList['2']}
data={allThemes?.map((theme: Theme) => {
return {
value: `${theme.id}`,
label: theme.name,
};
})}
classNames={{
input: selectClasses.menuSelectInput,
label: selectClasses.menuSelectLabel,
options: selectClasses.menuSelectOptions,
option: selectClasses.menuSelectOption,
}}
onChange={(data) => {
const newThemeList = themeList;
newThemeList['2'] = data;
createPlaylist({
method: 'PATCH',
endpoint: 'api/themePlaylists',
body: {
id: selectedPlaylist.id,
name: selectedPlaylist.name,
themeList: JSON.stringify(newThemeList),
},
});
}}
/>
</Group>
<Group w={'100%'}>
<Text w={'100px'}>18:00-23:59</Text>
<Select
labelProps={{ display: 'none' }}
placeholder='Select Theme'
defaultValue={themeList['3']}
data={allThemes?.map((theme: Theme) => {
return {
value: `${theme.id}`,
label: theme.name,
};
})}
classNames={{
input: selectClasses.menuSelectInput,
label: selectClasses.menuSelectLabel,
options: selectClasses.menuSelectOptions,
option: selectClasses.menuSelectOption,
}}
onChange={(data) => {
const newThemeList = themeList;
newThemeList['3'] = data;
createPlaylist({
method: 'PATCH',
endpoint: 'api/themePlaylists',
body: {
id: selectedPlaylist.id,
name: selectedPlaylist.name,
themeList: JSON.stringify(newThemeList),
},
});
}}
/>
</Group>
</Stack>
) : ( ) : (
<SimpleGrid cols={3}> <>
{selectedPlaylist.name !== 'Time of Day' && <SimpleGrid cols={3}>
allThemes?.map((miniTheme: Theme) => { {selectedPlaylist?.name !== 'Time of Day' &&
const newThemeList = themeList; allThemes?.map((miniTheme: Theme) => {
return ( const newThemeList = themeList;
<Group return (
key={miniTheme.id} <Group
style={{ key={miniTheme.id}
cursor: 'pointer', style={{
filter: cursor: 'pointer',
newThemeList && !newThemeList?.includes(miniTheme.id) filter:
? 'saturate(0)' newThemeList && !newThemeList?.includes(miniTheme.id)
: undefined, ? 'saturate(0)'
}} : undefined,
onClick={() => { }}
const newSelectedPlaylist = { ...selectedPlaylist }; onClick={() => {
if (themeList?.includes(miniTheme.id)) { const newSelectedPlaylist = { ...selectedPlaylist };
newThemeList.splice(themeList.indexOf(miniTheme.id), 1); if (themeList?.includes(miniTheme.id)) {
} else { newThemeList.splice(themeList.indexOf(miniTheme.id), 1);
newThemeList.push(miniTheme.id); } else {
} newThemeList.push(miniTheme.id);
newSelectedPlaylist.themeList = JSON.stringify(newThemeList); }
setSelectedPlaylist(newSelectedPlaylist); newSelectedPlaylist.themeList = JSON.stringify(newThemeList);
}} setSelectedPlaylist(newSelectedPlaylist);
> }}
<ThemeMiniCard allThemes={allThemes} item={Number(miniTheme.id)} /> >
</Group> <ThemeMiniCard
); allThemes={allThemes}
})} item={Number(miniTheme.id)}
</SimpleGrid> />
</Group>
);
})}
</SimpleGrid>
<Divider color='black' my='sm' />
<Group>
<Button
color={'green'}
styles={{ label: { color: 'black' } }}
onClick={handleSavePlaylist}
>
Save
</Button>
<Button
color={'red'}
styles={{ label: { color: 'black' } }}
onClick={() => {
handleClose();
setThemeList('[]');
setSelectedPlaylist({});
}}
>
Cancel
</Button>
</Group>
</>
)} )}
<Divider color='black' my='sm' />
<Group>
<Button
color={'green'}
styles={{ label: { color: 'black' } }}
onClick={handleSavePlaylist}
>
Save
</Button>
<Button
color={'red'}
styles={{ label: { color: 'black' } }}
onClick={() => {
handleClose();
setThemeList('[]');
setSelectedPlaylist({});
}}
>
Cancel
</Button>
</Group>
</Modal.Body> </Modal.Body>
</Modal.Content> </Modal.Content>
</Modal.Root> </Modal.Root>

View File

@@ -20,7 +20,7 @@ function ThemePlaylists() {
}); });
const { mutateAsync } = useMutationAPI(); const { mutateAsync } = useMutationAPI();
const [opened, { open, close }] = useDisclosure(false); const [opened, { open, close }] = useDisclosure(false);
const [selectedPlaylist, setSelectedPlaylist] = useState<any>({}); const [selectedPlaylist, setSelectedPlaylist] = useState<ThemePlaylist | undefined>();
const { currentThemePlaylist, theme, isMobile } = useCommonHooks(); const { currentThemePlaylist, theme, isMobile } = useCommonHooks();
const [searchValue, setSearchValue] = useState(''); const [searchValue, setSearchValue] = useState('');
const [debouncedSearch] = useDebouncedValue(searchValue, 500); const [debouncedSearch] = useDebouncedValue(searchValue, 500);
@@ -31,15 +31,15 @@ function ThemePlaylists() {
}; };
const handleClose = () => { const handleClose = () => {
setSelectedPlaylist({}); setSelectedPlaylist(undefined);
close(); close();
}; };
const handleSavePlaylist = () => { const handleSavePlaylist = () => {
mutateAsync({ mutateAsync({
method: selectedPlaylist.id === undefined ? 'POST' : 'PATCH', method: selectedPlaylist?.id === undefined ? 'POST' : 'PATCH',
endpoint: themePlaylistsEndpoint, endpoint: themePlaylistsEndpoint,
body: selectedPlaylist, body: selectedPlaylist ?? {},
}); });
close(); close();
}; };

View File

@@ -0,0 +1,99 @@
import { Group, Select, Text } from '@mantine/core';
import type { Theme } from 'types';
function ThemeSelect({
allThemes,
createPlaylist,
themeList,
selectedPlaylist,
index,
timeIndex,
}: {
allThemes: Theme[];
createPlaylist: any;
themeList: any;
selectedPlaylist: any;
index: string;
timeIndex: string;
}) {
const theme = allThemes.find((theme: Theme) => `${theme.id}` === themeList[index]);
return (
<Group>
<Text w={'100px'}>{timeIndex}</Text>
<Select
labelProps={{ display: 'none' }}
comboboxProps={{ withinPortal: false }}
placeholder='Select Theme'
defaultValue={themeList[index]}
data={allThemes?.map((theme: Theme) => {
return {
value: `${theme.id}`,
label: theme.name,
};
})}
onChange={(data) => {
const newThemeList = themeList;
newThemeList[index] = data;
createPlaylist({
method: 'PATCH',
endpoint: 'api/themePlaylists',
body: {
id: selectedPlaylist?.id,
name: selectedPlaylist?.name,
themeList: JSON.stringify(newThemeList),
},
});
}}
styles={{
option: {
padding: 4,
},
input: {
textAlign: 'center',
height: '60px',
color: theme?.primaryColor,
background: `linear-gradient(${theme?.backgroundColor}33, ${theme?.backgroundColor}33), no-repeat center url(/backgrounds/${theme?.backgroundImage})`,
backgroundSize: 'cover',
backgroundColor: theme?.backgroundColor,
border: `solid ${theme?.borderColor}`,
borderRadius: '8px',
},
}}
renderOption={({ option }: any) => {
const theme = allThemes?.find((theme: Theme) => `${theme.id}` === option.value);
return (
<Group
gap={0}
align='center'
justify='center'
w={'100%'}
h={'60px'}
style={{
background: `linear-gradient(${theme?.backgroundColor}33, ${theme?.backgroundColor}33), no-repeat center url(/backgrounds/${theme?.backgroundImage})`,
backgroundSize: 'cover',
backgroundColor: theme?.backgroundColor,
border: `solid ${theme?.borderColor}`,
borderRadius: '8px',
}}
>
<Text
bg={theme?.backgroundColor}
c={theme?.primaryColor}
size='md'
style={{
padding: 4,
borderRadius: '8px',
}}
>
{allThemes.find((theme: Theme) => `${theme.id}` === option.value)?.name}
</Text>
</Group>
);
}}
/>
</Group>
);
}
export default ThemeSelect;

View File

@@ -0,0 +1,49 @@
import { Stack } from '@mantine/core';
import type { Theme } from 'types';
import ThemeSelect from './ThemeSelect';
function TimeOfDay({
createPlaylist,
themeList,
allThemes,
selectedPlaylist,
}: { createPlaylist: any; themeList: any; allThemes: Theme[]; selectedPlaylist: any }) {
return (
<Stack>
<ThemeSelect
allThemes={allThemes}
createPlaylist={createPlaylist}
themeList={themeList}
selectedPlaylist={selectedPlaylist}
index='0'
timeIndex='00:00 - 05:59'
/>
<ThemeSelect
allThemes={allThemes}
createPlaylist={createPlaylist}
themeList={themeList}
selectedPlaylist={selectedPlaylist}
index='1'
timeIndex='06:00 - 11:59'
/>
<ThemeSelect
allThemes={allThemes}
createPlaylist={createPlaylist}
themeList={themeList}
selectedPlaylist={selectedPlaylist}
index='2'
timeIndex='12:00 - 17:59'
/>
<ThemeSelect
allThemes={allThemes}
createPlaylist={createPlaylist}
themeList={themeList}
selectedPlaylist={selectedPlaylist}
index='3'
timeIndex='18:00 - 23:59'
/>
</Stack>
);
}
export default TimeOfDay;

View File

@@ -27,8 +27,8 @@ function DebouncedWolClient({
const [modalOpened, { open: openModal, close: closeModal }] = useDisclosure(false); const [modalOpened, { open: openModal, close: closeModal }] = useDisclosure(false);
const { mutateAsync } = useMutationAPI(); const { mutateAsync } = useMutationAPI();
const [client, setClient] = useState<any>(wolClient); const [client, setClient] = useState<WolClient>(wolClient);
const [update, setUpdate] = useState({}); const [update, setUpdate] = useState<any>({});
const [debounced] = useDebouncedValue(update, 1000); const [debounced] = useDebouncedValue(update, 1000);
const handleClose = () => { const handleClose = () => {
setIsOpen(false); setIsOpen(false);

View File

@@ -59,3 +59,18 @@
color: var(--color-background) !important; color: var(--color-background) !important;
} }
} }
.settingsMenuButton {
&.root {
padding: 10px;
margin: 0px;
color: var(--color-background);
background-color: var(--color-text-pri);
border-radius: 20px;
cursor: pointer;
}
&:hover {
background-color: var(--color-text-acc) !important;
color: var(--color-background) !important;
}
}

View File

@@ -0,0 +1,19 @@
.default {
.trackContainer {
.track::before {
background-color: var(--color-border);
}
.bar {
background-color: var(--color-text-pri);
}
.mark {
border-color: var(--color-text-acc);
}
.thumb {
border-color: var(--color-text-acc);
}
.markLabel {
display: none;
}
}
}

View File

@@ -48,7 +48,6 @@
} }
.menuStack { .menuStack {
width: 40%;
height: 150px; height: 150px;
background-color: var(--color-search-background); background-color: var(--color-search-background);
border-radius: 10px; border-radius: 10px;

View File

@@ -7,6 +7,7 @@ import modalClasses from './Modal.module.css';
import multiSelectClasses from './MultiSelect.module.css'; import multiSelectClasses from './MultiSelect.module.css';
import popoverClasses from './Popover.module.css'; import popoverClasses from './Popover.module.css';
import selectClasses from './Select.module.css'; import selectClasses from './Select.module.css';
import sliderClasses from './Slider.module.css';
import stackClasses from './Stack.module.css'; import stackClasses from './Stack.module.css';
import switchClasses from './Switch.module.css'; import switchClasses from './Switch.module.css';
import tabClasses from './Tabs.module.css'; import tabClasses from './Tabs.module.css';
@@ -24,6 +25,7 @@ export {
multiSelectClasses, multiSelectClasses,
popoverClasses, popoverClasses,
selectClasses, selectClasses,
sliderClasses,
stackClasses, stackClasses,
switchClasses, switchClasses,
tabClasses, tabClasses,

View File

@@ -8,3 +8,5 @@ export type { Provider } from './provider';
export type { Theme, ThemePlaylist } from './theme'; export type { Theme, ThemePlaylist } from './theme';
export type { WolClient } from './wolClient'; export type { WolClient } from './wolClient';
export type { SearchHistoryItem } from './searchHistory'; export type { SearchHistoryItem } from './searchHistory';
export type { User } from './user';
export type { Location } from './location';

8
src/types/location.ts Normal file
View File

@@ -0,0 +1,8 @@
export interface Location {
office: string;
station: string;
x: number;
y: number;
lat: number;
lon: number;
}

6
src/types/user.ts Normal file
View File

@@ -0,0 +1,6 @@
export interface User {
firstName: string;
lastName: string;
email: string;
physicalAddress: string;
}