-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
904 additions
and
642 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './settings.form'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Container, Dropdown } from '@nextui-org/react'; | ||
import React from 'react'; | ||
import { Controller, useForm } from 'react-hook-form'; | ||
|
||
import { Settings, ThemeType } from '../../../storage'; | ||
|
||
export interface SettingsFormProps { | ||
id?: string; | ||
|
||
defaultValues?: Partial<Settings>; | ||
|
||
onSubmit: (payload: Settings) => void; | ||
} | ||
|
||
export const SettingsForm: React.FC<SettingsFormProps> = ({ | ||
onSubmit = () => {}, | ||
id, | ||
defaultValues, | ||
}) => { | ||
const { handleSubmit, control } = useForm<Settings>({ defaultValues }); | ||
|
||
return ( | ||
<form id={id} onSubmit={handleSubmit(onSubmit)}> | ||
<Container gap={0} display="flex" direction="column" justify="center"> | ||
<Controller | ||
name="theme" | ||
control={control} | ||
render={({ field }) => ( | ||
<Dropdown disableAnimation> | ||
<Dropdown.Button | ||
bordered | ||
borderWeight="light" | ||
animated={false} | ||
color="gradient" | ||
css={{ tt: 'capitalize' }} | ||
> | ||
{field.value} Theme | ||
</Dropdown.Button> | ||
<Dropdown.Menu | ||
aria-label="theme" | ||
color="primary" | ||
disallowEmptySelection | ||
selectionMode="single" | ||
defaultSelectedKeys={defaultValues?.theme} | ||
onSelectionChange={(keys) => { | ||
field.onChange(Array.from(keys).join('')); | ||
}} | ||
> | ||
<Dropdown.Item key={ThemeType.Light}>Light</Dropdown.Item> | ||
<Dropdown.Item key={ThemeType.Dark}>Dark</Dropdown.Item> | ||
</Dropdown.Menu> | ||
</Dropdown> | ||
)} | ||
/> | ||
</Container> | ||
</form> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './modals'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './update-settings.modal'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Button, Modal, ModalProps, Text } from '@nextui-org/react'; | ||
import React from 'react'; | ||
|
||
import { Settings, useSettingsStore } from '../../../storage'; | ||
import { SettingsForm } from '../forms'; | ||
|
||
export const UpdateSettingsModal: React.FC<ModalProps> = ({ onClose = () => {}, ...props }) => { | ||
const { updateTheme, theme } = useSettingsStore((store) => store); | ||
|
||
const handleSubmit = async (payload: Partial<Settings>) => { | ||
if (payload.theme) { | ||
await updateTheme(payload.theme); | ||
} | ||
|
||
onClose(); | ||
}; | ||
|
||
return ( | ||
<Modal {...props} onClose={onClose} aria-labelledby="update-settings-modal"> | ||
<Modal.Header css={{ userSelect: 'none' }}> | ||
<Text>Settings</Text> | ||
</Modal.Header> | ||
<Modal.Body> | ||
<SettingsForm | ||
id="update-settings-form" | ||
defaultValues={{ | ||
theme, | ||
}} | ||
onSubmit={handleSubmit} | ||
/> | ||
</Modal.Body> | ||
<Modal.Footer> | ||
<Button auto bordered borderWeight="light" size="sm" color="error" onClick={onClose}> | ||
Cancel | ||
</Button> | ||
<Button | ||
auto | ||
bordered | ||
borderWeight="light" | ||
size="sm" | ||
color="gradient" | ||
type="submit" | ||
form="update-settings-form" | ||
> | ||
Apply | ||
</Button> | ||
</Modal.Footer> | ||
</Modal> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
import { Language } from './language.interface'; | ||
import { ThemeType } from './theme.interface'; | ||
export enum Language { | ||
EN = 'en', | ||
} | ||
|
||
export enum ThemeType { | ||
Dark = 'dark', | ||
Light = 'light', | ||
} | ||
|
||
export interface SettingsStorage { | ||
type: ThemeType; | ||
export interface Settings { | ||
theme: ThemeType; | ||
language: Language; | ||
} | ||
|
||
export interface SettingsStorage extends Settings { | ||
updateTheme: (theme: ThemeType) => void; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters