Compare commits
No commits in common. "master" and "v2.1.0" have entirely different histories.
106 changed files with 11487 additions and 30095 deletions
|
@ -1 +0,0 @@
|
|||
docker build -t flame:dev -f .docker/Dockerfile .
|
|
@ -1,2 +0,0 @@
|
|||
docker build -t pawelmalak/flame -t "pawelmalak/flame:$1" -f .docker/Dockerfile . \
|
||||
&& docker push pawelmalak/flame && docker push "pawelmalak/flame:$1"
|
|
@ -1,6 +0,0 @@
|
|||
docker buildx build \
|
||||
--platform linux/arm/v7,linux/arm64,linux/amd64 \
|
||||
-f .docker/Dockerfile.multiarch \
|
||||
-t pawelmalak/flame:multiarch \
|
||||
-t "pawelmalak/flame:multiarch$1" \
|
||||
--push .
|
|
@ -1,4 +1,4 @@
|
|||
FROM node:16 as builder
|
||||
FROM node:14 as builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
|
@ -16,7 +16,7 @@ RUN mkdir -p ./public ./data \
|
|||
&& mv ./client/build/* ./public \
|
||||
&& rm -rf ./client
|
||||
|
||||
FROM node:16-alpine
|
||||
FROM node:14-alpine
|
||||
|
||||
COPY --from=builder /app /app
|
||||
|
||||
|
@ -27,4 +27,4 @@ EXPOSE 5005
|
|||
ENV NODE_ENV=production
|
||||
ENV PASSWORD=flame_password
|
||||
|
||||
CMD ["sh", "-c", "chown -R node /app/data && node server.js"]
|
||||
CMD ["node", "server.js"]
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
FROM node:16-alpine3.11 as builder
|
||||
FROM node:14-alpine3.11 as builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY package*.json ./
|
||||
|
||||
RUN apk --no-cache --virtual build-dependencies add python python3 make g++ \
|
||||
RUN apk --no-cache --virtual build-dependencies add python make g++ \
|
||||
&& npm install --production
|
||||
|
||||
COPY . .
|
||||
|
@ -17,7 +17,7 @@ RUN mkdir -p ./public ./data \
|
|||
&& mv ./client/build/* ./public \
|
||||
&& rm -rf ./client
|
||||
|
||||
FROM node:16-alpine3.11
|
||||
FROM node:14-alpine3.11
|
||||
|
||||
COPY --from=builder /app /app
|
||||
|
||||
|
@ -28,4 +28,4 @@ EXPOSE 5005
|
|||
ENV NODE_ENV=production
|
||||
ENV PASSWORD=flame_password
|
||||
|
||||
CMD ["sh", "-c", "chown -R node /app/data && node server.js"]
|
||||
CMD ["node", "server.js"]
|
|
@ -1,22 +1,12 @@
|
|||
version: '3.6'
|
||||
|
||||
version: '3'
|
||||
services:
|
||||
flame:
|
||||
image: pawelmalak/flame
|
||||
container_name: flame
|
||||
volumes:
|
||||
- /path/to/host/data:/app/data
|
||||
# - /var/run/docker.sock:/var/run/docker.sock # optional but required for Docker integration
|
||||
- /path/to/data:/app/data
|
||||
ports:
|
||||
- 5005:5005
|
||||
# secrets:
|
||||
# - password # optional but required for (1)
|
||||
environment:
|
||||
- PASSWORD=flame_password
|
||||
# - PASSWORD_FILE=/run/secrets/password # optional but required for (1)
|
||||
restart: unless-stopped
|
||||
|
||||
# optional but required for Docker secrets (1)
|
||||
# secrets:
|
||||
# password:
|
||||
# file: /path/to/secrets/password
|
||||
|
|
|
@ -2,5 +2,4 @@ node_modules
|
|||
.github
|
||||
public
|
||||
k8s
|
||||
skaffold.yaml
|
||||
data
|
||||
skaffold.yaml
|
2
.env
2
.env
|
@ -1,5 +1,5 @@
|
|||
PORT=5005
|
||||
NODE_ENV=development
|
||||
VERSION=2.3.1
|
||||
VERSION=2.1.0
|
||||
PASSWORD=flame_password
|
||||
SECRET=e02eb43d69953658c6d07311d6313f2d4467672cb881f96b29368ba1f3f4da4b
|
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,4 +1,5 @@
|
|||
node_modules
|
||||
data
|
||||
public
|
||||
!client/public
|
||||
!client/public
|
||||
build.sh
|
|
@ -1,2 +1 @@
|
|||
*.md
|
||||
docker-compose.yml
|
||||
*.md
|
34
CHANGELOG.md
34
CHANGELOG.md
|
@ -1,37 +1,3 @@
|
|||
### v2.3.1 (2023-07-23)
|
||||
- Fixed bug where "Open search results in the same tab" setting was not respected if "Local search" was set as primary search provider ([#270](https://github.com/pawelmalak/flame/issues/270))
|
||||
- Fixed bug where search bar had rounded input field on iOS ([#394](https://github.com/pawelmalak/flame/issues/394))
|
||||
- Updated link to Material Design Icons reference page ([#414](https://github.com/pawelmalak/flame/issues/414))
|
||||
- Fixed bug where color inputs in theme creator/editor were too small ([#429](https://github.com/pawelmalak/flame/issues/429))
|
||||
- Changed input labels in settings for more consistent naming ([#430](https://github.com/pawelmalak/flame/issues/430))
|
||||
|
||||
### v2.3.0 (2022-03-25)
|
||||
- Added custom theme editor ([#246](https://github.com/pawelmalak/flame/issues/246))
|
||||
- Added option to set secondary search provider ([#295](https://github.com/pawelmalak/flame/issues/295))
|
||||
- Fixed bug where pressing Enter with empty search bar would redirect to search results ([#325](https://github.com/pawelmalak/flame/issues/325))
|
||||
- Fixed bug where user could create empty app or bookmark which was causing page to go blank ([#332](https://github.com/pawelmalak/flame/issues/332))
|
||||
- Added new theme: Mint
|
||||
|
||||
### v2.2.2 (2022-03-21)
|
||||
- Added option to get user location directly from the app ([#287](https://github.com/pawelmalak/flame/issues/287))
|
||||
- Fixed bug with local search not working when using prefix ([#289](https://github.com/pawelmalak/flame/issues/289))
|
||||
- Fixed bug with app description not updating when using custom icon ([#310](https://github.com/pawelmalak/flame/issues/310))
|
||||
- Changed permissions to some files and directories created by Flame
|
||||
- Changed some of the settings tabs
|
||||
|
||||
### v2.2.1 (2022-01-08)
|
||||
- Local search will now include app descriptions ([#266](https://github.com/pawelmalak/flame/issues/266))
|
||||
- Fixed bug with unsupported characters in local search [#279](https://github.com/pawelmalak/flame/issues/279))
|
||||
- Background tasks optimization ([#283](https://github.com/pawelmalak/flame/issues/283))
|
||||
|
||||
### v2.2.0 (2021-12-17)
|
||||
- Added option to set custom description for apps ([#201](https://github.com/pawelmalak/flame/issues/201))
|
||||
- Fixed fatal error while deploying Flame to cluster ([#242](https://github.com/pawelmalak/flame/issues/242))
|
||||
|
||||
### v2.1.1 (2021-12-02)
|
||||
- Added support for Docker secrets ([#189](https://github.com/pawelmalak/flame/issues/189))
|
||||
- Changed some messages and buttons to make it easier to open bookmarks editor ([#239](https://github.com/pawelmalak/flame/issues/239))
|
||||
|
||||
### v2.1.0 (2021-11-26)
|
||||
- Added option to set custom order for bookmarks ([#43](https://github.com/pawelmalak/flame/issues/43)) and ([#187](https://github.com/pawelmalak/flame/issues/187))
|
||||
- Added support for .ico files for custom icons ([#209](https://github.com/pawelmalak/flame/issues/209))
|
||||
|
|
37
README.md
37
README.md
|
@ -11,7 +11,7 @@ Flame is self-hosted startpage for your server. Its design is inspired (heavily)
|
|||
- 📌 Pin your favourite items to the homescreen for quick and easy access
|
||||
- 🔍 Integrated search bar with local filtering, 11 web search providers and ability to add your own
|
||||
- 🔑 Authentication system to protect your settings, apps and bookmarks
|
||||
- 🔨 Dozens of options to customize Flame interface to your needs, including support for custom CSS, 15 built-in color themes and custom theme builder
|
||||
- 🔨 Dozens of options to customize Flame interface to your needs, including support for custom CSS and 15 built-in color themes
|
||||
- ☀️ Weather widget with current temperature, cloud coverage and animated weather status
|
||||
- 🐳 Docker integration to automatically pick and add apps based on their labels
|
||||
|
||||
|
@ -35,7 +35,7 @@ docker pull pawelmalak/flame:2.0.0
|
|||
|
||||
```sh
|
||||
# run container
|
||||
docker run -p 5005:5005 -v /path/to/data:/app/data -e PASSWORD=flame_password pawelmalak/flame
|
||||
docker run -p 5005:5005 -v /path/to/data:/app/data -e PASSWORD=flame_password flame
|
||||
```
|
||||
|
||||
#### Building images
|
||||
|
@ -55,42 +55,19 @@ docker buildx build \
|
|||
#### Docker-Compose
|
||||
|
||||
```yaml
|
||||
version: '3.6'
|
||||
|
||||
version: '2.1'
|
||||
services:
|
||||
flame:
|
||||
image: pawelmalak/flame
|
||||
image: pawelmalak/flame:latest
|
||||
container_name: flame
|
||||
volumes:
|
||||
- /path/to/host/data:/app/data
|
||||
- /var/run/docker.sock:/var/run/docker.sock # optional but required for Docker integration
|
||||
- <host_dir>:/app/data
|
||||
- /var/run/docker.sock:/var/run/docker.sock # optional but required for Docker integration feature
|
||||
ports:
|
||||
- 5005:5005
|
||||
secrets:
|
||||
- password # optional but required for (1)
|
||||
environment:
|
||||
- PASSWORD=flame_password
|
||||
- PASSWORD_FILE=/run/secrets/password # optional but required for (1)
|
||||
restart: unless-stopped
|
||||
|
||||
# optional but required for Docker secrets (1)
|
||||
secrets:
|
||||
password:
|
||||
file: /path/to/secrets/password
|
||||
```
|
||||
|
||||
##### Docker Secrets
|
||||
|
||||
All environment variables can be overwritten by appending `_FILE` to the variable value. For example, you can use `PASSWORD_FILE` to pass through a docker secret instead of `PASSWORD`. If both `PASSWORD` and `PASSWORD_FILE` are set, the docker secret will take precedent.
|
||||
|
||||
```bash
|
||||
# ./secrets/flame_password
|
||||
my_custom_secret_password_123
|
||||
|
||||
# ./docker-compose.yml
|
||||
secrets:
|
||||
password:
|
||||
file: ./secrets/flame_password
|
||||
```
|
||||
|
||||
#### Skaffold
|
||||
|
@ -235,7 +212,7 @@ metadata:
|
|||
- Backup your `db.sqlite` before running script!
|
||||
- Known Issues:
|
||||
- generated icons are sometimes incorrect
|
||||
|
||||
|
||||
```bash
|
||||
pip3 install Pillow, beautifulsoup4
|
||||
|
||||
|
|
1
api.js
1
api.js
|
@ -22,7 +22,6 @@ api.use('/api/categories', require('./routes/category'));
|
|||
api.use('/api/bookmarks', require('./routes/bookmark'));
|
||||
api.use('/api/queries', require('./routes/queries'));
|
||||
api.use('/api/auth', require('./routes/auth'));
|
||||
api.use('/api/themes', require('./routes/themes'));
|
||||
|
||||
// Custom error handler
|
||||
api.use(errorHandler);
|
||||
|
|
|
@ -1 +1 @@
|
|||
REACT_APP_VERSION=2.3.1
|
||||
REACT_APP_VERSION=2.1.0
|
33910
client/package-lock.json
generated
33910
client/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -11,6 +11,7 @@
|
|||
"@types/jest": "^27.0.2",
|
||||
"@types/node": "^16.11.6",
|
||||
"@types/react": "^17.0.34",
|
||||
"@types/react-autosuggest": "^10.1.5",
|
||||
"@types/react-beautiful-dnd": "^13.1.2",
|
||||
"@types/react-dom": "^17.0.11",
|
||||
"@types/react-redux": "^7.1.20",
|
||||
|
@ -20,11 +21,12 @@
|
|||
"http-proxy-middleware": "^2.0.1",
|
||||
"jwt-decode": "^3.1.2",
|
||||
"react": "^17.0.2",
|
||||
"react-autosuggest": "^10.1.0",
|
||||
"react-beautiful-dnd": "^13.1.0",
|
||||
"react-dom": "^17.0.2",
|
||||
"react-redux": "^7.2.6",
|
||||
"react-router-dom": "^5.2.0",
|
||||
"react-scripts": "^5.0.1",
|
||||
"react-scripts": "4.0.3",
|
||||
"redux": "^4.1.2",
|
||||
"redux-devtools-extension": "^2.13.9",
|
||||
"redux-thunk": "^2.4.0",
|
||||
|
|
|
@ -10,7 +10,7 @@ import { actionCreators, store } from './store';
|
|||
import { State } from './store/reducers';
|
||||
|
||||
// Utils
|
||||
import { checkVersion, decodeToken, parsePABToTheme } from './utility';
|
||||
import { checkVersion, decodeToken } from './utility';
|
||||
|
||||
// Routes
|
||||
import { Home } from './components/Home/Home';
|
||||
|
@ -31,7 +31,7 @@ export const App = (): JSX.Element => {
|
|||
const { config, loading } = useSelector((state: State) => state.config);
|
||||
|
||||
const dispath = useDispatch();
|
||||
const { fetchQueries, setTheme, logout, createNotification, fetchThemes } =
|
||||
const { fetchQueries, setTheme, logout, createNotification } =
|
||||
bindActionCreators(actionCreators, dispath);
|
||||
|
||||
useEffect(() => {
|
||||
|
@ -51,12 +51,9 @@ export const App = (): JSX.Element => {
|
|||
}
|
||||
}, 1000);
|
||||
|
||||
// load themes
|
||||
fetchThemes();
|
||||
|
||||
// set user theme if present
|
||||
if (localStorage.theme) {
|
||||
setTheme(parsePABToTheme(localStorage.theme));
|
||||
setTheme(localStorage.theme);
|
||||
}
|
||||
|
||||
// check for updated
|
||||
|
@ -71,7 +68,7 @@ export const App = (): JSX.Element => {
|
|||
// If there is no user theme, set the default one
|
||||
useEffect(() => {
|
||||
if (!loading && !localStorage.theme) {
|
||||
setTheme(parsePABToTheme(config.defaultTheme), false);
|
||||
setTheme(config.defaultTheme, false);
|
||||
}
|
||||
}, [loading]);
|
||||
|
||||
|
|
|
@ -8,15 +8,16 @@ import { State } from '../../../store/reducers';
|
|||
|
||||
interface Props {
|
||||
app: App;
|
||||
pinHandler?: Function;
|
||||
}
|
||||
|
||||
export const AppCard = ({ app }: Props): JSX.Element => {
|
||||
export const AppCard = (props: Props): JSX.Element => {
|
||||
const { config } = useSelector((state: State) => state.config);
|
||||
|
||||
const [displayUrl, redirectUrl] = urlParser(app.url);
|
||||
const [displayUrl, redirectUrl] = urlParser(props.app.url);
|
||||
|
||||
let iconEl: JSX.Element;
|
||||
const { icon } = app;
|
||||
const { icon } = props.app;
|
||||
|
||||
if (isImage(icon)) {
|
||||
const source = isUrl(icon) ? icon : `/uploads/${icon}`;
|
||||
|
@ -24,7 +25,7 @@ export const AppCard = ({ app }: Props): JSX.Element => {
|
|||
iconEl = (
|
||||
<img
|
||||
src={source}
|
||||
alt={`${app.name} icon`}
|
||||
alt={`${props.app.name} icon`}
|
||||
className={classes.CustomIcon}
|
||||
/>
|
||||
);
|
||||
|
@ -53,8 +54,8 @@ export const AppCard = ({ app }: Props): JSX.Element => {
|
|||
>
|
||||
<div className={classes.AppCardIcon}>{iconEl}</div>
|
||||
<div className={classes.AppCardDetails}>
|
||||
<h5>{app.name}</h5>
|
||||
<span>{!app.description.length ? displayUrl : app.description}</span>
|
||||
<h5>{props.app.name}</h5>
|
||||
<span>{displayUrl}</span>
|
||||
</div>
|
||||
</a>
|
||||
);
|
||||
|
|
|
@ -18,8 +18,10 @@ export const AppForm = ({ modalHandler }: Props): JSX.Element => {
|
|||
const { appInUpdate } = useSelector((state: State) => state.apps);
|
||||
|
||||
const dispatch = useDispatch();
|
||||
const { addApp, updateApp, setEditApp, createNotification } =
|
||||
bindActionCreators(actionCreators, dispatch);
|
||||
const { addApp, updateApp, setEditApp } = bindActionCreators(
|
||||
actionCreators,
|
||||
dispatch
|
||||
);
|
||||
|
||||
const [useCustomIcon, toggleUseCustomIcon] = useState<boolean>(false);
|
||||
const [customIcon, setCustomIcon] = useState<File | null>(null);
|
||||
|
@ -56,26 +58,13 @@ export const AppForm = ({ modalHandler }: Props): JSX.Element => {
|
|||
const formSubmitHandler = (e: SyntheticEvent<HTMLFormElement>): void => {
|
||||
e.preventDefault();
|
||||
|
||||
for (let field of ['name', 'url', 'icon'] as const) {
|
||||
if (/^ +$/.test(formData[field])) {
|
||||
createNotification({
|
||||
title: 'Error',
|
||||
message: `Field cannot be empty: ${field}`,
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const createFormData = (): FormData => {
|
||||
const data = new FormData();
|
||||
|
||||
if (customIcon) {
|
||||
data.append('icon', customIcon);
|
||||
}
|
||||
|
||||
data.append('name', formData.name);
|
||||
data.append('description', formData.description);
|
||||
data.append('url', formData.url);
|
||||
data.append('isPublic', `${formData.isPublic ? 1 : 0}`);
|
||||
|
||||
|
@ -107,7 +96,7 @@ export const AppForm = ({ modalHandler }: Props): JSX.Element => {
|
|||
<ModalForm modalHandler={modalHandler} formHandler={formSubmitHandler}>
|
||||
{/* NAME */}
|
||||
<InputGroup>
|
||||
<label htmlFor="name">App name</label>
|
||||
<label htmlFor="name">App Name</label>
|
||||
<input
|
||||
type="text"
|
||||
name="name"
|
||||
|
@ -133,27 +122,11 @@ export const AppForm = ({ modalHandler }: Props): JSX.Element => {
|
|||
/>
|
||||
</InputGroup>
|
||||
|
||||
{/* DESCRIPTION */}
|
||||
<InputGroup>
|
||||
<label htmlFor="description">App description</label>
|
||||
<input
|
||||
type="text"
|
||||
name="description"
|
||||
id="description"
|
||||
placeholder="My self-hosted app"
|
||||
value={formData.description}
|
||||
onChange={(e) => inputChangeHandler(e)}
|
||||
/>
|
||||
<span>
|
||||
Optional - If description is not set, app URL will be displayed
|
||||
</span>
|
||||
</InputGroup>
|
||||
|
||||
{/* ICON */}
|
||||
{!useCustomIcon ? (
|
||||
// use mdi icon
|
||||
<InputGroup>
|
||||
<label htmlFor="icon">App icon</label>
|
||||
<label htmlFor="icon">App Icon</label>
|
||||
<input
|
||||
type="text"
|
||||
name="icon"
|
||||
|
@ -165,7 +138,7 @@ export const AppForm = ({ modalHandler }: Props): JSX.Element => {
|
|||
/>
|
||||
<span>
|
||||
Use icon name from MDI or pass a valid URL.
|
||||
<a href="https://pictogrammers.com/library/mdi/" target="blank">
|
||||
<a href="https://materialdesignicons.com/" target="blank">
|
||||
{' '}
|
||||
Click here for reference
|
||||
</a>
|
||||
|
|
29
client/src/components/Apps/AppTable/AppTable.module.css
Normal file
29
client/src/components/Apps/AppTable/AppTable.module.css
Normal file
|
@ -0,0 +1,29 @@
|
|||
.TableActions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.TableAction {
|
||||
width: 22px;
|
||||
}
|
||||
|
||||
.TableAction:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.Message {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: baseline;
|
||||
color: var(--color-primary);
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.Message a {
|
||||
color: var(--color-accent);
|
||||
}
|
||||
|
||||
.Message a:hover {
|
||||
cursor: pointer;
|
||||
}
|
|
@ -17,7 +17,8 @@ import { actionCreators } from '../../../store';
|
|||
import { App } from '../../../interfaces';
|
||||
|
||||
// Other
|
||||
import { Message, Table } from '../../UI';
|
||||
import classes from './AppTable.module.css';
|
||||
import { Table } from '../../UI';
|
||||
import { TableActions } from '../../Actions/TableActions';
|
||||
|
||||
interface Props {
|
||||
|
@ -88,16 +89,16 @@ export const AppTable = (props: Props): JSX.Element => {
|
|||
|
||||
return (
|
||||
<Fragment>
|
||||
<Message isPrimary={false}>
|
||||
<div className={classes.Message}>
|
||||
{config.useOrdering === 'orderId' ? (
|
||||
<p>You can drag and drop single rows to reorder application</p>
|
||||
) : (
|
||||
<p>
|
||||
Custom order is disabled. You can change it in the{' '}
|
||||
<Link to="/settings/general">settings</Link>
|
||||
<Link to="/settings/interface">settings</Link>
|
||||
</p>
|
||||
)}
|
||||
</Message>
|
||||
</div>
|
||||
|
||||
<DragDropContext onDragEnd={dragEndHanlder}>
|
||||
<Droppable droppableId="apps">
|
||||
|
|
|
@ -22,10 +22,7 @@ interface Props {
|
|||
export const BookmarkCard = (props: Props): JSX.Element => {
|
||||
const { category, fromHomepage = false } = props;
|
||||
|
||||
const {
|
||||
config: { config },
|
||||
auth: { isAuthenticated },
|
||||
} = useSelector((state: State) => state);
|
||||
const { config } = useSelector((state: State) => state.config);
|
||||
|
||||
const dispatch = useDispatch();
|
||||
const { setEditCategory } = bindActionCreators(actionCreators, dispatch);
|
||||
|
@ -33,11 +30,9 @@ export const BookmarkCard = (props: Props): JSX.Element => {
|
|||
return (
|
||||
<div className={classes.BookmarkCard}>
|
||||
<h3
|
||||
className={
|
||||
fromHomepage || !isAuthenticated ? '' : classes.BookmarkHeader
|
||||
}
|
||||
className={fromHomepage ? '' : classes.BookmarkHeader}
|
||||
onClick={() => {
|
||||
if (!fromHomepage && isAuthenticated) {
|
||||
if (!fromHomepage) {
|
||||
setEditCategory(category);
|
||||
}
|
||||
}}
|
||||
|
|
|
@ -14,14 +14,7 @@ import { Category, Bookmark } from '../../interfaces';
|
|||
import classes from './Bookmarks.module.css';
|
||||
|
||||
// UI
|
||||
import {
|
||||
Container,
|
||||
Headline,
|
||||
ActionButton,
|
||||
Spinner,
|
||||
Modal,
|
||||
Message,
|
||||
} from '../UI';
|
||||
import { Container, Headline, ActionButton, Spinner, Modal } from '../UI';
|
||||
|
||||
// Components
|
||||
import { BookmarkGrid } from './BookmarkGrid/BookmarkGrid';
|
||||
|
@ -128,11 +121,6 @@ export const Bookmarks = (props: Props): JSX.Element => {
|
|||
}
|
||||
};
|
||||
|
||||
const finishEditing = () => {
|
||||
setShowTable(false);
|
||||
setEditCategory(null);
|
||||
};
|
||||
|
||||
return (
|
||||
<Container>
|
||||
<Modal isOpen={modalIsOpen} setIsOpen={toggleModal}>
|
||||
|
@ -162,24 +150,14 @@ export const Bookmarks = (props: Props): JSX.Element => {
|
|||
icon="mdiPencil"
|
||||
handler={() => showTableForEditing(ContentType.category)}
|
||||
/>
|
||||
{showTable && tableContentType === ContentType.bookmark && (
|
||||
<ActionButton
|
||||
name="Finish Editing"
|
||||
icon="mdiPencil"
|
||||
handler={finishEditing}
|
||||
/>
|
||||
)}
|
||||
<ActionButton
|
||||
name="Edit Bookmarks"
|
||||
icon="mdiPencil"
|
||||
handler={() => showTableForEditing(ContentType.bookmark)}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{categories.length && isAuthenticated && !showTable ? (
|
||||
<Message isPrimary={false}>
|
||||
Click on category name to edit its bookmarks
|
||||
</Message>
|
||||
) : (
|
||||
<></>
|
||||
)}
|
||||
|
||||
{loading ? (
|
||||
<Spinner />
|
||||
) : !showTable ? (
|
||||
|
|
|
@ -69,17 +69,6 @@ export const BookmarksForm = ({
|
|||
const formSubmitHandler = (e: FormEvent): void => {
|
||||
e.preventDefault();
|
||||
|
||||
for (let field of ['name', 'url', 'icon'] as const) {
|
||||
if (/^ +$/.test(formData[field])) {
|
||||
createNotification({
|
||||
title: 'Error',
|
||||
message: `Field cannot be empty: ${field}`,
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const createFormData = (): FormData => {
|
||||
const data = new FormData();
|
||||
if (customIcon) {
|
||||
|
|
|
@ -15,8 +15,11 @@ import { actionCreators } from '../../../store';
|
|||
// Typescript
|
||||
import { Bookmark, Category } from '../../../interfaces';
|
||||
|
||||
// CSS
|
||||
import classes from './Table.module.css';
|
||||
|
||||
// UI
|
||||
import { Message, Table } from '../../UI';
|
||||
import { Table } from '../../UI';
|
||||
import { TableActions } from '../../Actions/TableActions';
|
||||
import { bookmarkTemplate } from '../../../utility';
|
||||
|
||||
|
@ -105,14 +108,18 @@ export const BookmarksTable = ({ openFormForUpdating }: Props): JSX.Element => {
|
|||
return (
|
||||
<Fragment>
|
||||
{!categoryInEdit ? (
|
||||
<Message isPrimary={false}>
|
||||
Switch to grid view and click on the name of category you want to edit
|
||||
</Message>
|
||||
<div className={classes.Message}>
|
||||
<p>
|
||||
Switch to grid view and click on the name of category you want to
|
||||
edit
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<Message isPrimary={false}>
|
||||
Editing bookmarks from <span>{categoryInEdit.name}</span>
|
||||
category
|
||||
</Message>
|
||||
<div className={classes.Message}>
|
||||
<p>
|
||||
Editing bookmarks from <span>{categoryInEdit.name}</span> category
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{categoryInEdit && (
|
||||
|
|
|
@ -16,8 +16,11 @@ import { actionCreators } from '../../../store';
|
|||
// Typescript
|
||||
import { Bookmark, Category } from '../../../interfaces';
|
||||
|
||||
// CSS
|
||||
import classes from './Table.module.css';
|
||||
|
||||
// UI
|
||||
import { Message, Table } from '../../UI';
|
||||
import { Table } from '../../UI';
|
||||
import { TableActions } from '../../Actions/TableActions';
|
||||
|
||||
interface Props {
|
||||
|
@ -96,16 +99,16 @@ export const CategoryTable = ({ openFormForUpdating }: Props): JSX.Element => {
|
|||
|
||||
return (
|
||||
<Fragment>
|
||||
<Message isPrimary={false}>
|
||||
<div className={classes.Message}>
|
||||
{config.useOrdering === 'orderId' ? (
|
||||
<p>You can drag and drop single rows to reorder categories</p>
|
||||
) : (
|
||||
<p>
|
||||
Custom order is disabled. You can change it in the{' '}
|
||||
<Link to="/settings/general">settings</Link>
|
||||
<Link to="/settings/interface">settings</Link>
|
||||
</p>
|
||||
)}
|
||||
</Message>
|
||||
</div>
|
||||
|
||||
<DragDropContext onDragEnd={dragEndHanlder}>
|
||||
<Droppable droppableId="categories">
|
||||
|
|
17
client/src/components/Bookmarks/Table/Table.module.css
Normal file
17
client/src/components/Bookmarks/Table/Table.module.css
Normal file
|
@ -0,0 +1,17 @@
|
|||
.Message {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: baseline;
|
||||
color: var(--color-primary);
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.Message a,
|
||||
.Message span {
|
||||
color: var(--color-accent);
|
||||
}
|
||||
|
||||
.Message a:hover {
|
||||
cursor: pointer;
|
||||
}
|
|
@ -64,10 +64,8 @@ export const Home = (): JSX.Element => {
|
|||
if (localSearch) {
|
||||
// Search through apps
|
||||
setAppSearchResult([
|
||||
...apps.filter(({ name, description }) =>
|
||||
new RegExp(escapeRegex(localSearch), 'i').test(
|
||||
`${name} ${description}`
|
||||
)
|
||||
...apps.filter(({ name }) =>
|
||||
new RegExp(escapeRegex(localSearch), 'i').test(name)
|
||||
),
|
||||
]);
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
border-bottom: 2px solid var(--color-accent);
|
||||
opacity: 0.5;
|
||||
transition: all 0.2s;
|
||||
border-radius: 0px;
|
||||
}
|
||||
|
||||
.SearchBar:focus {
|
||||
|
|
|
@ -64,22 +64,16 @@ export const SearchBar = (props: Props): JSX.Element => {
|
|||
};
|
||||
|
||||
const searchHandler = (e: KeyboardEvent<HTMLInputElement>) => {
|
||||
const {
|
||||
isLocal,
|
||||
encodedURL,
|
||||
primarySearch,
|
||||
secondarySearch,
|
||||
isURL,
|
||||
sameTab,
|
||||
rawQuery,
|
||||
} = searchParser(inputRef.current.value);
|
||||
const { isLocal, search, query, isURL, sameTab } = searchParser(
|
||||
inputRef.current.value
|
||||
);
|
||||
|
||||
if (isLocal) {
|
||||
setLocalSearch(encodedURL);
|
||||
setLocalSearch(search);
|
||||
}
|
||||
|
||||
if (e.code === 'Enter' || e.code === 'NumpadEnter') {
|
||||
if (!primarySearch.prefix) {
|
||||
if (!query.prefix) {
|
||||
// Prefix not found -> emit notification
|
||||
createNotification({
|
||||
title: 'Error',
|
||||
|
@ -96,21 +90,19 @@ export const SearchBar = (props: Props): JSX.Element => {
|
|||
} else if (bookmarkSearchResult?.[0]?.bookmarks?.length) {
|
||||
redirectUrl(bookmarkSearchResult[0].bookmarks[0].url, sameTab);
|
||||
} else {
|
||||
// no local results -> search the internet with the default search provider if query is not empty
|
||||
if (!/^ *$/.test(rawQuery)) {
|
||||
let template = primarySearch.template;
|
||||
// no local results -> search the internet with the default search provider
|
||||
let template = query.template;
|
||||
|
||||
if (primarySearch.prefix === 'l') {
|
||||
template = secondarySearch.template;
|
||||
}
|
||||
|
||||
const url = `${template}${encodedURL}`;
|
||||
redirectUrl(url, sameTab);
|
||||
if (query.prefix === 'l') {
|
||||
template = 'https://duckduckgo.com/?q=';
|
||||
}
|
||||
|
||||
const url = `${template}${search}`;
|
||||
redirectUrl(url, sameTab);
|
||||
}
|
||||
} else {
|
||||
// Valid query -> redirect to search results
|
||||
const url = `${primarySearch.template}${encodedURL}`;
|
||||
const url = `${query.template}${search}`;
|
||||
redirectUrl(url, sameTab);
|
||||
}
|
||||
} else if (e.code === 'Escape') {
|
||||
|
|
|
@ -1,57 +1,43 @@
|
|||
import { Fragment } from 'react';
|
||||
|
||||
// UI
|
||||
import { Button, SettingsHeadline } from '../../UI';
|
||||
import { AuthForm } from './AuthForm/AuthForm';
|
||||
import classes from './AppDetails.module.css';
|
||||
|
||||
// Store
|
||||
import { useSelector } from 'react-redux';
|
||||
import { State } from '../../../store/reducers';
|
||||
|
||||
// Other
|
||||
import { checkVersion } from '../../../utility';
|
||||
import { AuthForm } from './AuthForm/AuthForm';
|
||||
|
||||
export const AppDetails = (): JSX.Element => {
|
||||
const { isAuthenticated } = useSelector((state: State) => state.auth);
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
<SettingsHeadline text="Authentication" />
|
||||
<AuthForm />
|
||||
|
||||
{isAuthenticated && (
|
||||
<Fragment>
|
||||
<hr className={classes.separator} />
|
||||
<hr className={classes.separator} />
|
||||
|
||||
<div>
|
||||
<SettingsHeadline text="App version" />
|
||||
<p className={classes.text}>
|
||||
<a
|
||||
href="https://github.com/pawelmalak/flame"
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
Flame
|
||||
</a>{' '}
|
||||
version {process.env.REACT_APP_VERSION}
|
||||
</p>
|
||||
<div>
|
||||
<SettingsHeadline text="App version" />
|
||||
<p className={classes.text}>
|
||||
<a
|
||||
href="https://github.com/pawelmalak/flame"
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
Flame
|
||||
</a>{' '}
|
||||
version {process.env.REACT_APP_VERSION}
|
||||
</p>
|
||||
|
||||
<p className={classes.text}>
|
||||
See changelog{' '}
|
||||
<a
|
||||
href="https://github.com/pawelmalak/flame/blob/master/CHANGELOG.md"
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
here
|
||||
</a>
|
||||
</p>
|
||||
<p className={classes.text}>
|
||||
See changelog{' '}
|
||||
<a
|
||||
href="https://github.com/pawelmalak/flame/blob/master/CHANGELOG.md"
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
here
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<Button click={() => checkVersion(true)}>Check for updates</Button>
|
||||
</div>
|
||||
</Fragment>
|
||||
)}
|
||||
<Button click={() => checkVersion(true)}>Check for updates</Button>
|
||||
</div>
|
||||
</Fragment>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -1,242 +0,0 @@
|
|||
// React
|
||||
import { useState, useEffect, FormEvent, ChangeEvent, Fragment } from 'react';
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
|
||||
// Typescript
|
||||
import { Query, GeneralForm } from '../../../interfaces';
|
||||
|
||||
// Components
|
||||
import { CustomQueries } from './CustomQueries/CustomQueries';
|
||||
|
||||
// UI
|
||||
import { Button, SettingsHeadline, InputGroup } from '../../UI';
|
||||
|
||||
// Utils
|
||||
import { inputHandler, generalSettingsTemplate } from '../../../utility';
|
||||
|
||||
// Data
|
||||
import searchQueries from '../../../utility/searchQueries.json';
|
||||
|
||||
// Redux
|
||||
import { State } from '../../../store/reducers';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import { actionCreators } from '../../../store';
|
||||
|
||||
export const GeneralSettings = (): JSX.Element => {
|
||||
const {
|
||||
config: { loading, customQueries, config },
|
||||
bookmarks: { categories },
|
||||
} = useSelector((state: State) => state);
|
||||
|
||||
const dispatch = useDispatch();
|
||||
const { updateConfig, sortApps, sortCategories, sortBookmarks } =
|
||||
bindActionCreators(actionCreators, dispatch);
|
||||
|
||||
const queries = searchQueries.queries;
|
||||
|
||||
// Initial state
|
||||
const [formData, setFormData] = useState<GeneralForm>(
|
||||
generalSettingsTemplate
|
||||
);
|
||||
|
||||
// Get config
|
||||
useEffect(() => {
|
||||
setFormData({
|
||||
...config,
|
||||
});
|
||||
}, [loading]);
|
||||
|
||||
// Form handler
|
||||
const formSubmitHandler = async (e: FormEvent) => {
|
||||
e.preventDefault();
|
||||
|
||||
// Save settings
|
||||
await updateConfig(formData);
|
||||
|
||||
// Sort entities with new settings
|
||||
if (formData.useOrdering !== config.useOrdering) {
|
||||
sortApps();
|
||||
sortCategories();
|
||||
|
||||
for (let { id } of categories) {
|
||||
sortBookmarks(id);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Input handler
|
||||
const inputChangeHandler = (
|
||||
e: ChangeEvent<HTMLInputElement | HTMLSelectElement>,
|
||||
options?: { isNumber?: boolean; isBool?: boolean }
|
||||
) => {
|
||||
inputHandler<GeneralForm>({
|
||||
e,
|
||||
options,
|
||||
setStateHandler: setFormData,
|
||||
state: formData,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
<form
|
||||
onSubmit={(e) => formSubmitHandler(e)}
|
||||
style={{ marginBottom: '30px' }}
|
||||
>
|
||||
{/* === GENERAL OPTIONS === */}
|
||||
<SettingsHeadline text="General" />
|
||||
{/* SORT TYPE */}
|
||||
<InputGroup>
|
||||
<label htmlFor="useOrdering">Sorting type</label>
|
||||
<select
|
||||
id="useOrdering"
|
||||
name="useOrdering"
|
||||
value={formData.useOrdering}
|
||||
onChange={(e) => inputChangeHandler(e)}
|
||||
>
|
||||
<option value="createdAt">By creation date</option>
|
||||
<option value="name">Alphabetical order</option>
|
||||
<option value="orderId">Custom order</option>
|
||||
</select>
|
||||
</InputGroup>
|
||||
|
||||
{/* === APPS OPTIONS === */}
|
||||
<SettingsHeadline text="Apps" />
|
||||
{/* PIN APPS */}
|
||||
<InputGroup>
|
||||
<label htmlFor="pinAppsByDefault">
|
||||
Pin new applications by default
|
||||
</label>
|
||||
<select
|
||||
id="pinAppsByDefault"
|
||||
name="pinAppsByDefault"
|
||||
value={formData.pinAppsByDefault ? 1 : 0}
|
||||
onChange={(e) => inputChangeHandler(e, { isBool: true })}
|
||||
>
|
||||
<option value={1}>True</option>
|
||||
<option value={0}>False</option>
|
||||
</select>
|
||||
</InputGroup>
|
||||
|
||||
{/* APPS OPPENING */}
|
||||
<InputGroup>
|
||||
<label htmlFor="appsSameTab">Open applications in the same tab</label>
|
||||
<select
|
||||
id="appsSameTab"
|
||||
name="appsSameTab"
|
||||
value={formData.appsSameTab ? 1 : 0}
|
||||
onChange={(e) => inputChangeHandler(e, { isBool: true })}
|
||||
>
|
||||
<option value={1}>True</option>
|
||||
<option value={0}>False</option>
|
||||
</select>
|
||||
</InputGroup>
|
||||
|
||||
{/* === BOOKMARKS OPTIONS === */}
|
||||
<SettingsHeadline text="Bookmarks" />
|
||||
{/* PIN CATEGORIES */}
|
||||
<InputGroup>
|
||||
<label htmlFor="pinCategoriesByDefault">
|
||||
Pin new categories by default
|
||||
</label>
|
||||
<select
|
||||
id="pinCategoriesByDefault"
|
||||
name="pinCategoriesByDefault"
|
||||
value={formData.pinCategoriesByDefault ? 1 : 0}
|
||||
onChange={(e) => inputChangeHandler(e, { isBool: true })}
|
||||
>
|
||||
<option value={1}>True</option>
|
||||
<option value={0}>False</option>
|
||||
</select>
|
||||
</InputGroup>
|
||||
|
||||
{/* BOOKMARKS OPPENING */}
|
||||
<InputGroup>
|
||||
<label htmlFor="bookmarksSameTab">
|
||||
Open bookmarks in the same tab
|
||||
</label>
|
||||
<select
|
||||
id="bookmarksSameTab"
|
||||
name="bookmarksSameTab"
|
||||
value={formData.bookmarksSameTab ? 1 : 0}
|
||||
onChange={(e) => inputChangeHandler(e, { isBool: true })}
|
||||
>
|
||||
<option value={1}>True</option>
|
||||
<option value={0}>False</option>
|
||||
</select>
|
||||
</InputGroup>
|
||||
|
||||
{/* === SEARCH OPTIONS === */}
|
||||
<SettingsHeadline text="Search" />
|
||||
<InputGroup>
|
||||
<label htmlFor="defaultSearchProvider">Primary search provider</label>
|
||||
<select
|
||||
id="defaultSearchProvider"
|
||||
name="defaultSearchProvider"
|
||||
value={formData.defaultSearchProvider}
|
||||
onChange={(e) => inputChangeHandler(e)}
|
||||
>
|
||||
{[...queries, ...customQueries].map((query: Query, idx) => {
|
||||
const isCustom = idx >= queries.length;
|
||||
|
||||
return (
|
||||
<option key={idx} value={query.prefix}>
|
||||
{isCustom && '+'} {query.name}
|
||||
</option>
|
||||
);
|
||||
})}
|
||||
</select>
|
||||
</InputGroup>
|
||||
|
||||
{formData.defaultSearchProvider === 'l' && (
|
||||
<InputGroup>
|
||||
<label htmlFor="secondarySearchProvider">
|
||||
Secondary search provider
|
||||
</label>
|
||||
<select
|
||||
id="secondarySearchProvider"
|
||||
name="secondarySearchProvider"
|
||||
value={formData.secondarySearchProvider}
|
||||
onChange={(e) => inputChangeHandler(e)}
|
||||
>
|
||||
{[...queries, ...customQueries].map((query: Query, idx) => {
|
||||
const isCustom = idx >= queries.length;
|
||||
|
||||
return (
|
||||
<option key={idx} value={query.prefix}>
|
||||
{isCustom && '+'} {query.name}
|
||||
</option>
|
||||
);
|
||||
})}
|
||||
</select>
|
||||
<span>
|
||||
Will be used when "Local search" is primary search provider and
|
||||
there are not any local results
|
||||
</span>
|
||||
</InputGroup>
|
||||
)}
|
||||
|
||||
<InputGroup>
|
||||
<label htmlFor="searchSameTab">
|
||||
Open search results in the same tab
|
||||
</label>
|
||||
<select
|
||||
id="searchSameTab"
|
||||
name="searchSameTab"
|
||||
value={formData.searchSameTab ? 1 : 0}
|
||||
onChange={(e) => inputChangeHandler(e, { isBool: true })}
|
||||
>
|
||||
<option value={1}>True</option>
|
||||
<option value={0}>False</option>
|
||||
</select>
|
||||
</InputGroup>
|
||||
|
||||
<Button>Save changes</Button>
|
||||
</form>
|
||||
|
||||
{/* CUSTOM QUERIES */}
|
||||
<SettingsHeadline text="Custom search providers" />
|
||||
<CustomQueries />
|
||||
</Fragment>
|
||||
);
|
||||
};
|
|
@ -0,0 +1,30 @@
|
|||
.QueriesGrid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
}
|
||||
|
||||
.QueriesGrid span {
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.QueriesGrid span:last-child {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.ActionIcons {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.ActionIcons svg {
|
||||
width: 20px;
|
||||
}
|
||||
|
||||
.ActionIcons svg:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.Separator {
|
||||
grid-column: 1 / 4;
|
||||
border-bottom: 1px solid var(--color-primary);
|
||||
margin: 10px 0;
|
||||
}
|
|
@ -9,8 +9,11 @@ import { actionCreators } from '../../../../store';
|
|||
// Typescript
|
||||
import { Query } from '../../../../interfaces';
|
||||
|
||||
// CSS
|
||||
import classes from './CustomQueries.module.css';
|
||||
|
||||
// UI
|
||||
import { Modal, Icon, Button, CompactTable, ActionIcons } from '../../../UI';
|
||||
import { Modal, Icon, Button } from '../../../UI';
|
||||
|
||||
// Components
|
||||
import { QueriesForm } from './QueriesForm';
|
||||
|
@ -64,27 +67,33 @@ export const CustomQueries = (): JSX.Element => {
|
|||
)}
|
||||
</Modal>
|
||||
|
||||
<section>
|
||||
{customQueries.length ? (
|
||||
<CompactTable headers={['Name', 'Prefix', 'Actions']}>
|
||||
{customQueries.map((q: Query, idx) => (
|
||||
<Fragment key={idx}>
|
||||
<span>{q.name}</span>
|
||||
<span>{q.prefix}</span>
|
||||
<ActionIcons>
|
||||
<span onClick={() => updateHandler(q)}>
|
||||
<Icon icon="mdiPencil" />
|
||||
</span>
|
||||
<span onClick={() => deleteHandler(q)}>
|
||||
<Icon icon="mdiDelete" />
|
||||
</span>
|
||||
</ActionIcons>
|
||||
</Fragment>
|
||||
))}
|
||||
</CompactTable>
|
||||
) : (
|
||||
<></>
|
||||
)}
|
||||
<div>
|
||||
<div className={classes.QueriesGrid}>
|
||||
{customQueries.length > 0 && (
|
||||
<Fragment>
|
||||
<span>Name</span>
|
||||
<span>Prefix</span>
|
||||
<span>Actions</span>
|
||||
|
||||
<div className={classes.Separator}></div>
|
||||
</Fragment>
|
||||
)}
|
||||
|
||||
{customQueries.map((q: Query, idx) => (
|
||||
<Fragment key={idx}>
|
||||
<span>{q.name}</span>
|
||||
<span>{q.prefix}</span>
|
||||
<span className={classes.ActionIcons}>
|
||||
<span onClick={() => updateHandler(q)}>
|
||||
<Icon icon="mdiPencil" />
|
||||
</span>
|
||||
<span onClick={() => deleteHandler(q)}>
|
||||
<Icon icon="mdiDelete" />
|
||||
</span>
|
||||
</span>
|
||||
</Fragment>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<Button
|
||||
click={() => {
|
||||
|
@ -94,7 +103,7 @@ export const CustomQueries = (): JSX.Element => {
|
|||
>
|
||||
Add new search provider
|
||||
</Button>
|
||||
</section>
|
||||
</div>
|
||||
</Fragment>
|
||||
);
|
||||
};
|
141
client/src/components/Settings/SearchSettings/SearchSettings.tsx
Normal file
141
client/src/components/Settings/SearchSettings/SearchSettings.tsx
Normal file
|
@ -0,0 +1,141 @@
|
|||
// React
|
||||
import { useState, useEffect, FormEvent, ChangeEvent, Fragment } from 'react';
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
|
||||
// Typescript
|
||||
import { Query, SearchForm } from '../../../interfaces';
|
||||
|
||||
// Components
|
||||
import { CustomQueries } from './CustomQueries/CustomQueries';
|
||||
|
||||
// UI
|
||||
import { Button, SettingsHeadline, InputGroup } from '../../UI';
|
||||
|
||||
// Utils
|
||||
import { inputHandler, searchSettingsTemplate } from '../../../utility';
|
||||
|
||||
// Data
|
||||
import { queries } from '../../../utility/searchQueries.json';
|
||||
|
||||
// Redux
|
||||
import { State } from '../../../store/reducers';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import { actionCreators } from '../../../store';
|
||||
|
||||
export const SearchSettings = (): JSX.Element => {
|
||||
const { loading, customQueries, config } = useSelector(
|
||||
(state: State) => state.config
|
||||
);
|
||||
|
||||
const dispatch = useDispatch();
|
||||
const { updateConfig } = bindActionCreators(actionCreators, dispatch);
|
||||
|
||||
// Initial state
|
||||
const [formData, setFormData] = useState<SearchForm>(searchSettingsTemplate);
|
||||
|
||||
// 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<SearchForm>({
|
||||
e,
|
||||
options,
|
||||
setStateHandler: setFormData,
|
||||
state: formData,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
{/* GENERAL SETTINGS */}
|
||||
<form
|
||||
onSubmit={(e) => formSubmitHandler(e)}
|
||||
style={{ marginBottom: '30px' }}
|
||||
>
|
||||
<SettingsHeadline text="General" />
|
||||
<InputGroup>
|
||||
<label htmlFor="defaultSearchProvider">Default search provider</label>
|
||||
<select
|
||||
id="defaultSearchProvider"
|
||||
name="defaultSearchProvider"
|
||||
value={formData.defaultSearchProvider}
|
||||
onChange={(e) => inputChangeHandler(e)}
|
||||
>
|
||||
{[...queries, ...customQueries].map((query: Query, idx) => {
|
||||
const isCustom = idx >= queries.length;
|
||||
|
||||
return (
|
||||
<option key={idx} value={query.prefix}>
|
||||
{isCustom && '+'} {query.name}
|
||||
</option>
|
||||
);
|
||||
})}
|
||||
</select>
|
||||
</InputGroup>
|
||||
|
||||
<InputGroup>
|
||||
<label htmlFor="searchSameTab">
|
||||
Open search results in the same tab
|
||||
</label>
|
||||
<select
|
||||
id="searchSameTab"
|
||||
name="searchSameTab"
|
||||
value={formData.searchSameTab ? 1 : 0}
|
||||
onChange={(e) => inputChangeHandler(e, { isBool: true })}
|
||||
>
|
||||
<option value={1}>True</option>
|
||||
<option value={0}>False</option>
|
||||
</select>
|
||||
</InputGroup>
|
||||
|
||||
<InputGroup>
|
||||
<label htmlFor="hideSearch">Hide search bar</label>
|
||||
<select
|
||||
id="hideSearch"
|
||||
name="hideSearch"
|
||||
value={formData.hideSearch ? 1 : 0}
|
||||
onChange={(e) => inputChangeHandler(e, { isBool: true })}
|
||||
>
|
||||
<option value={1}>True</option>
|
||||
<option value={0}>False</option>
|
||||
</select>
|
||||
</InputGroup>
|
||||
|
||||
<InputGroup>
|
||||
<label htmlFor="disableAutofocus">Disable search bar autofocus</label>
|
||||
<select
|
||||
id="disableAutofocus"
|
||||
name="disableAutofocus"
|
||||
value={formData.disableAutofocus ? 1 : 0}
|
||||
onChange={(e) => inputChangeHandler(e, { isBool: true })}
|
||||
>
|
||||
<option value={1}>True</option>
|
||||
<option value={0}>False</option>
|
||||
</select>
|
||||
</InputGroup>
|
||||
|
||||
<Button>Save changes</Button>
|
||||
</form>
|
||||
|
||||
{/* CUSTOM QUERIES */}
|
||||
<SettingsHeadline text="Custom search providers" />
|
||||
<CustomQueries />
|
||||
</Fragment>
|
||||
);
|
||||
};
|
|
@ -16,7 +16,7 @@ import { WeatherSettings } from './WeatherSettings/WeatherSettings';
|
|||
import { UISettings } from './UISettings/UISettings';
|
||||
import { AppDetails } from './AppDetails/AppDetails';
|
||||
import { StyleSettings } from './StyleSettings/StyleSettings';
|
||||
import { GeneralSettings } from './GeneralSettings/GeneralSettings';
|
||||
import { SearchSettings } from './SearchSettings/SearchSettings';
|
||||
import { DockerSettings } from './DockerSettings/DockerSettings';
|
||||
import { ProtectedRoute } from '../Routing/ProtectedRoute';
|
||||
|
||||
|
@ -24,11 +24,9 @@ import { ProtectedRoute } from '../Routing/ProtectedRoute';
|
|||
import { Container, Headline } from '../UI';
|
||||
|
||||
// Data
|
||||
import clientRoutes from './settings.json';
|
||||
import { routes } from './settings.json';
|
||||
|
||||
export const Settings = (): JSX.Element => {
|
||||
const routes = clientRoutes.routes;
|
||||
|
||||
const { isAuthenticated } = useSelector((state: State) => state.auth);
|
||||
|
||||
const tabs = isAuthenticated ? routes : routes.filter((r) => !r.authRequired);
|
||||
|
@ -61,8 +59,8 @@ export const Settings = (): JSX.Element => {
|
|||
component={WeatherSettings}
|
||||
/>
|
||||
<ProtectedRoute
|
||||
path="/settings/general"
|
||||
component={GeneralSettings}
|
||||
path="/settings/search"
|
||||
component={SearchSettings}
|
||||
/>
|
||||
<ProtectedRoute path="/settings/interface" component={UISettings} />
|
||||
<ProtectedRoute
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
.ThemeBuilder {
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.Buttons button:not(:last-child) {
|
||||
margin-right: 10px;
|
||||
}
|
|
@ -1,95 +0,0 @@
|
|||
import { useState, useEffect } from 'react';
|
||||
|
||||
// Redux
|
||||
import { useSelector, useDispatch } from 'react-redux';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import { actionCreators } from '../../../../store';
|
||||
import { State } from '../../../../store/reducers';
|
||||
|
||||
// Other
|
||||
import { Theme } from '../../../../interfaces';
|
||||
|
||||
// UI
|
||||
import { Button, Modal } from '../../../UI';
|
||||
import { ThemeGrid } from '../ThemeGrid/ThemeGrid';
|
||||
import classes from './ThemeBuilder.module.css';
|
||||
import { ThemeCreator } from './ThemeCreator';
|
||||
import { ThemeEditor } from './ThemeEditor';
|
||||
|
||||
interface Props {
|
||||
themes: Theme[];
|
||||
}
|
||||
|
||||
export const ThemeBuilder = ({ themes }: Props): JSX.Element => {
|
||||
const {
|
||||
auth: { isAuthenticated },
|
||||
theme: { themeInEdit, userThemes },
|
||||
} = useSelector((state: State) => state);
|
||||
|
||||
const { editTheme } = bindActionCreators(actionCreators, useDispatch());
|
||||
|
||||
const [showModal, toggleShowModal] = useState(false);
|
||||
const [isInEdit, toggleIsInEdit] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (themeInEdit) {
|
||||
toggleIsInEdit(false);
|
||||
toggleShowModal(true);
|
||||
}
|
||||
}, [themeInEdit]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isInEdit && !userThemes.length) {
|
||||
toggleIsInEdit(false);
|
||||
toggleShowModal(false);
|
||||
}
|
||||
}, [userThemes]);
|
||||
|
||||
return (
|
||||
<div className={classes.ThemeBuilder}>
|
||||
{/* MODALS */}
|
||||
<Modal
|
||||
isOpen={showModal}
|
||||
setIsOpen={() => toggleShowModal(!showModal)}
|
||||
cb={() => editTheme(null)}
|
||||
>
|
||||
{isInEdit ? (
|
||||
<ThemeEditor modalHandler={() => toggleShowModal(!showModal)} />
|
||||
) : (
|
||||
<ThemeCreator modalHandler={() => toggleShowModal(!showModal)} />
|
||||
)}
|
||||
</Modal>
|
||||
|
||||
{/* USER THEMES */}
|
||||
<ThemeGrid themes={themes} />
|
||||
|
||||
{/* BUTTONS */}
|
||||
{isAuthenticated && (
|
||||
<div className={classes.Buttons}>
|
||||
<Button
|
||||
click={() => {
|
||||
editTheme(null);
|
||||
toggleIsInEdit(false);
|
||||
toggleShowModal(!showModal);
|
||||
}}
|
||||
>
|
||||
Create new theme
|
||||
</Button>
|
||||
|
||||
{themes.length ? (
|
||||
<Button
|
||||
click={() => {
|
||||
toggleIsInEdit(true);
|
||||
toggleShowModal(!showModal);
|
||||
}}
|
||||
>
|
||||
Edit user themes
|
||||
</Button>
|
||||
) : (
|
||||
<></>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
|
@ -1,5 +0,0 @@
|
|||
.ColorsContainer {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
grid-gap: 10px;
|
||||
}
|
|
@ -1,152 +0,0 @@
|
|||
import { ChangeEvent, FormEvent, useState, useEffect } from 'react';
|
||||
|
||||
// Redux
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import { actionCreators } from '../../../../store';
|
||||
import { State } from '../../../../store/reducers';
|
||||
|
||||
// UI
|
||||
import { Button, InputGroup, ModalForm } from '../../../UI';
|
||||
import classes from './ThemeCreator.module.css';
|
||||
|
||||
// Other
|
||||
import { Theme } from '../../../../interfaces';
|
||||
|
||||
interface Props {
|
||||
modalHandler: () => void;
|
||||
}
|
||||
|
||||
export const ThemeCreator = ({ modalHandler }: Props): JSX.Element => {
|
||||
const {
|
||||
theme: { activeTheme, themeInEdit },
|
||||
} = useSelector((state: State) => state);
|
||||
|
||||
const { addTheme, updateTheme, editTheme } = bindActionCreators(
|
||||
actionCreators,
|
||||
useDispatch()
|
||||
);
|
||||
|
||||
const [formData, setFormData] = useState<Theme>({
|
||||
name: '',
|
||||
isCustom: true,
|
||||
colors: {
|
||||
primary: '#ffffff',
|
||||
accent: '#ffffff',
|
||||
background: '#ffffff',
|
||||
},
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
setFormData({ ...formData, colors: activeTheme.colors });
|
||||
}, [activeTheme]);
|
||||
|
||||
useEffect(() => {
|
||||
if (themeInEdit) {
|
||||
setFormData(themeInEdit);
|
||||
}
|
||||
}, [themeInEdit]);
|
||||
|
||||
const inputChangeHandler = (e: ChangeEvent<HTMLInputElement>) => {
|
||||
const { name, value } = e.target;
|
||||
|
||||
setFormData({
|
||||
...formData,
|
||||
[name]: value,
|
||||
});
|
||||
};
|
||||
|
||||
const setColor = ({
|
||||
target: { value, name },
|
||||
}: ChangeEvent<HTMLInputElement>) => {
|
||||
setFormData({
|
||||
...formData,
|
||||
colors: {
|
||||
...formData.colors,
|
||||
[name]: value,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const closeModal = () => {
|
||||
editTheme(null);
|
||||
modalHandler();
|
||||
};
|
||||
|
||||
const formHandler = (e: FormEvent) => {
|
||||
e.preventDefault();
|
||||
|
||||
if (!themeInEdit) {
|
||||
addTheme(formData);
|
||||
} else {
|
||||
updateTheme(formData, themeInEdit.name);
|
||||
}
|
||||
|
||||
// close modal
|
||||
closeModal();
|
||||
|
||||
// clear theme name
|
||||
setFormData({ ...formData, name: '' });
|
||||
};
|
||||
|
||||
return (
|
||||
<ModalForm formHandler={formHandler} modalHandler={closeModal}>
|
||||
<InputGroup>
|
||||
<label htmlFor="name">Theme name</label>
|
||||
<input
|
||||
type="text"
|
||||
name="name"
|
||||
id="name"
|
||||
placeholder="my_theme"
|
||||
required
|
||||
value={formData.name}
|
||||
onChange={(e) => inputChangeHandler(e)}
|
||||
/>
|
||||
</InputGroup>
|
||||
|
||||
<div className={classes.ColorsContainer}>
|
||||
<InputGroup>
|
||||
<label htmlFor="primary">Primary color</label>
|
||||
<input
|
||||
type="color"
|
||||
name="primary"
|
||||
id="primary"
|
||||
required
|
||||
value={formData.colors.primary}
|
||||
onChange={(e) => setColor(e)}
|
||||
/>
|
||||
</InputGroup>
|
||||
|
||||
<InputGroup>
|
||||
<label htmlFor="accent">Accent color</label>
|
||||
<input
|
||||
type="color"
|
||||
name="accent"
|
||||
id="accent"
|
||||
required
|
||||
value={formData.colors.accent}
|
||||
onChange={(e) => setColor(e)}
|
||||
/>
|
||||
</InputGroup>
|
||||
|
||||
<InputGroup>
|
||||
<label htmlFor="background">Background color</label>
|
||||
<input
|
||||
type="color"
|
||||
name="background"
|
||||
id="background"
|
||||
required
|
||||
value={formData.colors.background}
|
||||
onChange={(e) => setColor(e)}
|
||||
/>
|
||||
</InputGroup>
|
||||
</div>
|
||||
|
||||
{!themeInEdit ? (
|
||||
<Button>Add theme</Button>
|
||||
) : (
|
||||
<Button>Update theme</Button>
|
||||
)}
|
||||
</ModalForm>
|
||||
);
|
||||
};
|
|
@ -1,57 +0,0 @@
|
|||
import { Fragment } from 'react';
|
||||
|
||||
// Redux
|
||||
import { useSelector, useDispatch } from 'react-redux';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import { Theme } from '../../../../interfaces';
|
||||
import { actionCreators } from '../../../../store';
|
||||
import { State } from '../../../../store/reducers';
|
||||
|
||||
// Other
|
||||
import { ActionIcons, CompactTable, Icon, ModalForm } from '../../../UI';
|
||||
|
||||
interface Props {
|
||||
modalHandler: () => void;
|
||||
}
|
||||
|
||||
export const ThemeEditor = (props: Props): JSX.Element => {
|
||||
const {
|
||||
theme: { userThemes },
|
||||
} = useSelector((state: State) => state);
|
||||
|
||||
const { deleteTheme, editTheme } = bindActionCreators(
|
||||
actionCreators,
|
||||
useDispatch()
|
||||
);
|
||||
|
||||
const updateHandler = (theme: Theme) => {
|
||||
props.modalHandler();
|
||||
editTheme(theme);
|
||||
};
|
||||
|
||||
const deleteHandler = (theme: Theme) => {
|
||||
if (window.confirm(`Are you sure you want to delete this theme?`)) {
|
||||
deleteTheme(theme.name);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<ModalForm formHandler={() => {}} modalHandler={props.modalHandler}>
|
||||
<CompactTable headers={['Name', 'Actions']}>
|
||||
{userThemes.map((t, idx) => (
|
||||
<Fragment key={idx}>
|
||||
<span>{t.name}</span>
|
||||
<ActionIcons>
|
||||
<span onClick={() => updateHandler(t)}>
|
||||
<Icon icon="mdiPencil" />
|
||||
</span>
|
||||
<span onClick={() => deleteHandler(t)}>
|
||||
<Icon icon="mdiDelete" />
|
||||
</span>
|
||||
</ActionIcons>
|
||||
</Fragment>
|
||||
))}
|
||||
</CompactTable>
|
||||
</ModalForm>
|
||||
);
|
||||
};
|
|
@ -1,22 +0,0 @@
|
|||
// Components
|
||||
import { ThemePreview } from '../ThemePreview/ThemePreview';
|
||||
|
||||
// Other
|
||||
import { Theme } from '../../../../interfaces';
|
||||
import classes from './ThemeGrid.module.css';
|
||||
|
||||
interface Props {
|
||||
themes: Theme[];
|
||||
}
|
||||
|
||||
export const ThemeGrid = ({ themes }: Props): JSX.Element => {
|
||||
return (
|
||||
<div className={classes.ThemerGrid}>
|
||||
{themes.map(
|
||||
(theme: Theme, idx: number): JSX.Element => (
|
||||
<ThemePreview key={idx} theme={theme} />
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
32
client/src/components/Settings/Themer/ThemePreview.tsx
Normal file
32
client/src/components/Settings/Themer/ThemePreview.tsx
Normal file
|
@ -0,0 +1,32 @@
|
|||
import { Theme } from '../../../interfaces/Theme';
|
||||
import classes from './ThemePreview.module.css';
|
||||
|
||||
interface Props {
|
||||
theme: Theme;
|
||||
applyTheme: Function;
|
||||
}
|
||||
|
||||
export const ThemePreview = (props: Props): JSX.Element => {
|
||||
return (
|
||||
<div
|
||||
className={classes.ThemePreview}
|
||||
onClick={() => props.applyTheme(props.theme.name)}
|
||||
>
|
||||
<div className={classes.ColorsPreview}>
|
||||
<div
|
||||
className={classes.ColorPreview}
|
||||
style={{ backgroundColor: props.theme.colors.background }}
|
||||
></div>
|
||||
<div
|
||||
className={classes.ColorPreview}
|
||||
style={{ backgroundColor: props.theme.colors.primary }}
|
||||
></div>
|
||||
<div
|
||||
className={classes.ColorPreview}
|
||||
style={{ backgroundColor: props.theme.colors.accent }}
|
||||
></div>
|
||||
</div>
|
||||
<p>{props.theme.name}</p>
|
||||
</div>
|
||||
);
|
||||
};
|
|
@ -1,38 +0,0 @@
|
|||
// Redux
|
||||
import { useDispatch } from 'react-redux';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import { actionCreators } from '../../../../store';
|
||||
|
||||
// Other
|
||||
import { Theme } from '../../../../interfaces/Theme';
|
||||
import classes from './ThemePreview.module.css';
|
||||
|
||||
interface Props {
|
||||
theme: Theme;
|
||||
}
|
||||
|
||||
export const ThemePreview = ({
|
||||
theme: { colors, name },
|
||||
}: Props): JSX.Element => {
|
||||
const { setTheme } = bindActionCreators(actionCreators, useDispatch());
|
||||
|
||||
return (
|
||||
<div className={classes.ThemePreview} onClick={() => setTheme(colors)}>
|
||||
<div className={classes.ColorsPreview}>
|
||||
<div
|
||||
className={classes.ColorPreview}
|
||||
style={{ backgroundColor: colors.background }}
|
||||
></div>
|
||||
<div
|
||||
className={classes.ColorPreview}
|
||||
style={{ backgroundColor: colors.primary }}
|
||||
></div>
|
||||
<div
|
||||
className={classes.ColorPreview}
|
||||
style={{ backgroundColor: colors.accent }}
|
||||
></div>
|
||||
</div>
|
||||
<p>{name}</p>
|
||||
</div>
|
||||
);
|
||||
};
|
|
@ -15,4 +15,4 @@
|
|||
.ThemerGrid {
|
||||
grid-template-columns: 1fr 1fr 1fr;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,32 +4,31 @@ import { ChangeEvent, FormEvent, Fragment, useEffect, useState } from 'react';
|
|||
import { useDispatch, useSelector } from 'react-redux';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import { actionCreators } from '../../../store';
|
||||
import { State } from '../../../store/reducers';
|
||||
|
||||
// Typescript
|
||||
import { Theme, ThemeSettingsForm } from '../../../interfaces';
|
||||
|
||||
// Components
|
||||
import { Button, InputGroup, SettingsHeadline, Spinner } from '../../UI';
|
||||
import { ThemeBuilder } from './ThemeBuilder/ThemeBuilder';
|
||||
import { ThemeGrid } from './ThemeGrid/ThemeGrid';
|
||||
import { ThemePreview } from './ThemePreview';
|
||||
import { Button, InputGroup, SettingsHeadline } from '../../UI';
|
||||
|
||||
// Other
|
||||
import {
|
||||
inputHandler,
|
||||
parseThemeToPAB,
|
||||
themeSettingsTemplate,
|
||||
} from '../../../utility';
|
||||
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 },
|
||||
theme: { themes, userThemes },
|
||||
} = useSelector((state: State) => state);
|
||||
|
||||
const dispatch = useDispatch();
|
||||
const { updateConfig } = bindActionCreators(actionCreators, dispatch);
|
||||
const { setTheme, updateConfig } = bindActionCreators(
|
||||
actionCreators,
|
||||
dispatch
|
||||
);
|
||||
|
||||
// Initial state
|
||||
const [formData, setFormData] = useState<ThemeSettingsForm>(
|
||||
|
@ -48,7 +47,7 @@ export const Themer = (): JSX.Element => {
|
|||
e.preventDefault();
|
||||
|
||||
// Save settings
|
||||
await updateConfig({ ...formData });
|
||||
await updateConfig(formData);
|
||||
};
|
||||
|
||||
// Input handler
|
||||
|
@ -64,34 +63,31 @@ export const Themer = (): JSX.Element => {
|
|||
});
|
||||
};
|
||||
|
||||
const customThemesEl = (
|
||||
<Fragment>
|
||||
<SettingsHeadline text="User themes" />
|
||||
<ThemeBuilder themes={userThemes} />
|
||||
</Fragment>
|
||||
);
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
<SettingsHeadline text="App themes" />
|
||||
{!themes.length ? <Spinner /> : <ThemeGrid themes={themes} />}
|
||||
|
||||
{!userThemes.length ? isAuthenticated && customThemesEl : customThemesEl}
|
||||
<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>
|
||||
<label htmlFor="defaultTheme">Default theme (for new users)</label>
|
||||
<select
|
||||
id="defaultTheme"
|
||||
name="defaultTheme"
|
||||
value={formData.defaultTheme}
|
||||
onChange={(e) => inputChangeHandler(e)}
|
||||
>
|
||||
{[...themes, ...userThemes].map((theme: Theme, idx) => (
|
||||
<option key={idx} value={parseThemeToPAB(theme.colors)}>
|
||||
{theme.isCustom && '+'} {theme.name}
|
||||
{themes.map((theme: Theme, idx) => (
|
||||
<option key={idx} value={theme.name}>
|
||||
{theme.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
|
|
|
@ -6,8 +6,7 @@
|
|||
"background": "#1a1a1a",
|
||||
"primary": "#FFFDEA",
|
||||
"accent": "#5c5c5c"
|
||||
},
|
||||
"isCustom": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "gazette",
|
||||
|
@ -15,8 +14,7 @@
|
|||
"background": "#F2F7FF",
|
||||
"primary": "#000000",
|
||||
"accent": "#5c5c5c"
|
||||
},
|
||||
"isCustom": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "espresso",
|
||||
|
@ -24,8 +22,7 @@
|
|||
"background": "#21211F",
|
||||
"primary": "#D1B59A",
|
||||
"accent": "#4E4E4E"
|
||||
},
|
||||
"isCustom": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "cab",
|
||||
|
@ -33,8 +30,7 @@
|
|||
"background": "#F6D305",
|
||||
"primary": "#1F1F1F",
|
||||
"accent": "#424242"
|
||||
},
|
||||
"isCustom": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "cloud",
|
||||
|
@ -42,8 +38,7 @@
|
|||
"background": "#f1f2f0",
|
||||
"primary": "#35342f",
|
||||
"accent": "#37bbe4"
|
||||
},
|
||||
"isCustom": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "lime",
|
||||
|
@ -51,8 +46,7 @@
|
|||
"background": "#263238",
|
||||
"primary": "#AABBC3",
|
||||
"accent": "#aeea00"
|
||||
},
|
||||
"isCustom": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "white",
|
||||
|
@ -60,8 +54,7 @@
|
|||
"background": "#ffffff",
|
||||
"primary": "#222222",
|
||||
"accent": "#dddddd"
|
||||
},
|
||||
"isCustom": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "tron",
|
||||
|
@ -69,8 +62,7 @@
|
|||
"background": "#242B33",
|
||||
"primary": "#EFFBFF",
|
||||
"accent": "#6EE2FF"
|
||||
},
|
||||
"isCustom": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "blues",
|
||||
|
@ -78,8 +70,7 @@
|
|||
"background": "#2B2C56",
|
||||
"primary": "#EFF1FC",
|
||||
"accent": "#6677EB"
|
||||
},
|
||||
"isCustom": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "passion",
|
||||
|
@ -87,8 +78,7 @@
|
|||
"background": "#f5f5f5",
|
||||
"primary": "#12005e",
|
||||
"accent": "#8e24aa"
|
||||
},
|
||||
"isCustom": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "chalk",
|
||||
|
@ -96,8 +86,7 @@
|
|||
"background": "#263238",
|
||||
"primary": "#AABBC3",
|
||||
"accent": "#FF869A"
|
||||
},
|
||||
"isCustom": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "paper",
|
||||
|
@ -105,8 +94,7 @@
|
|||
"background": "#F8F6F1",
|
||||
"primary": "#4C432E",
|
||||
"accent": "#AA9A73"
|
||||
},
|
||||
"isCustom": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "neon",
|
||||
|
@ -114,8 +102,7 @@
|
|||
"background": "#091833",
|
||||
"primary": "#EFFBFF",
|
||||
"accent": "#ea00d9"
|
||||
},
|
||||
"isCustom": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "pumpkin",
|
||||
|
@ -123,8 +110,7 @@
|
|||
"background": "#2d3436",
|
||||
"primary": "#EFFBFF",
|
||||
"accent": "#ffa500"
|
||||
},
|
||||
"isCustom": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "onedark",
|
||||
|
@ -132,17 +118,7 @@
|
|||
"background": "#282c34",
|
||||
"primary": "#dfd9d6",
|
||||
"accent": "#98c379"
|
||||
},
|
||||
"isCustom": false
|
||||
},
|
||||
{
|
||||
"name": "mint",
|
||||
"colors": {
|
||||
"background": "#282525",
|
||||
"primary": "#d9d9d9",
|
||||
"accent": "#50fbc2"
|
||||
},
|
||||
"isCustom": false
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -7,22 +7,28 @@ import { bindActionCreators } from 'redux';
|
|||
import { actionCreators } from '../../../store';
|
||||
|
||||
// Typescript
|
||||
import { UISettingsForm } from '../../../interfaces';
|
||||
import { OtherSettingsForm } from '../../../interfaces';
|
||||
|
||||
// UI
|
||||
import { InputGroup, Button, SettingsHeadline } from '../../UI';
|
||||
|
||||
// Utils
|
||||
import { uiSettingsTemplate, inputHandler } from '../../../utility';
|
||||
import { otherSettingsTemplate, inputHandler } from '../../../utility';
|
||||
|
||||
export const UISettings = (): JSX.Element => {
|
||||
const { loading, config } = useSelector((state: State) => state.config);
|
||||
const {
|
||||
config: { loading, config },
|
||||
bookmarks: { categories },
|
||||
} = useSelector((state: State) => state);
|
||||
|
||||
const dispatch = useDispatch();
|
||||
const { updateConfig } = bindActionCreators(actionCreators, dispatch);
|
||||
const { updateConfig, sortApps, sortCategories, sortBookmarks } =
|
||||
bindActionCreators(actionCreators, dispatch);
|
||||
|
||||
// Initial state
|
||||
const [formData, setFormData] = useState<UISettingsForm>(uiSettingsTemplate);
|
||||
const [formData, setFormData] = useState<OtherSettingsForm>(
|
||||
otherSettingsTemplate
|
||||
);
|
||||
|
||||
// Get config
|
||||
useEffect(() => {
|
||||
|
@ -40,6 +46,16 @@ export const UISettings = (): JSX.Element => {
|
|||
|
||||
// Update local page title
|
||||
document.title = formData.customTitle;
|
||||
|
||||
// Sort entities with new settings
|
||||
if (formData.useOrdering !== config.useOrdering) {
|
||||
sortApps();
|
||||
sortCategories();
|
||||
|
||||
for (let { id } of categories) {
|
||||
sortBookmarks(id);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Input handler
|
||||
|
@ -47,7 +63,7 @@ export const UISettings = (): JSX.Element => {
|
|||
e: ChangeEvent<HTMLInputElement | HTMLSelectElement>,
|
||||
options?: { isNumber?: boolean; isBool?: boolean }
|
||||
) => {
|
||||
inputHandler<UISettingsForm>({
|
||||
inputHandler<OtherSettingsForm>({
|
||||
e,
|
||||
options,
|
||||
setStateHandler: setFormData,
|
||||
|
@ -72,36 +88,6 @@ export const UISettings = (): JSX.Element => {
|
|||
/>
|
||||
</InputGroup>
|
||||
|
||||
{/* === SEARCH OPTIONS === */}
|
||||
<SettingsHeadline text="Search" />
|
||||
{/* HIDE SEARCHBAR */}
|
||||
<InputGroup>
|
||||
<label htmlFor="hideSearch">Hide search bar</label>
|
||||
<select
|
||||
id="hideSearch"
|
||||
name="hideSearch"
|
||||
value={formData.hideSearch ? 1 : 0}
|
||||
onChange={(e) => inputChangeHandler(e, { isBool: true })}
|
||||
>
|
||||
<option value={1}>True</option>
|
||||
<option value={0}>False</option>
|
||||
</select>
|
||||
</InputGroup>
|
||||
|
||||
{/* AUTOFOCUS SEARCHBAR */}
|
||||
<InputGroup>
|
||||
<label htmlFor="disableAutofocus">Disable search bar autofocus</label>
|
||||
<select
|
||||
id="disableAutofocus"
|
||||
name="disableAutofocus"
|
||||
value={formData.disableAutofocus ? 1 : 0}
|
||||
onChange={(e) => inputChangeHandler(e, { isBool: true })}
|
||||
>
|
||||
<option value={1}>True</option>
|
||||
<option value={0}>False</option>
|
||||
</select>
|
||||
</InputGroup>
|
||||
|
||||
{/* === HEADER OPTIONS === */}
|
||||
<SettingsHeadline text="Header" />
|
||||
{/* HIDE HEADER */}
|
||||
|
@ -174,8 +160,8 @@ export const UISettings = (): JSX.Element => {
|
|||
onChange={(e) => inputChangeHandler(e)}
|
||||
/>
|
||||
<span>
|
||||
Greetings must be separated with semicolon. All 4 messages must be
|
||||
filled, even if they are the same
|
||||
Greetings must be separated with semicolon. Only 4 messages can be
|
||||
used
|
||||
</span>
|
||||
</InputGroup>
|
||||
|
||||
|
@ -207,8 +193,85 @@ export const UISettings = (): JSX.Element => {
|
|||
<span>Names must be separated with semicolon</span>
|
||||
</InputGroup>
|
||||
|
||||
{/* === SECTIONS OPTIONS === */}
|
||||
<SettingsHeadline text="Sections" />
|
||||
{/* === BEAHVIOR OPTIONS === */}
|
||||
<SettingsHeadline text="App Behavior" />
|
||||
{/* PIN APPS */}
|
||||
<InputGroup>
|
||||
<label htmlFor="pinAppsByDefault">
|
||||
Pin new applications by default
|
||||
</label>
|
||||
<select
|
||||
id="pinAppsByDefault"
|
||||
name="pinAppsByDefault"
|
||||
value={formData.pinAppsByDefault ? 1 : 0}
|
||||
onChange={(e) => inputChangeHandler(e, { isBool: true })}
|
||||
>
|
||||
<option value={1}>True</option>
|
||||
<option value={0}>False</option>
|
||||
</select>
|
||||
</InputGroup>
|
||||
|
||||
{/* PIN CATEGORIES */}
|
||||
<InputGroup>
|
||||
<label htmlFor="pinCategoriesByDefault">
|
||||
Pin new categories by default
|
||||
</label>
|
||||
<select
|
||||
id="pinCategoriesByDefault"
|
||||
name="pinCategoriesByDefault"
|
||||
value={formData.pinCategoriesByDefault ? 1 : 0}
|
||||
onChange={(e) => inputChangeHandler(e, { isBool: true })}
|
||||
>
|
||||
<option value={1}>True</option>
|
||||
<option value={0}>False</option>
|
||||
</select>
|
||||
</InputGroup>
|
||||
|
||||
{/* SORT TYPE */}
|
||||
<InputGroup>
|
||||
<label htmlFor="useOrdering">Sorting type</label>
|
||||
<select
|
||||
id="useOrdering"
|
||||
name="useOrdering"
|
||||
value={formData.useOrdering}
|
||||
onChange={(e) => inputChangeHandler(e)}
|
||||
>
|
||||
<option value="createdAt">By creation date</option>
|
||||
<option value="name">Alphabetical order</option>
|
||||
<option value="orderId">Custom order</option>
|
||||
</select>
|
||||
</InputGroup>
|
||||
|
||||
{/* APPS OPPENING */}
|
||||
<InputGroup>
|
||||
<label htmlFor="appsSameTab">Open applications in the same tab</label>
|
||||
<select
|
||||
id="appsSameTab"
|
||||
name="appsSameTab"
|
||||
value={formData.appsSameTab ? 1 : 0}
|
||||
onChange={(e) => inputChangeHandler(e, { isBool: true })}
|
||||
>
|
||||
<option value={1}>True</option>
|
||||
<option value={0}>False</option>
|
||||
</select>
|
||||
</InputGroup>
|
||||
|
||||
{/* BOOKMARKS OPPENING */}
|
||||
<InputGroup>
|
||||
<label htmlFor="bookmarksSameTab">Open bookmarks in the same tab</label>
|
||||
<select
|
||||
id="bookmarksSameTab"
|
||||
name="bookmarksSameTab"
|
||||
value={formData.bookmarksSameTab ? 1 : 0}
|
||||
onChange={(e) => inputChangeHandler(e, { isBool: true })}
|
||||
>
|
||||
<option value={1}>True</option>
|
||||
<option value={0}>False</option>
|
||||
</select>
|
||||
</InputGroup>
|
||||
|
||||
{/* === MODULES OPTIONS === */}
|
||||
<SettingsHeadline text="Modules" />
|
||||
{/* HIDE APPS */}
|
||||
<InputGroup>
|
||||
<label htmlFor="hideApps">Hide applications</label>
|
||||
|
@ -223,9 +286,9 @@ export const UISettings = (): JSX.Element => {
|
|||
</select>
|
||||
</InputGroup>
|
||||
|
||||
{/* HIDE BOOKMARK CATEGORIES */}
|
||||
{/* HIDE CATEGORIES */}
|
||||
<InputGroup>
|
||||
<label htmlFor="hideCategories">Hide bookmarks</label>
|
||||
<label htmlFor="hideCategories">Hide categories</label>
|
||||
<select
|
||||
id="hideCategories"
|
||||
name="hideCategories"
|
||||
|
|
|
@ -82,19 +82,6 @@ export const WeatherSettings = (): JSX.Element => {
|
|||
});
|
||||
};
|
||||
|
||||
// Get user location
|
||||
const getLocation = () => {
|
||||
window.navigator.geolocation.getCurrentPosition(
|
||||
({ coords: { latitude, longitude } }) => {
|
||||
setFormData({
|
||||
...formData,
|
||||
lat: latitude,
|
||||
long: longitude,
|
||||
});
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<form onSubmit={(e) => formSubmitHandler(e)}>
|
||||
<SettingsHeadline text="API" />
|
||||
|
@ -133,8 +120,15 @@ export const WeatherSettings = (): JSX.Element => {
|
|||
step="any"
|
||||
lang="en-150"
|
||||
/>
|
||||
<span onClick={getLocation}>
|
||||
<a href="#">Click to get current location</a>
|
||||
<span>
|
||||
You can use
|
||||
<a
|
||||
href="https://www.latlong.net/convert-address-to-lat-long.html"
|
||||
target="blank"
|
||||
>
|
||||
{' '}
|
||||
latlong.net
|
||||
</a>
|
||||
</span>
|
||||
</InputGroup>
|
||||
|
||||
|
|
|
@ -6,8 +6,13 @@
|
|||
"authRequired": false
|
||||
},
|
||||
{
|
||||
"name": "General",
|
||||
"dest": "/settings/general",
|
||||
"name": "Weather",
|
||||
"dest": "/settings/weather",
|
||||
"authRequired": true
|
||||
},
|
||||
{
|
||||
"name": "Search",
|
||||
"dest": "/settings/search",
|
||||
"authRequired": true
|
||||
},
|
||||
{
|
||||
|
@ -15,11 +20,6 @@
|
|||
"dest": "/settings/interface",
|
||||
"authRequired": true
|
||||
},
|
||||
{
|
||||
"name": "Weather",
|
||||
"dest": "/settings/weather",
|
||||
"authRequired": true
|
||||
},
|
||||
{
|
||||
"name": "Docker",
|
||||
"dest": "/settings/docker",
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
.InputGroup span {
|
||||
font-size: 12px;
|
||||
color: var(--color-primary);
|
||||
color: var(--color-primary)
|
||||
}
|
||||
|
||||
.InputGroup span a {
|
||||
|
@ -37,14 +37,4 @@
|
|||
.InputGroup textarea {
|
||||
resize: none;
|
||||
height: 50vh;
|
||||
}
|
||||
|
||||
.InputGroup input[type='color'] {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
.InputGroup input[type='color']:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
import classes from './SettingsHeadline.module.css';
|
||||
const classes = require('./SettingsHeadline.module.css');
|
||||
|
||||
interface Props {
|
||||
text: string;
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
.ActionIcons {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.ActionIcons svg {
|
||||
width: 20px;
|
||||
}
|
||||
|
||||
.ActionIcons svg:hover {
|
||||
cursor: pointer;
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
import { ReactNode } from 'react';
|
||||
import styles from './ActionIcons.module.css';
|
||||
|
||||
interface Props {
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
export const ActionIcons = ({ children }: Props): JSX.Element => {
|
||||
return <span className={styles.ActionIcons}>{children}</span>;
|
||||
};
|
|
@ -10,7 +10,7 @@ interface Props {
|
|||
}
|
||||
|
||||
export const WeatherIcon = (props: Props): JSX.Element => {
|
||||
const { activeTheme } = useSelector((state: State) => state.theme);
|
||||
const { theme } = useSelector((state: State) => state.theme);
|
||||
|
||||
const icon = props.isDay
|
||||
? new IconMapping().mapIcon(props.weatherStatusCode, TimeOfDay.day)
|
||||
|
@ -18,7 +18,7 @@ export const WeatherIcon = (props: Props): JSX.Element => {
|
|||
|
||||
useEffect(() => {
|
||||
const delay = setTimeout(() => {
|
||||
const skycons = new Skycons({ color: activeTheme.colors.accent });
|
||||
const skycons = new Skycons({ color: theme.colors.accent });
|
||||
skycons.add(`weather-icon`, icon);
|
||||
skycons.play();
|
||||
}, 1);
|
||||
|
@ -26,7 +26,7 @@ export const WeatherIcon = (props: Props): JSX.Element => {
|
|||
return () => {
|
||||
clearTimeout(delay);
|
||||
};
|
||||
}, [props.weatherStatusCode, icon, activeTheme.colors.accent]);
|
||||
}, [props.weatherStatusCode, icon, theme.colors.accent]);
|
||||
|
||||
return <canvas id={`weather-icon`} width="50" height="50"></canvas>;
|
||||
};
|
||||
|
|
|
@ -6,32 +6,24 @@ interface Props {
|
|||
isOpen: boolean;
|
||||
setIsOpen: Function;
|
||||
children: ReactNode;
|
||||
cb?: Function;
|
||||
}
|
||||
|
||||
export const Modal = ({
|
||||
isOpen,
|
||||
setIsOpen,
|
||||
children,
|
||||
cb,
|
||||
}: Props): JSX.Element => {
|
||||
export const Modal = (props: Props): JSX.Element => {
|
||||
const modalRef = useRef(null);
|
||||
const modalClasses = [
|
||||
classes.Modal,
|
||||
isOpen ? classes.ModalOpen : classes.ModalClose,
|
||||
props.isOpen ? classes.ModalOpen : classes.ModalClose,
|
||||
].join(' ');
|
||||
|
||||
const clickHandler = (e: MouseEvent) => {
|
||||
if (e.target === modalRef.current) {
|
||||
setIsOpen(false);
|
||||
|
||||
if (cb) cb();
|
||||
props.setIsOpen(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={modalClasses} onClick={clickHandler} ref={modalRef}>
|
||||
{children}
|
||||
{props.children}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
.CompactTable {
|
||||
display: grid;
|
||||
}
|
||||
|
||||
.CompactTable span {
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.CompactTable span:last-child {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.Separator {
|
||||
border-bottom: 1px solid var(--color-primary);
|
||||
margin: 10px 0;
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
import { ReactNode } from 'react';
|
||||
import classes from './CompactTable.module.css';
|
||||
|
||||
interface Props {
|
||||
headers: string[];
|
||||
children?: ReactNode;
|
||||
}
|
||||
|
||||
export const CompactTable = ({ headers, children }: Props): JSX.Element => {
|
||||
return (
|
||||
<div
|
||||
className={classes.CompactTable}
|
||||
style={{ gridTemplateColumns: `repeat(${headers.length}, 1fr)` }}
|
||||
>
|
||||
{headers.map((h, idx) => (
|
||||
<span key={idx}>{h}</span>
|
||||
))}
|
||||
|
||||
<div
|
||||
className={classes.Separator}
|
||||
style={{ gridColumn: `1 / ${headers.length + 1}` }}
|
||||
></div>
|
||||
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
};
|
|
@ -6,21 +6,3 @@
|
|||
color: var(--color-accent);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.messageCenter {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: baseline;
|
||||
color: var(--color-primary);
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.messageCenter a,
|
||||
.messageCenter span {
|
||||
color: var(--color-accent);
|
||||
}
|
||||
|
||||
.messageCenter a:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
|
|
@ -4,11 +4,8 @@ import classes from './Message.module.css';
|
|||
|
||||
interface Props {
|
||||
children: ReactNode;
|
||||
isPrimary?: boolean;
|
||||
}
|
||||
|
||||
export const Message = ({ children, isPrimary = true }: Props): JSX.Element => {
|
||||
const style = isPrimary ? classes.message : classes.messageCenter;
|
||||
|
||||
return <p className={style}>{children}</p>;
|
||||
export const Message = ({ children }: Props): JSX.Element => {
|
||||
return <p className={classes.message}>{children}</p>;
|
||||
};
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
export * from './Tables/Table/Table';
|
||||
export * from './Tables/CompactTable/CompactTable';
|
||||
export * from './Table/Table';
|
||||
export * from './Spinner/Spinner';
|
||||
export * from './Notification/Notification';
|
||||
export * from './Modal/Modal';
|
||||
export * from './Layout/Layout';
|
||||
export * from './Icons/Icon/Icon';
|
||||
export * from './Icons/WeatherIcon/WeatherIcon';
|
||||
export * from './Icons/ActionIcons/ActionIcons';
|
||||
export * from './Headlines/Headline/Headline';
|
||||
export * from './Headlines/SectionHeadline/SectionHeadline';
|
||||
export * from './Headlines/SettingsHeadline/SettingsHeadline';
|
||||
|
|
|
@ -5,7 +5,6 @@ export interface NewApp {
|
|||
url: string;
|
||||
icon: string;
|
||||
isPublic: boolean;
|
||||
description: string;
|
||||
}
|
||||
|
||||
export interface App extends Model, NewApp {
|
||||
|
|
|
@ -17,7 +17,6 @@ export interface Config {
|
|||
hideCategories: boolean;
|
||||
hideSearch: boolean;
|
||||
defaultSearchProvider: string;
|
||||
secondarySearchProvider: string;
|
||||
dockerApps: boolean;
|
||||
dockerHost: string;
|
||||
kubernetesApps: boolean;
|
||||
|
|
|
@ -8,30 +8,29 @@ export interface WeatherForm {
|
|||
weatherData: WeatherData;
|
||||
}
|
||||
|
||||
export interface GeneralForm {
|
||||
export interface SearchForm {
|
||||
hideSearch: boolean;
|
||||
defaultSearchProvider: string;
|
||||
secondarySearchProvider: string;
|
||||
searchSameTab: boolean;
|
||||
pinAppsByDefault: boolean;
|
||||
pinCategoriesByDefault: boolean;
|
||||
useOrdering: string;
|
||||
appsSameTab: boolean;
|
||||
bookmarksSameTab: boolean;
|
||||
disableAutofocus: boolean;
|
||||
}
|
||||
|
||||
export interface UISettingsForm {
|
||||
export interface OtherSettingsForm {
|
||||
customTitle: string;
|
||||
pinAppsByDefault: boolean;
|
||||
pinCategoriesByDefault: boolean;
|
||||
hideHeader: boolean;
|
||||
hideApps: boolean;
|
||||
hideCategories: boolean;
|
||||
useOrdering: string;
|
||||
appsSameTab: boolean;
|
||||
bookmarksSameTab: boolean;
|
||||
useAmericanDate: boolean;
|
||||
greetingsSchema: string;
|
||||
daySchema: string;
|
||||
monthSchema: string;
|
||||
showTime: boolean;
|
||||
hideDate: boolean;
|
||||
hideSearch: boolean;
|
||||
disableAutofocus: boolean;
|
||||
}
|
||||
|
||||
export interface DockerSettingsForm {
|
||||
|
|
|
@ -4,8 +4,6 @@ export interface SearchResult {
|
|||
isLocal: boolean;
|
||||
isURL: boolean;
|
||||
sameTab: boolean;
|
||||
encodedURL: string;
|
||||
primarySearch: Query;
|
||||
secondarySearch: Query;
|
||||
rawQuery: string;
|
||||
search: string;
|
||||
query: Query;
|
||||
}
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
export interface ThemeColors {
|
||||
background: string;
|
||||
primary: string;
|
||||
accent: string;
|
||||
}
|
||||
|
||||
export interface Theme {
|
||||
name: string;
|
||||
colors: ThemeColors;
|
||||
isCustom: boolean;
|
||||
}
|
||||
colors: {
|
||||
background: string;
|
||||
primary: string;
|
||||
accent: string;
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@ import {
|
|||
UpdateConfigAction,
|
||||
UpdateQueryAction,
|
||||
} from '../actions/config';
|
||||
import axios, { AxiosError } from 'axios';
|
||||
import axios from 'axios';
|
||||
import { ApiResponse, Config, Query } from '../../interfaces';
|
||||
import { ActionType } from '../action-types';
|
||||
import { storeUIConfig, applyAuth } from '../../utility';
|
||||
|
@ -103,15 +103,7 @@ export const addQuery =
|
|||
payload: res.data.data,
|
||||
});
|
||||
} catch (err) {
|
||||
const error = err as AxiosError<{ error: string }>;
|
||||
|
||||
dispatch<any>({
|
||||
type: ActionType.createNotification,
|
||||
payload: {
|
||||
title: 'Error',
|
||||
message: error.response?.data.error,
|
||||
},
|
||||
});
|
||||
console.log(err);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1,128 +1,30 @@
|
|||
import { Dispatch } from 'redux';
|
||||
import {
|
||||
AddThemeAction,
|
||||
DeleteThemeAction,
|
||||
EditThemeAction,
|
||||
FetchThemesAction,
|
||||
SetThemeAction,
|
||||
UpdateThemeAction,
|
||||
} from '../actions/theme';
|
||||
import { SetThemeAction } from '../actions/theme';
|
||||
import { ActionType } from '../action-types';
|
||||
import { Theme, ApiResponse, ThemeColors } from '../../interfaces';
|
||||
import { applyAuth, parseThemeToPAB } from '../../utility';
|
||||
import axios, { AxiosError } from 'axios';
|
||||
import { Theme } from '../../interfaces/Theme';
|
||||
import { themes } from '../../components/Settings/Themer/themes.json';
|
||||
|
||||
export const setTheme =
|
||||
(colors: ThemeColors, remeberTheme: boolean = true) =>
|
||||
(name: string, remeberTheme: boolean = true) =>
|
||||
(dispatch: Dispatch<SetThemeAction>) => {
|
||||
if (remeberTheme) {
|
||||
localStorage.setItem('theme', parseThemeToPAB(colors));
|
||||
}
|
||||
const theme = themes.find((theme) => theme.name === name);
|
||||
|
||||
for (const [key, value] of Object.entries(colors)) {
|
||||
document.body.style.setProperty(`--color-${key}`, value);
|
||||
}
|
||||
if (theme) {
|
||||
if (remeberTheme) {
|
||||
localStorage.setItem('theme', name);
|
||||
}
|
||||
|
||||
dispatch({
|
||||
type: ActionType.setTheme,
|
||||
payload: colors,
|
||||
});
|
||||
};
|
||||
|
||||
export const fetchThemes =
|
||||
() => async (dispatch: Dispatch<FetchThemesAction>) => {
|
||||
try {
|
||||
const res = await axios.get<ApiResponse<Theme[]>>('/api/themes');
|
||||
loadTheme(theme);
|
||||
|
||||
dispatch({
|
||||
type: ActionType.fetchThemes,
|
||||
payload: res.data.data,
|
||||
});
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
};
|
||||
|
||||
export const addTheme =
|
||||
(theme: Theme) => async (dispatch: Dispatch<AddThemeAction>) => {
|
||||
try {
|
||||
const res = await axios.post<ApiResponse<Theme>>('/api/themes', theme, {
|
||||
headers: applyAuth(),
|
||||
});
|
||||
|
||||
dispatch({
|
||||
type: ActionType.addTheme,
|
||||
payload: res.data.data,
|
||||
});
|
||||
|
||||
dispatch<any>({
|
||||
type: ActionType.createNotification,
|
||||
payload: {
|
||||
title: 'Success',
|
||||
message: 'Theme added',
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
const error = err as AxiosError<{ error: string }>;
|
||||
|
||||
dispatch<any>({
|
||||
type: ActionType.createNotification,
|
||||
payload: {
|
||||
title: 'Error',
|
||||
message: error.response?.data.error,
|
||||
},
|
||||
type: ActionType.setTheme,
|
||||
payload: theme,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const deleteTheme =
|
||||
(name: string) => async (dispatch: Dispatch<DeleteThemeAction>) => {
|
||||
try {
|
||||
const res = await axios.delete<ApiResponse<Theme[]>>(
|
||||
`/api/themes/${name}`,
|
||||
{ headers: applyAuth() }
|
||||
);
|
||||
|
||||
dispatch({
|
||||
type: ActionType.deleteTheme,
|
||||
payload: res.data.data,
|
||||
});
|
||||
|
||||
dispatch<any>({
|
||||
type: ActionType.createNotification,
|
||||
payload: {
|
||||
title: 'Success',
|
||||
message: 'Theme deleted',
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
};
|
||||
|
||||
export const editTheme =
|
||||
(theme: Theme | null) => (dispatch: Dispatch<EditThemeAction>) => {
|
||||
dispatch({
|
||||
type: ActionType.editTheme,
|
||||
payload: theme,
|
||||
});
|
||||
};
|
||||
|
||||
export const updateTheme =
|
||||
(theme: Theme, originalName: string) =>
|
||||
async (dispatch: Dispatch<UpdateThemeAction>) => {
|
||||
try {
|
||||
const res = await axios.put<ApiResponse<Theme[]>>(
|
||||
`/api/themes/${originalName}`,
|
||||
theme,
|
||||
{ headers: applyAuth() }
|
||||
);
|
||||
|
||||
dispatch({
|
||||
type: ActionType.updateTheme,
|
||||
payload: res.data.data,
|
||||
});
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
};
|
||||
export const loadTheme = (theme: Theme): void => {
|
||||
for (const [key, value] of Object.entries(theme.colors)) {
|
||||
document.body.style.setProperty(`--color-${key}`, value);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
export enum ActionType {
|
||||
// THEME
|
||||
setTheme = 'SET_THEME',
|
||||
fetchThemes = 'FETCH_THEMES',
|
||||
addTheme = 'ADD_THEME',
|
||||
deleteTheme = 'DELETE_THEME',
|
||||
updateTheme = 'UPDATE_THEME',
|
||||
editTheme = 'EDIT_THEME',
|
||||
// CONFIG
|
||||
getConfig = 'GET_CONFIG',
|
||||
updateConfig = 'UPDATE_CONFIG',
|
||||
|
|
|
@ -1,13 +1,6 @@
|
|||
import { App } from '../../interfaces';
|
||||
|
||||
import {
|
||||
AddThemeAction,
|
||||
DeleteThemeAction,
|
||||
EditThemeAction,
|
||||
FetchThemesAction,
|
||||
SetThemeAction,
|
||||
UpdateThemeAction,
|
||||
} from './theme';
|
||||
import { SetThemeAction } from './theme';
|
||||
|
||||
import {
|
||||
AddQueryAction,
|
||||
|
@ -61,11 +54,6 @@ import {
|
|||
export type Action =
|
||||
// Theme
|
||||
| SetThemeAction
|
||||
| FetchThemesAction
|
||||
| AddThemeAction
|
||||
| DeleteThemeAction
|
||||
| UpdateThemeAction
|
||||
| EditThemeAction
|
||||
// Config
|
||||
| GetConfigAction
|
||||
| UpdateConfigAction
|
||||
|
|
|
@ -1,32 +1,7 @@
|
|||
import { ActionType } from '../action-types';
|
||||
import { Theme, ThemeColors } from '../../interfaces';
|
||||
import { Theme } from '../../interfaces';
|
||||
|
||||
export interface SetThemeAction {
|
||||
type: ActionType.setTheme;
|
||||
payload: ThemeColors;
|
||||
}
|
||||
|
||||
export interface FetchThemesAction {
|
||||
type: ActionType.fetchThemes;
|
||||
payload: Theme[];
|
||||
}
|
||||
|
||||
export interface AddThemeAction {
|
||||
type: ActionType.addTheme;
|
||||
payload: Theme;
|
||||
}
|
||||
|
||||
export interface DeleteThemeAction {
|
||||
type: ActionType.deleteTheme;
|
||||
payload: Theme[];
|
||||
}
|
||||
|
||||
export interface UpdateThemeAction {
|
||||
type: ActionType.updateTheme;
|
||||
payload: Theme[];
|
||||
}
|
||||
|
||||
export interface EditThemeAction {
|
||||
type: ActionType.editTheme;
|
||||
payload: Theme | null;
|
||||
}
|
||||
|
|
|
@ -1,30 +1,20 @@
|
|||
import { Action } from '../actions';
|
||||
import { ActionType } from '../action-types';
|
||||
import { Theme } from '../../interfaces/Theme';
|
||||
import { arrayPartition, parsePABToTheme } from '../../utility';
|
||||
|
||||
interface ThemeState {
|
||||
activeTheme: Theme;
|
||||
themes: Theme[];
|
||||
userThemes: Theme[];
|
||||
themeInEdit: Theme | null;
|
||||
theme: Theme;
|
||||
}
|
||||
|
||||
const savedTheme = localStorage.theme
|
||||
? parsePABToTheme(localStorage.theme)
|
||||
: parsePABToTheme('#effbff;#6ee2ff;#242b33');
|
||||
|
||||
const initialState: ThemeState = {
|
||||
activeTheme: {
|
||||
name: 'main',
|
||||
isCustom: false,
|
||||
theme: {
|
||||
name: 'tron',
|
||||
colors: {
|
||||
...savedTheme,
|
||||
background: '#242B33',
|
||||
primary: '#EFFBFF',
|
||||
accent: '#6EE2FF',
|
||||
},
|
||||
},
|
||||
themes: [],
|
||||
userThemes: [],
|
||||
themeInEdit: null,
|
||||
};
|
||||
|
||||
export const themeReducer = (
|
||||
|
@ -32,56 +22,8 @@ export const themeReducer = (
|
|||
action: Action
|
||||
): ThemeState => {
|
||||
switch (action.type) {
|
||||
case ActionType.setTheme: {
|
||||
return {
|
||||
...state,
|
||||
activeTheme: {
|
||||
...state.activeTheme,
|
||||
colors: action.payload,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.fetchThemes: {
|
||||
const [themes, userThemes] = arrayPartition<Theme>(
|
||||
action.payload,
|
||||
(e) => !e.isCustom
|
||||
);
|
||||
|
||||
return {
|
||||
...state,
|
||||
themes,
|
||||
userThemes,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.addTheme: {
|
||||
return {
|
||||
...state,
|
||||
userThemes: [...state.userThemes, action.payload],
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.deleteTheme: {
|
||||
return {
|
||||
...state,
|
||||
userThemes: action.payload,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.editTheme: {
|
||||
return {
|
||||
...state,
|
||||
themeInEdit: action.payload,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.updateTheme: {
|
||||
return {
|
||||
...state,
|
||||
userThemes: action.payload,
|
||||
};
|
||||
}
|
||||
case ActionType.setTheme:
|
||||
return { theme: action.payload };
|
||||
|
||||
default:
|
||||
return state;
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
import {
|
||||
DockerSettingsForm,
|
||||
UISettingsForm,
|
||||
GeneralForm,
|
||||
OtherSettingsForm,
|
||||
SearchForm,
|
||||
ThemeSettingsForm,
|
||||
WeatherForm,
|
||||
} from '../interfaces';
|
||||
|
||||
export type ConfigFormData =
|
||||
| WeatherForm
|
||||
| GeneralForm
|
||||
| SearchForm
|
||||
| DockerSettingsForm
|
||||
| UISettingsForm
|
||||
| OtherSettingsForm
|
||||
| ThemeSettingsForm;
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
export const arrayPartition = <T>(
|
||||
arr: T[],
|
||||
isValid: (e: T) => boolean
|
||||
): T[][] => {
|
||||
let pass: T[] = [];
|
||||
let fail: T[] = [];
|
||||
|
||||
arr.forEach((e) => (isValid(e) ? pass : fail).push(e));
|
||||
|
||||
return [pass, fail];
|
||||
};
|
|
@ -12,5 +12,3 @@ export * from './parseTime';
|
|||
export * from './decodeToken';
|
||||
export * from './applyAuth';
|
||||
export * from './escapeRegex';
|
||||
export * from './parseTheme';
|
||||
export * from './arrayPartition';
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
import { ThemeColors } from '../interfaces';
|
||||
|
||||
// parse theme in PAB (primary;accent;background) format to theme colors object
|
||||
export const parsePABToTheme = (themeStr: string): ThemeColors => {
|
||||
const [primary, accent, background] = themeStr.split(';');
|
||||
|
||||
return {
|
||||
primary,
|
||||
accent,
|
||||
background,
|
||||
};
|
||||
};
|
||||
|
||||
export const parseThemeToPAB = ({
|
||||
primary: p,
|
||||
accent: a,
|
||||
background: b,
|
||||
}: ThemeColors): string => {
|
||||
return `${p};${a};${b}`;
|
||||
};
|
|
@ -4,7 +4,7 @@ export const redirectUrl = (url: string, sameTab: boolean) => {
|
|||
const parsedUrl = urlParser(url)[1];
|
||||
|
||||
if (sameTab) {
|
||||
document.location.assign(parsedUrl);
|
||||
document.location.replace(parsedUrl);
|
||||
} else {
|
||||
window.open(parsedUrl);
|
||||
}
|
||||
|
|
|
@ -1,27 +1,19 @@
|
|||
import searchQueries from './searchQueries.json';
|
||||
import { SearchResult } from '../interfaces';
|
||||
import { queries } from './searchQueries.json';
|
||||
import { Query, SearchResult } from '../interfaces';
|
||||
import { store } from '../store/store';
|
||||
import { isUrlOrIp } from '.';
|
||||
|
||||
export const searchParser = (searchQuery: string): SearchResult => {
|
||||
const queries = searchQueries.queries;
|
||||
|
||||
const result: SearchResult = {
|
||||
isLocal: false,
|
||||
isURL: false,
|
||||
sameTab: false,
|
||||
encodedURL: '',
|
||||
primarySearch: {
|
||||
search: '',
|
||||
query: {
|
||||
name: '',
|
||||
prefix: '',
|
||||
template: '',
|
||||
},
|
||||
secondarySearch: {
|
||||
name: '',
|
||||
prefix: '',
|
||||
template: '',
|
||||
},
|
||||
rawQuery: searchQuery,
|
||||
};
|
||||
|
||||
const { customQueries, config } = store.getState().config;
|
||||
|
@ -32,35 +24,25 @@ export const searchParser = (searchQuery: string): SearchResult => {
|
|||
// Match prefix and query
|
||||
const splitQuery = searchQuery.match(/^\/([a-z]+)[ ](.+)$/i);
|
||||
|
||||
// Extract prefix
|
||||
const prefix = splitQuery ? splitQuery[1] : config.defaultSearchProvider;
|
||||
|
||||
// Encode url
|
||||
const encodedURL = splitQuery
|
||||
const search = splitQuery
|
||||
? encodeURIComponent(splitQuery[2])
|
||||
: encodeURIComponent(searchQuery);
|
||||
|
||||
// Find primary search engine template
|
||||
const findProvider = (prefix: string) => {
|
||||
return [...queries, ...customQueries].find((q) => q.prefix === prefix);
|
||||
};
|
||||
const query = [...queries, ...customQueries].find(
|
||||
(q: Query) => q.prefix === prefix
|
||||
);
|
||||
|
||||
const primarySearch = findProvider(prefix);
|
||||
const secondarySearch = findProvider(config.secondarySearchProvider);
|
||||
|
||||
// If search providers were found
|
||||
if (primarySearch) {
|
||||
result.primarySearch = primarySearch;
|
||||
result.encodedURL = encodedURL;
|
||||
// If search provider was found
|
||||
if (query) {
|
||||
result.query = query;
|
||||
result.search = search;
|
||||
|
||||
if (prefix === 'l') {
|
||||
result.isLocal = true;
|
||||
}
|
||||
|
||||
result.sameTab = config.searchSameTab;
|
||||
|
||||
if (secondarySearch) {
|
||||
result.secondarySearch = secondarySearch;
|
||||
} else {
|
||||
result.sameTab = config.searchSameTab;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
@ -5,7 +5,6 @@ export const newAppTemplate: NewApp = {
|
|||
url: '',
|
||||
icon: '',
|
||||
isPublic: true,
|
||||
description: '',
|
||||
};
|
||||
|
||||
export const appTemplate: App = {
|
||||
|
|
|
@ -17,7 +17,6 @@ export const configTemplate: Config = {
|
|||
hideCategories: false,
|
||||
hideSearch: false,
|
||||
defaultSearchProvider: 'l',
|
||||
secondarySearchProvider: 'd',
|
||||
dockerApps: false,
|
||||
dockerHost: 'localhost',
|
||||
kubernetesApps: false,
|
||||
|
|
|
@ -1,16 +1,21 @@
|
|||
import {
|
||||
DockerSettingsForm,
|
||||
UISettingsForm,
|
||||
GeneralForm,
|
||||
OtherSettingsForm,
|
||||
SearchForm,
|
||||
ThemeSettingsForm,
|
||||
WeatherForm,
|
||||
} from '../../interfaces';
|
||||
|
||||
export const uiSettingsTemplate: UISettingsForm = {
|
||||
export const otherSettingsTemplate: OtherSettingsForm = {
|
||||
customTitle: document.title,
|
||||
pinAppsByDefault: true,
|
||||
pinCategoriesByDefault: true,
|
||||
hideHeader: false,
|
||||
hideApps: false,
|
||||
hideCategories: false,
|
||||
useOrdering: 'createdAt',
|
||||
appsSameTab: false,
|
||||
bookmarksSameTab: false,
|
||||
useAmericanDate: false,
|
||||
greetingsSchema: 'Good evening!;Good afternoon!;Good morning!;Good night!',
|
||||
daySchema: 'Sunday;Monday;Tuesday;Wednesday;Thursday;Friday;Saturday',
|
||||
|
@ -18,8 +23,6 @@ export const uiSettingsTemplate: UISettingsForm = {
|
|||
'January;February;March;April;May;June;July;August;September;October;November;December',
|
||||
showTime: false,
|
||||
hideDate: false,
|
||||
hideSearch: false,
|
||||
disableAutofocus: false,
|
||||
};
|
||||
|
||||
export const weatherSettingsTemplate: WeatherForm = {
|
||||
|
@ -30,15 +33,11 @@ export const weatherSettingsTemplate: WeatherForm = {
|
|||
weatherData: 'cloud',
|
||||
};
|
||||
|
||||
export const generalSettingsTemplate: GeneralForm = {
|
||||
export const searchSettingsTemplate: SearchForm = {
|
||||
hideSearch: false,
|
||||
searchSameTab: false,
|
||||
defaultSearchProvider: 'l',
|
||||
secondarySearchProvider: 'd',
|
||||
pinAppsByDefault: true,
|
||||
pinCategoriesByDefault: true,
|
||||
useOrdering: 'createdAt',
|
||||
appsSameTab: false,
|
||||
bookmarksSameTab: false,
|
||||
disableAutofocus: false,
|
||||
};
|
||||
|
||||
export const dockerSettingsTemplate: DockerSettingsForm = {
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
const asyncWrapper = require('../../middleware/asyncWrapper');
|
||||
const ErrorResponse = require('../../utils/ErrorResponse');
|
||||
const File = require('../../utils/File');
|
||||
|
||||
// @desc Add custom search query
|
||||
|
@ -9,12 +8,6 @@ const addQuery = asyncWrapper(async (req, res, next) => {
|
|||
const file = new File('data/customQueries.json');
|
||||
let content = JSON.parse(file.read());
|
||||
|
||||
const prefixes = content.queries.map((q) => q.prefix);
|
||||
|
||||
if (prefixes.includes(req.body.prefix)) {
|
||||
return next(new ErrorResponse('Prefix must be unique', 400));
|
||||
}
|
||||
|
||||
// Add new query
|
||||
content.queries.push(req.body);
|
||||
file.write(content, true);
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
const asyncWrapper = require('../../middleware/asyncWrapper');
|
||||
const ErrorResponse = require('../../utils/ErrorResponse');
|
||||
const File = require('../../utils/File');
|
||||
|
||||
// @desc Create new theme
|
||||
// @route POST /api/themes
|
||||
// @access Private
|
||||
const addTheme = asyncWrapper(async (req, res, next) => {
|
||||
const file = new File('data/themes.json');
|
||||
let content = JSON.parse(file.read());
|
||||
|
||||
const themeNames = content.themes.map((t) => t.name);
|
||||
|
||||
if (themeNames.includes(req.body.name)) {
|
||||
return next(new ErrorResponse('Name must be unique', 400));
|
||||
}
|
||||
|
||||
// Add new theme
|
||||
content.themes.push(req.body);
|
||||
file.write(content, true);
|
||||
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
data: req.body,
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = addTheme;
|
|
@ -1,22 +0,0 @@
|
|||
const asyncWrapper = require('../../middleware/asyncWrapper');
|
||||
const File = require('../../utils/File');
|
||||
|
||||
// @desc Delete theme
|
||||
// @route DELETE /api/themes/:name
|
||||
// @access Public
|
||||
const deleteTheme = asyncWrapper(async (req, res, next) => {
|
||||
const file = new File('data/themes.json');
|
||||
let content = JSON.parse(file.read());
|
||||
|
||||
content.themes = content.themes.filter((t) => t.name != req.params.name);
|
||||
file.write(content, true);
|
||||
|
||||
const userThemes = content.themes.filter((t) => t.isCustom);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: userThemes,
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = deleteTheme;
|
|
@ -1,17 +0,0 @@
|
|||
const asyncWrapper = require('../../middleware/asyncWrapper');
|
||||
const File = require('../../utils/File');
|
||||
|
||||
// @desc Get themes file
|
||||
// @route GET /api/themes
|
||||
// @access Public
|
||||
const getThemes = asyncWrapper(async (req, res, next) => {
|
||||
const file = new File('data/themes.json');
|
||||
const content = JSON.parse(file.read());
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: content.themes,
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = getThemes;
|
|
@ -1,6 +0,0 @@
|
|||
module.exports = {
|
||||
getThemes: require('./getThemes'),
|
||||
addTheme: require('./addTheme'),
|
||||
deleteTheme: require('./deleteTheme'),
|
||||
updateTheme: require('./updateTheme'),
|
||||
};
|
|
@ -1,32 +0,0 @@
|
|||
const asyncWrapper = require('../../middleware/asyncWrapper');
|
||||
const File = require('../../utils/File');
|
||||
|
||||
// @desc Update theme
|
||||
// @route PUT /api/themes/:name
|
||||
// @access Public
|
||||
const updateTheme = asyncWrapper(async (req, res, next) => {
|
||||
const file = new File('data/themes.json');
|
||||
let content = JSON.parse(file.read());
|
||||
|
||||
let themeIdx = content.themes.findIndex((t) => t.name == req.params.name);
|
||||
|
||||
// theme found
|
||||
if (themeIdx > -1) {
|
||||
content.themes = [
|
||||
...content.themes.slice(0, themeIdx),
|
||||
req.body,
|
||||
...content.themes.slice(themeIdx + 1),
|
||||
];
|
||||
}
|
||||
|
||||
file.write(content, true);
|
||||
|
||||
const userThemes = content.themes.filter((t) => t.isCustom);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: userThemes,
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = updateTheme;
|
|
@ -1,19 +0,0 @@
|
|||
const { DataTypes } = require('sequelize');
|
||||
const { STRING } = DataTypes;
|
||||
|
||||
const up = async (query) => {
|
||||
await query.addColumn('apps', 'description', {
|
||||
type: STRING,
|
||||
allowNull: false,
|
||||
defaultValue: '',
|
||||
});
|
||||
};
|
||||
|
||||
const down = async (query) => {
|
||||
await query.removeColumn('apps', 'description');
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
up,
|
||||
down,
|
||||
};
|
|
@ -1,4 +1,5 @@
|
|||
const ErrorResponse = require('../utils/ErrorResponse');
|
||||
const colors = require('colors');
|
||||
const Logger = require('../utils/Logger');
|
||||
const logger = new Logger();
|
||||
|
||||
|
|
|
@ -31,11 +31,6 @@ const App = sequelize.define(
|
|||
allowNull: true,
|
||||
defaultValue: 1,
|
||||
},
|
||||
description: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
defaultValue: '',
|
||||
},
|
||||
},
|
||||
{
|
||||
tableName: 'apps',
|
||||
|
|
5047
package-lock.json
generated
5047
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -20,8 +20,8 @@
|
|||
"@kubernetes/client-node": "^0.15.1",
|
||||
"@types/express": "^4.17.13",
|
||||
"axios": "^0.24.0",
|
||||
"colors": "^1.4.0",
|
||||
"concurrently": "^6.3.0",
|
||||
"docker-secret": "^1.2.4",
|
||||
"dotenv": "^10.0.0",
|
||||
"express": "^4.17.1",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
|
|
|
@ -2,7 +2,7 @@ const express = require('express');
|
|||
const router = express.Router();
|
||||
|
||||
// middleware
|
||||
const { auth, requireAuth, requireBody } = require('../middleware');
|
||||
const { auth, requireAuth } = require('../middleware');
|
||||
|
||||
const {
|
||||
getQueries,
|
||||
|
@ -11,16 +11,7 @@ const {
|
|||
updateQuery,
|
||||
} = require('../controllers/queries/');
|
||||
|
||||
router
|
||||
.route('/')
|
||||
.post(
|
||||
auth,
|
||||
requireAuth,
|
||||
requireBody(['name', 'prefix', 'template']),
|
||||
addQuery
|
||||
)
|
||||
.get(getQueries);
|
||||
|
||||
router.route('/').post(auth, requireAuth, addQuery).get(getQueries);
|
||||
router
|
||||
.route('/:prefix')
|
||||
.delete(auth, requireAuth, deleteQuery)
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
// middleware
|
||||
const { auth, requireAuth, requireBody } = require('../middleware');
|
||||
|
||||
const {
|
||||
getThemes,
|
||||
addTheme,
|
||||
deleteTheme,
|
||||
updateTheme,
|
||||
} = require('../controllers/themes/');
|
||||
|
||||
router
|
||||
.route('/')
|
||||
.get(getThemes)
|
||||
.post(
|
||||
auth,
|
||||
requireAuth,
|
||||
requireBody(['name', 'colors', 'isCustom']),
|
||||
addTheme
|
||||
);
|
||||
|
||||
router
|
||||
.route('/:name')
|
||||
.delete(auth, requireAuth, deleteTheme)
|
||||
.put(auth, requireAuth, updateTheme);
|
||||
|
||||
module.exports = router;
|
|
@ -23,7 +23,6 @@ const logger = new Logger();
|
|||
await initApp();
|
||||
await connectDB();
|
||||
await associateModels();
|
||||
await jobs();
|
||||
|
||||
// Create server for Express API and WebSockets
|
||||
const server = http.createServer();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class Logger {
|
||||
log(message, level = 'INFO') {
|
||||
console.log(`[${this.generateTimestamp()}] [${level}] ${message}`);
|
||||
console.log(`[${this.generateTimestamp()}] [${level}] ${message}`)
|
||||
}
|
||||
|
||||
generateTimestamp() {
|
||||
|
@ -20,9 +20,7 @@ class Logger {
|
|||
// Timezone
|
||||
const tz = -d.getTimezoneOffset() / 60;
|
||||
|
||||
return `${year}-${month}-${day} ${hour}:${minutes}:${seconds}.${miliseconds} UTC${
|
||||
tz >= 0 ? '+' + tz : tz
|
||||
}`;
|
||||
return `${year}-${month}-${day} ${hour}:${minutes}:${seconds}.${miliseconds} UTC${tz >= 0 ? '+' + tz : tz}`;
|
||||
}
|
||||
|
||||
parseDate(date, ms = false) {
|
||||
|
@ -38,4 +36,4 @@ class Logger {
|
|||
}
|
||||
}
|
||||
|
||||
module.exports = Logger;
|
||||
module.exports = Logger;
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue