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-07-02 11:41:02 +02:00
|
|
|
import Select from "./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-30 00:56:01 +02:00
|
|
|
const ThemeSelect = styled(Select)`
|
|
|
|
-webkit-appearance: button;
|
|
|
|
-moz-appearance: button;
|
|
|
|
|
|
|
|
text-transform: uppercase;
|
|
|
|
font-family: Roboto, sans-serif;
|
|
|
|
font-weight: 400;
|
|
|
|
border: 1px solid ${selectedTheme.mainColor};
|
|
|
|
color: ${selectedTheme.mainColor};
|
|
|
|
background: none;
|
|
|
|
|
|
|
|
& > option {
|
|
|
|
background-color: ${selectedTheme.backgroundColor};
|
|
|
|
}
|
|
|
|
`;
|
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>
|
2021-06-30 00:56:01 +02:00
|
|
|
<ThemeSelect
|
|
|
|
items={themes}
|
|
|
|
onChange={(theme: IThemeProps) => setNewTheme(theme)}
|
|
|
|
></ThemeSelect>
|
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>
|
2021-06-30 00:56:01 +02:00
|
|
|
{search.providers.map(({ name, prefix }, index) => (
|
|
|
|
<TableRow key={name + index}>
|
|
|
|
<TableCell>{name}</TableCell>
|
|
|
|
<TableCell>{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;
|