mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-28 15:19:36 +02:00
Moved Themer to Settings. Added option to set default theme
This commit is contained in:
parent
426766225b
commit
e2285e2deb
20 changed files with 156 additions and 54 deletions
|
@ -59,7 +59,7 @@ export const DockerSettings = (): JSX.Element => {
|
|||
<SettingsHeadline text="Docker" />
|
||||
{/* CUSTOM DOCKER SOCKET HOST */}
|
||||
<InputGroup>
|
||||
<label htmlFor="dockerHost">Docker Host</label>
|
||||
<label htmlFor="dockerHost">Docker host</label>
|
||||
<input
|
||||
type="text"
|
||||
id="dockerHost"
|
||||
|
|
|
@ -70,7 +70,7 @@ export const SearchSettings = (): JSX.Element => {
|
|||
>
|
||||
<SettingsHeadline text="General" />
|
||||
<InputGroup>
|
||||
<label htmlFor="defaultSearchProvider">Default Search Provider</label>
|
||||
<label htmlFor="defaultSearchProvider">Default search provider</label>
|
||||
<select
|
||||
id="defaultSearchProvider"
|
||||
name="defaultSearchProvider"
|
||||
|
|
|
@ -11,7 +11,7 @@ import { Route as SettingsRoute } from '../../interfaces';
|
|||
import classes from './Settings.module.css';
|
||||
|
||||
// Components
|
||||
import { Themer } from '../Themer/Themer';
|
||||
import { Themer } from './Themer/Themer';
|
||||
import { WeatherSettings } from './WeatherSettings/WeatherSettings';
|
||||
import { UISettings } from './UISettings/UISettings';
|
||||
import { AppDetails } from './AppDetails/AppDetails';
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
text-transform: capitalize;
|
||||
margin: 8px 0;
|
||||
color: var(--color-primary);
|
||||
/* align-self: flex-start; */
|
||||
}
|
||||
|
||||
.ColorsPreview {
|
||||
|
@ -32,4 +31,4 @@
|
|||
width: 40px;
|
||||
height: 40px;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
import { Theme } from '../../interfaces/Theme';
|
||||
import { Theme } from '../../../interfaces/Theme';
|
||||
import classes from './ThemePreview.module.css';
|
||||
|
||||
interface Props {
|
101
client/src/components/Settings/Themer/Themer.tsx
Normal file
101
client/src/components/Settings/Themer/Themer.tsx
Normal file
|
@ -0,0 +1,101 @@
|
|||
import { ChangeEvent, FormEvent, Fragment, useEffect, useState } from 'react';
|
||||
|
||||
// Redux
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import { actionCreators } from '../../../store';
|
||||
|
||||
// Typescript
|
||||
import { Theme, ThemeSettingsForm } from '../../../interfaces';
|
||||
|
||||
// Components
|
||||
import { ThemePreview } from './ThemePreview';
|
||||
import { Button, InputGroup, SettingsHeadline } from '../../UI';
|
||||
|
||||
// Other
|
||||
import classes from './Themer.module.css';
|
||||
import { themes } from './themes.json';
|
||||
import { State } from '../../../store/reducers';
|
||||
import { inputHandler, themeSettingsTemplate } from '../../../utility';
|
||||
|
||||
export const Themer = (): JSX.Element => {
|
||||
const {
|
||||
auth: { isAuthenticated },
|
||||
config: { loading, config },
|
||||
} = useSelector((state: State) => state);
|
||||
|
||||
const dispatch = useDispatch();
|
||||
const { setTheme, updateConfig } = bindActionCreators(
|
||||
actionCreators,
|
||||
dispatch
|
||||
);
|
||||
|
||||
// Initial state
|
||||
const [formData, setFormData] = useState<ThemeSettingsForm>(
|
||||
themeSettingsTemplate
|
||||
);
|
||||
|
||||
// Get config
|
||||
useEffect(() => {
|
||||
setFormData({
|
||||
...config,
|
||||
});
|
||||
}, [loading]);
|
||||
|
||||
// Form handler
|
||||
const formSubmitHandler = async (e: FormEvent) => {
|
||||
e.preventDefault();
|
||||
|
||||
// Save settings
|
||||
await updateConfig(formData);
|
||||
};
|
||||
|
||||
// Input handler
|
||||
const inputChangeHandler = (
|
||||
e: ChangeEvent<HTMLInputElement | HTMLSelectElement>,
|
||||
options?: { isNumber?: boolean; isBool?: boolean }
|
||||
) => {
|
||||
inputHandler<ThemeSettingsForm>({
|
||||
e,
|
||||
options,
|
||||
setStateHandler: setFormData,
|
||||
state: formData,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
<SettingsHeadline text="Set theme" />
|
||||
<div className={classes.ThemerGrid}>
|
||||
{themes.map(
|
||||
(theme: Theme, idx: number): JSX.Element => (
|
||||
<ThemePreview key={idx} theme={theme} applyTheme={setTheme} />
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
|
||||
{isAuthenticated && (
|
||||
<form onSubmit={formSubmitHandler}>
|
||||
<SettingsHeadline text="Other settings" />
|
||||
<InputGroup>
|
||||
<label htmlFor="defaultTheme">Default theme (for new users)</label>
|
||||
<select
|
||||
id="defaultTheme"
|
||||
name="defaultTheme"
|
||||
value={formData.defaultTheme}
|
||||
onChange={(e) => inputChangeHandler(e)}
|
||||
>
|
||||
{themes.map((theme: Theme, idx) => (
|
||||
<option key={idx} value={theme.name}>
|
||||
{theme.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</InputGroup>
|
||||
|
||||
<Button>Save changes</Button>
|
||||
</form>
|
||||
)}
|
||||
</Fragment>
|
||||
);
|
||||
};
|
|
@ -1,29 +0,0 @@
|
|||
import { Fragment } from 'react';
|
||||
import { useDispatch } from 'react-redux';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import { actionCreators } from '../../store';
|
||||
|
||||
import classes from './Themer.module.css';
|
||||
|
||||
import { themes } from './themes.json';
|
||||
import { Theme } from '../../interfaces/Theme';
|
||||
import { ThemePreview } from './ThemePreview';
|
||||
|
||||
export const Themer = (): JSX.Element => {
|
||||
const dispatch = useDispatch();
|
||||
const { setTheme } = bindActionCreators(actionCreators, dispatch);
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
<div>
|
||||
<div className={classes.ThemerGrid}>
|
||||
{themes.map(
|
||||
(theme: Theme, idx: number): JSX.Element => (
|
||||
<ThemePreview key={idx} theme={theme} applyTheme={setTheme} />
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</Fragment>
|
||||
);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue