2021-06-14 11:29:03 +02:00
|
|
|
import { useState } from "react";
|
2020-07-08 19:36:36 +02:00
|
|
|
import styled from "styled-components";
|
|
|
|
|
2021-04-03 16:54:44 +02:00
|
|
|
import Select, { ValueType } from "react-select";
|
2020-07-08 19:36:36 +02:00
|
|
|
|
2021-04-22 11:15:41 +02:00
|
|
|
import { ISearchProps } from "./searchBar";
|
2021-03-21 18:05:24 +01:00
|
|
|
import selectedTheme, { setTheme, IThemeProps } from "../lib/theme";
|
|
|
|
import { Button, SubHeadline } from "./elements";
|
2020-07-08 19:36:36 +02:00
|
|
|
|
2020-09-08 13:18:58 +02:00
|
|
|
import Modal from "./modal";
|
|
|
|
|
2021-06-21 16:52:16 +02:00
|
|
|
export const FormContainer = styled.div`
|
2020-07-08 19:36:36 +02:00
|
|
|
display: grid;
|
|
|
|
grid-template-columns: auto auto auto;
|
|
|
|
`;
|
|
|
|
|
2021-06-21 16:52:16 +02:00
|
|
|
export const Table = styled.table`
|
2020-07-08 19:36:36 +02:00
|
|
|
font-weight: 400;
|
|
|
|
background: none;
|
2021-04-22 11:15:41 +02:00
|
|
|
width: 100%;
|
2020-07-08 19:36:36 +02:00
|
|
|
color: ${selectedTheme.mainColor};
|
|
|
|
`;
|
|
|
|
|
2021-06-21 16:52:16 +02:00
|
|
|
export const TableRow = styled.tr`
|
2020-07-08 19:36:36 +02:00
|
|
|
border-bottom: 1px solid ${selectedTheme.mainColor};
|
|
|
|
`;
|
|
|
|
|
2021-06-21 16:52:16 +02:00
|
|
|
export const TableCell = styled.td`
|
2020-07-08 19:36:36 +02:00
|
|
|
background: none;
|
|
|
|
padding-top: 0.5rem;
|
|
|
|
`;
|
|
|
|
|
2021-06-21 16:52:16 +02:00
|
|
|
export const HeadCell = styled.th`
|
2020-07-08 19:36:36 +02:00
|
|
|
font-weight: 700;
|
2021-04-22 11:15:41 +02:00
|
|
|
text-align: left;
|
2020-07-08 19:36:36 +02:00
|
|
|
`;
|
|
|
|
|
2021-06-21 16:52:16 +02:00
|
|
|
export const Section = styled.div`
|
2021-03-21 18:05:24 +01:00
|
|
|
padding: 1rem 0;
|
|
|
|
`;
|
|
|
|
|
2021-06-21 16:52:16 +02:00
|
|
|
export const SectionHeadline = styled(SubHeadline)`
|
2021-03-21 18:05:24 +01:00
|
|
|
width: 100%;
|
|
|
|
border-bottom: 1px solid ${selectedTheme.accentColor};
|
|
|
|
margin-bottom: 0.5rem;
|
|
|
|
`;
|
|
|
|
|
2021-04-22 11:15:41 +02:00
|
|
|
const Text = styled.p`
|
|
|
|
font-weight: 700;
|
|
|
|
color: ${selectedTheme.accentColor};
|
|
|
|
`;
|
|
|
|
|
|
|
|
const Code = styled.p`
|
|
|
|
font-family: monospace;
|
|
|
|
color: ${selectedTheme.accentColor};
|
|
|
|
`;
|
|
|
|
|
2021-06-21 16:52:16 +02:00
|
|
|
export const SelectorStyle: any = {
|
2021-04-03 16:54:44 +02:00
|
|
|
container: (base: any): any => ({
|
2021-03-21 18:05:24 +01:00
|
|
|
...base,
|
|
|
|
margin: "0 2px",
|
|
|
|
}),
|
2021-04-03 16:54:44 +02:00
|
|
|
control: (base: any): any => ({
|
2021-03-21 18:05:24 +01:00
|
|
|
...base,
|
|
|
|
fontWeight: 500,
|
2020-07-08 19:36:36 +02:00
|
|
|
color: selectedTheme.mainColor,
|
|
|
|
textTransform: "uppercase",
|
|
|
|
width: "12rem",
|
|
|
|
background: "none",
|
2021-03-21 18:05:24 +01:00
|
|
|
borderRadius: 0,
|
|
|
|
border: "1px solid",
|
|
|
|
borderColor: selectedTheme.mainColor,
|
|
|
|
boxShadow: "none",
|
2020-07-08 19:36:36 +02:00
|
|
|
"&:hover": {
|
2021-03-21 18:05:24 +01:00
|
|
|
border: "1px solid",
|
2021-06-14 11:29:03 +02:00
|
|
|
borderColor: selectedTheme.mainColor,
|
2020-07-10 00:04:47 +02:00
|
|
|
},
|
2020-07-08 19:36:36 +02:00
|
|
|
}),
|
2021-04-03 16:54:44 +02:00
|
|
|
dropdownIndicator: (base: any): any => ({
|
|
|
|
...base,
|
|
|
|
color: selectedTheme.mainColor,
|
|
|
|
"&:hover": {
|
2021-06-14 11:29:03 +02:00
|
|
|
color: selectedTheme.mainColor,
|
|
|
|
},
|
2021-04-03 16:54:44 +02:00
|
|
|
}),
|
|
|
|
indicatorSeparator: () => ({
|
|
|
|
display: "none",
|
|
|
|
}),
|
|
|
|
menu: (base: any): any => ({
|
2021-03-21 18:05:24 +01:00
|
|
|
...base,
|
2020-07-08 19:36:36 +02:00
|
|
|
backgroundColor: selectedTheme.backgroundColor,
|
|
|
|
border: "1px solid " + selectedTheme.mainColor,
|
|
|
|
borderRadius: 0,
|
2021-03-21 18:05:24 +01:00
|
|
|
boxShadow: "none",
|
2021-06-14 11:29:03 +02:00
|
|
|
margin: "4px 0",
|
2020-07-08 19:36:36 +02:00
|
|
|
}),
|
2021-04-03 16:54:44 +02:00
|
|
|
option: (base: any): any => ({
|
2021-03-21 18:05:24 +01:00
|
|
|
...base,
|
|
|
|
fontWeight: 500,
|
2020-07-08 19:36:36 +02:00
|
|
|
color: selectedTheme.mainColor,
|
|
|
|
textTransform: "uppercase",
|
|
|
|
borderRadius: 0,
|
2021-03-21 18:05:24 +01:00
|
|
|
boxShadow: "none",
|
2020-07-08 19:36:36 +02:00
|
|
|
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
|
|
|
}),
|
2021-04-03 16:54:44 +02:00
|
|
|
singleValue: (base: any): any => ({
|
2021-03-21 18:05:24 +01:00
|
|
|
...base,
|
|
|
|
color: selectedTheme.mainColor,
|
|
|
|
}),
|
2020-07-08 19:36:36 +02:00
|
|
|
};
|
|
|
|
|
2021-03-05 22:00:32 +01:00
|
|
|
interface ISettingsProps {
|
|
|
|
themes: Array<IThemeProps> | undefined;
|
2021-04-22 11:15:41 +02:00
|
|
|
search: ISearchProps | undefined;
|
2021-03-05 22:00:32 +01:00
|
|
|
}
|
2020-07-08 19:36:36 +02:00
|
|
|
|
2021-03-21 19:59:18 +01:00
|
|
|
/**
|
|
|
|
* Handles the settings-modal
|
|
|
|
* @param {Array<IThemeProps>} themes - the list of themes a user can select between
|
2021-04-22 11:15:41 +02:00
|
|
|
* @param {ISearchProps} search - the list of search providers
|
2021-03-21 19:59:18 +01:00
|
|
|
*/
|
2021-04-22 11:15:41 +02:00
|
|
|
const Settings = ({ themes, search }: ISettingsProps) => {
|
2021-03-23 16:26:14 +01:00
|
|
|
const [newTheme, setNewTheme] = useState<IThemeProps>();
|
2020-07-08 19:36:36 +02:00
|
|
|
|
2021-06-21 20:16:40 +02:00
|
|
|
if (themes || search) {
|
2021-03-05 22:00:32 +01:00
|
|
|
return (
|
2021-03-21 18:05:24 +01:00
|
|
|
<Modal element="icon" icon="settings" title="Settings">
|
2021-03-05 22:00:32 +01:00
|
|
|
{themes && (
|
2021-03-21 18:05:24 +01:00
|
|
|
<Section>
|
|
|
|
<SectionHeadline>Theme:</SectionHeadline>
|
2021-03-05 22:00:32 +01:00
|
|
|
<FormContainer>
|
|
|
|
<Select
|
2021-06-21 16:52:16 +02:00
|
|
|
classNamePrefix="list"
|
2021-03-05 22:00:32 +01:00
|
|
|
options={themes}
|
|
|
|
defaultValue={selectedTheme}
|
2021-03-23 16:26:14 +01:00
|
|
|
onChange={(e: ValueType<IThemeProps, false>) => {
|
|
|
|
if (e !== null && e !== undefined) setNewTheme(e);
|
2021-03-05 22:00:32 +01:00
|
|
|
}}
|
|
|
|
styles={SelectorStyle}
|
|
|
|
/>
|
2021-06-21 16:52:16 +02:00
|
|
|
<Button
|
|
|
|
data-testid="button-submit"
|
2021-06-21 20:16:40 +02:00
|
|
|
onClick={() => {
|
|
|
|
if (newTheme) setTheme(newTheme);
|
|
|
|
}}
|
2021-06-21 16:52:16 +02:00
|
|
|
>
|
2021-03-05 22:00:32 +01:00
|
|
|
Apply
|
|
|
|
</Button>
|
2021-06-21 16:52:16 +02:00
|
|
|
<Button
|
|
|
|
data-testid="button-refresh"
|
|
|
|
onClick={() => window.location.reload()}
|
|
|
|
>
|
|
|
|
Refresh
|
|
|
|
</Button>
|
2021-03-05 22:00:32 +01:00
|
|
|
</FormContainer>
|
2021-03-21 18:05:24 +01:00
|
|
|
</Section>
|
2021-03-05 22:00:32 +01:00
|
|
|
)}
|
2021-04-22 11:15:41 +02:00
|
|
|
{search && (
|
2021-03-21 18:05:24 +01:00
|
|
|
<Section>
|
|
|
|
<SectionHeadline>Search Providers</SectionHeadline>
|
2021-04-22 11:15:41 +02:00
|
|
|
<>
|
|
|
|
<Text>Default Search Provider</Text>
|
|
|
|
<Code>{search.defaultProvider}</Code>
|
|
|
|
</>
|
|
|
|
<>
|
2021-06-21 20:16:40 +02:00
|
|
|
{search.providers && (
|
|
|
|
<Table>
|
|
|
|
<tbody>
|
|
|
|
<TableRow>
|
|
|
|
<HeadCell>Search Provider</HeadCell>
|
|
|
|
<HeadCell>Prefix</HeadCell>
|
|
|
|
</TableRow>
|
|
|
|
{search.providers.map((provider, index) => (
|
|
|
|
<TableRow key={provider.name + index}>
|
|
|
|
<TableCell>{provider.name}</TableCell>
|
|
|
|
<TableCell>{provider.prefix}</TableCell>
|
2021-04-22 11:15:41 +02:00
|
|
|
</TableRow>
|
2021-06-21 20:16:40 +02:00
|
|
|
))}
|
|
|
|
</tbody>
|
|
|
|
</Table>
|
|
|
|
)}
|
2021-04-22 11:15:41 +02:00
|
|
|
</>
|
2021-03-21 18:05:24 +01:00
|
|
|
</Section>
|
2021-03-05 22:00:32 +01:00
|
|
|
)}
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return <></>;
|
|
|
|
}
|
2020-07-08 19:36:36 +02:00
|
|
|
};
|
|
|
|
|
2020-09-08 13:18:58 +02:00
|
|
|
export default Settings;
|