2020-07-08 19:36:36 +02:00
|
|
|
import React, { useCallback, useEffect, useState } from "react";
|
|
|
|
import styled from "styled-components";
|
|
|
|
|
|
|
|
import Select from "react-select";
|
|
|
|
|
|
|
|
import searchData from "./data/search.json";
|
|
|
|
|
|
|
|
import selectedTheme, { setTheme } from "./themeManager";
|
|
|
|
import {
|
|
|
|
handleResponse,
|
|
|
|
Button,
|
|
|
|
ErrorMessage,
|
2020-07-10 00:04:47 +02:00
|
|
|
Headline as hl,
|
2020-07-08 19:36:36 +02:00
|
|
|
} from "./elements";
|
|
|
|
|
2020-09-08 13:18:58 +02:00
|
|
|
import Modal from "./modal";
|
|
|
|
|
2020-07-08 19:36:36 +02:00
|
|
|
const Headline = styled(hl)`
|
|
|
|
padding: 0.5rem 0;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const SelectContainer = styled.div`
|
|
|
|
padding-bottom: 1rem;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const FormContainer = styled.div`
|
|
|
|
display: grid;
|
|
|
|
grid-template-columns: auto auto auto;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const Table = styled.table`
|
|
|
|
font-weight: 400;
|
|
|
|
background: none;
|
|
|
|
color: ${selectedTheme.mainColor};
|
|
|
|
`;
|
|
|
|
|
|
|
|
const TableRow = styled.tr`
|
|
|
|
border-bottom: 1px solid ${selectedTheme.mainColor};
|
|
|
|
`;
|
|
|
|
|
|
|
|
const TableCell = styled.td`
|
|
|
|
background: none;
|
|
|
|
padding-top: 0.5rem;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const HeadCell = styled.th`
|
|
|
|
font-weight: 700;
|
|
|
|
background: none;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const SelectorStyle = {
|
|
|
|
control: (provided: any) => ({
|
|
|
|
...provided,
|
|
|
|
fontWeight: "500",
|
|
|
|
color: selectedTheme.mainColor,
|
|
|
|
textTransform: "uppercase",
|
|
|
|
width: "12rem",
|
|
|
|
background: "none",
|
|
|
|
borderRadius: "0px",
|
|
|
|
border: "1px solid " + selectedTheme.mainColor,
|
|
|
|
boxShadow: 0,
|
|
|
|
"&:hover": {
|
2020-07-10 00:04:47 +02:00
|
|
|
border: "1px solid " + selectedTheme.mainColor,
|
|
|
|
},
|
2020-07-08 19:36:36 +02:00
|
|
|
}),
|
|
|
|
menu: (provided: any) => ({
|
|
|
|
...provided,
|
|
|
|
backgroundColor: selectedTheme.backgroundColor,
|
|
|
|
border: "1px solid " + selectedTheme.mainColor,
|
|
|
|
borderRadius: 0,
|
2020-07-10 00:04:47 +02:00
|
|
|
boxShadow: 0,
|
2020-07-08 19:36:36 +02:00
|
|
|
}),
|
|
|
|
option: (provided: any) => ({
|
|
|
|
...provided,
|
|
|
|
fontWeight: "500",
|
|
|
|
color: selectedTheme.mainColor,
|
|
|
|
textTransform: "uppercase",
|
|
|
|
borderRadius: 0,
|
|
|
|
boxShadow: 0,
|
|
|
|
backgroundColor: selectedTheme.backgroundColor,
|
|
|
|
"&:hover": {
|
|
|
|
backgroundColor: selectedTheme.mainColor,
|
2020-07-10 00:04:47 +02:00
|
|
|
color: selectedTheme.backgroundColor,
|
|
|
|
},
|
2020-07-08 19:36:36 +02:00
|
|
|
}),
|
|
|
|
singleValue: (provided: any) => {
|
|
|
|
return {
|
|
|
|
...provided,
|
2020-07-10 00:04:47 +02:00
|
|
|
color: selectedTheme.mainColor,
|
2020-07-08 19:36:36 +02:00
|
|
|
};
|
2020-07-10 00:04:47 +02:00
|
|
|
},
|
2020-07-08 19:36:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const useThemeData = () => {
|
|
|
|
const [themeData, setThemeData] = useState({ themes: [], error: false });
|
|
|
|
|
|
|
|
const fetchThemeData = useCallback(() => {
|
|
|
|
(process.env.NODE_ENV === "production"
|
|
|
|
? fetch("/data/themes.json").then(handleResponse)
|
|
|
|
: import("./data/themes.json")
|
|
|
|
)
|
2020-07-10 00:04:47 +02:00
|
|
|
.then((jsonResponse) => {
|
2020-07-08 19:36:36 +02:00
|
|
|
setThemeData({ ...jsonResponse, error: false });
|
|
|
|
})
|
2020-07-10 00:04:47 +02:00
|
|
|
.catch((error) => {
|
2020-07-08 19:36:36 +02:00
|
|
|
setThemeData({ themes: [], error: error.message });
|
|
|
|
});
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
fetchThemeData();
|
|
|
|
}, [fetchThemeData]);
|
|
|
|
return { themeData, fetchThemeData };
|
|
|
|
};
|
|
|
|
|
2020-09-08 13:18:58 +02:00
|
|
|
const Settings = () => {
|
2020-07-08 19:36:36 +02:00
|
|
|
const [newTheme, setNewTheme] = useState();
|
|
|
|
|
|
|
|
const {
|
2020-07-10 00:04:47 +02:00
|
|
|
themeData: { themes, error },
|
2020-07-08 19:36:36 +02:00
|
|
|
} = useThemeData();
|
|
|
|
|
2020-07-10 00:04:47 +02:00
|
|
|
useEffect(() => {
|
|
|
|
console.log(newTheme);
|
|
|
|
}, [newTheme]);
|
|
|
|
|
2020-07-08 19:36:36 +02:00
|
|
|
return (
|
2020-09-08 13:18:58 +02:00
|
|
|
<Modal element="icon" icon="settings">
|
|
|
|
{error && <ErrorMessage>{error}</ErrorMessage>}
|
|
|
|
<SelectContainer>
|
|
|
|
<Headline>Theme:</Headline>
|
|
|
|
<FormContainer>
|
|
|
|
<Select
|
|
|
|
options={themes}
|
|
|
|
defaultValue={selectedTheme}
|
|
|
|
onChange={(e: any) => {
|
|
|
|
setNewTheme(e);
|
|
|
|
}}
|
|
|
|
styles={SelectorStyle}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<Button onClick={() => setTheme(JSON.stringify(newTheme))}>
|
|
|
|
Apply
|
|
|
|
</Button>
|
|
|
|
<Button onClick={() => window.location.reload()}>Refresh</Button>
|
|
|
|
</FormContainer>
|
|
|
|
</SelectContainer>
|
|
|
|
<Table>
|
|
|
|
<tbody>
|
|
|
|
<TableRow>
|
|
|
|
<HeadCell>Search Provider</HeadCell>
|
|
|
|
<HeadCell>Prefix</HeadCell>
|
|
|
|
</TableRow>
|
|
|
|
{searchData.providers.map((provider, index) => (
|
|
|
|
<TableRow key={provider.name + index}>
|
|
|
|
<TableCell>{provider.name}</TableCell>
|
|
|
|
<TableCell>{provider.prefix}</TableCell>
|
2020-07-08 19:36:36 +02:00
|
|
|
</TableRow>
|
2020-09-08 13:18:58 +02:00
|
|
|
))}
|
|
|
|
</tbody>
|
|
|
|
</Table>
|
|
|
|
</Modal>
|
2020-07-08 19:36:36 +02:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-09-08 13:18:58 +02:00
|
|
|
export default Settings;
|