ThemeEditor: allow exporting a theme
This commit is contained in:
parent
b15871aaa8
commit
c624fbcba3
|
@ -8,13 +8,16 @@ import snackbar from 'soapbox/actions/snackbar';
|
||||||
import { fetchSoapboxConfig } from 'soapbox/actions/soapbox';
|
import { fetchSoapboxConfig } from 'soapbox/actions/soapbox';
|
||||||
import List, { ListItem } from 'soapbox/components/list';
|
import List, { ListItem } from 'soapbox/components/list';
|
||||||
import { Button, Column, Form, FormActions } from 'soapbox/components/ui';
|
import { Button, Column, Form, FormActions } from 'soapbox/components/ui';
|
||||||
|
import DropdownMenuContainer from 'soapbox/containers/dropdown-menu-container';
|
||||||
import { useAppDispatch, useAppSelector, useSoapboxConfig } from 'soapbox/hooks';
|
import { useAppDispatch, useAppSelector, useSoapboxConfig } from 'soapbox/hooks';
|
||||||
|
import { download } from 'soapbox/utils/download';
|
||||||
|
|
||||||
import Palette, { ColorGroup } from './components/palette';
|
import Palette, { ColorGroup } from './components/palette';
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
title: { id: 'admin.theme.title', defaultMessage: 'Theme' },
|
title: { id: 'admin.theme.title', defaultMessage: 'Theme' },
|
||||||
saved: { id: 'theme_editor.saved', defaultMessage: 'Theme updated!' },
|
saved: { id: 'theme_editor.saved', defaultMessage: 'Theme updated!' },
|
||||||
|
export: { id: 'theme_editor.export', defaultMessage: 'Export theme' },
|
||||||
});
|
});
|
||||||
|
|
||||||
interface IThemeEditor {
|
interface IThemeEditor {
|
||||||
|
@ -55,6 +58,11 @@ const ThemeEditor: React.FC<IThemeEditor> = () => {
|
||||||
await dispatch(updateSoapboxConfig(params));
|
await dispatch(updateSoapboxConfig(params));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const exportTheme = () => {
|
||||||
|
const data = JSON.stringify(colors, null, 2);
|
||||||
|
download(data, 'theme.json');
|
||||||
|
};
|
||||||
|
|
||||||
const handleSubmit = async() => {
|
const handleSubmit = async() => {
|
||||||
setSubmitting(true);
|
setSubmitting(true);
|
||||||
|
|
||||||
|
@ -116,6 +124,12 @@ const ThemeEditor: React.FC<IThemeEditor> = () => {
|
||||||
</List>
|
</List>
|
||||||
|
|
||||||
<FormActions>
|
<FormActions>
|
||||||
|
<DropdownMenuContainer
|
||||||
|
items={[{
|
||||||
|
text: intl.formatMessage(messages.export),
|
||||||
|
action: exportTheme,
|
||||||
|
}]}
|
||||||
|
/>
|
||||||
<Button theme='secondary' onClick={resetTheme}>
|
<Button theme='secondary' onClick={resetTheme}>
|
||||||
<FormattedMessage id='theme_editor.Reset' defaultMessage='Reset' />
|
<FormattedMessage id='theme_editor.Reset' defaultMessage='Reset' />
|
||||||
</Button>
|
</Button>
|
||||||
|
|
Loading…
Reference in New Issue