Compare commits
84 commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
3c347c854c | ||
![]() |
89fa2980e6 | ||
![]() |
7479ffb134 | ||
![]() |
97884a5293 | ||
![]() |
002a87a6df | ||
![]() |
17f0b7a553 | ||
![]() |
69ddc44796 | ||
![]() |
9e6d6fce73 | ||
![]() |
018ec0dd94 | ||
![]() |
c2d580ee0d | ||
![]() |
188c5bc04b | ||
![]() |
35ae5f9ee7 | ||
![]() |
ebd98d29c1 | ||
![]() |
446b4095f6 | ||
![]() |
2b5b3494f2 | ||
![]() |
6fb5737118 | ||
![]() |
16121ff547 | ||
![]() |
2c0491a5b0 | ||
![]() |
0f6d79683e | ||
![]() |
0b3eb2e87f | ||
![]() |
668edb03d3 | ||
![]() |
ad92de141b | ||
![]() |
bd96f6ca50 | ||
![]() |
9ab6c65d85 | ||
![]() |
378dd8e36d | ||
![]() |
b8af178cbf | ||
![]() |
48e28b9abd | ||
![]() |
89bd921875 | ||
![]() |
e427fbf54c | ||
![]() |
ee0b435493 | ||
![]() |
baac78021a | ||
![]() |
c2e81832a9 | ||
![]() |
58d021dde6 | ||
![]() |
1098a04fb9 | ||
![]() |
76dc3c44c8 | ||
![]() |
2d5cce9fdb | ||
![]() |
12295a6f68 | ||
![]() |
500e138643 | ||
![]() |
04e80b339c | ||
![]() |
750891cffa | ||
![]() |
fac8ef4027 | ||
![]() |
19fb14d553 | ||
![]() |
5c84d90bf1 | ||
![]() |
6767b1dac0 | ||
![]() |
e0ecf34ced | ||
![]() |
396c442062 | ||
![]() |
eaab31aacc | ||
![]() |
0044d265d1 | ||
![]() |
19a910a91c | ||
![]() |
6d8ce5361a | ||
![]() |
d2f99a5ec0 | ||
![]() |
c985fc17bf | ||
![]() |
73cf66c592 | ||
![]() |
ee044ed2ff | ||
![]() |
9dd3bd1f53 | ||
![]() |
55a064c2a4 | ||
![]() |
c8436aaf03 | ||
![]() |
edc01a341c | ||
![]() |
531ede0adf | ||
![]() |
a536ad49ea | ||
![]() |
b08181e712 | ||
![]() |
bc077b658d | ||
![]() |
48b91581b8 | ||
![]() |
d1d32cdbe6 | ||
![]() |
2b25a67bbf | ||
![]() |
64f1f28982 | ||
![]() |
f49ab6fd0d | ||
![]() |
068c8ab2e7 | ||
![]() |
2ca90a18e1 | ||
![]() |
fcf2b87d1c | ||
![]() |
d5610ad6be | ||
![]() |
ec5f50aba4 | ||
![]() |
a02814aa02 | ||
![]() |
e15c2a2f07 | ||
![]() |
f1f7b698f8 | ||
![]() |
dfdd49cf4a | ||
![]() |
d110d9b732 | ||
![]() |
882f011d07 | ||
![]() |
8941f8f2f4 | ||
![]() |
089ace562a | ||
![]() |
f963c1980b | ||
![]() |
1ff2c7afd9 | ||
![]() |
7a8808df4f | ||
![]() |
4c1c0087c7 |
144 changed files with 31167 additions and 11991 deletions
1
.dev/build_dev.sh
Normal file
1
.dev/build_dev.sh
Normal file
|
@ -0,0 +1 @@
|
|||
docker build -t flame:dev -f .docker/Dockerfile .
|
2
.dev/build_latest.sh
Normal file
2
.dev/build_latest.sh
Normal file
|
@ -0,0 +1,2 @@
|
|||
docker build -t pawelmalak/flame -t "pawelmalak/flame:$1" -f .docker/Dockerfile . \
|
||||
&& docker push pawelmalak/flame && docker push "pawelmalak/flame:$1"
|
6
.dev/build_multiarch.sh
Normal file
6
.dev/build_multiarch.sh
Normal file
|
@ -0,0 +1,6 @@
|
|||
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:14 as builder
|
||||
FROM node:16 as builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
|
@ -16,7 +16,7 @@ RUN mkdir -p ./public ./data \
|
|||
&& mv ./client/build/* ./public \
|
||||
&& rm -rf ./client
|
||||
|
||||
FROM node:14-alpine
|
||||
FROM node:16-alpine
|
||||
|
||||
COPY --from=builder /app /app
|
||||
|
||||
|
@ -27,4 +27,4 @@ EXPOSE 5005
|
|||
ENV NODE_ENV=production
|
||||
ENV PASSWORD=flame_password
|
||||
|
||||
CMD ["node", "server.js"]
|
||||
CMD ["sh", "-c", "chown -R node /app/data && node server.js"]
|
|
@ -1,10 +1,10 @@
|
|||
FROM node:14-alpine3.11 as builder
|
||||
FROM node:16-alpine3.11 as builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY package*.json ./
|
||||
|
||||
RUN apk --no-cache --virtual build-dependencies add python make g++ \
|
||||
RUN apk --no-cache --virtual build-dependencies add python python3 make g++ \
|
||||
&& npm install --production
|
||||
|
||||
COPY . .
|
||||
|
@ -17,7 +17,7 @@ RUN mkdir -p ./public ./data \
|
|||
&& mv ./client/build/* ./public \
|
||||
&& rm -rf ./client
|
||||
|
||||
FROM node:14-alpine3.11
|
||||
FROM node:16-alpine3.11
|
||||
|
||||
COPY --from=builder /app /app
|
||||
|
||||
|
@ -28,4 +28,4 @@ EXPOSE 5005
|
|||
ENV NODE_ENV=production
|
||||
ENV PASSWORD=flame_password
|
||||
|
||||
CMD ["node", "server.js"]
|
||||
CMD ["sh", "-c", "chown -R node /app/data && node server.js"]
|
|
@ -1,12 +1,22 @@
|
|||
version: '3'
|
||||
version: '3.6'
|
||||
|
||||
services:
|
||||
flame:
|
||||
image: pawelmalak/flame
|
||||
container_name: flame
|
||||
volumes:
|
||||
- /path/to/data:/app/data
|
||||
- /path/to/host/data:/app/data
|
||||
# - /var/run/docker.sock:/var/run/docker.sock # optional but required for Docker integration
|
||||
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,4 +2,5 @@ node_modules
|
|||
.github
|
||||
public
|
||||
k8s
|
||||
skaffold.yaml
|
||||
skaffold.yaml
|
||||
data
|
2
.env
2
.env
|
@ -1,5 +1,5 @@
|
|||
PORT=5005
|
||||
NODE_ENV=development
|
||||
VERSION=2.0.1
|
||||
VERSION=2.3.1
|
||||
PASSWORD=flame_password
|
||||
SECRET=e02eb43d69953658c6d07311d6313f2d4467672cb881f96b29368ba1f3f4da4b
|
27
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
27
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
---
|
||||
name: Bug report
|
||||
about: Create a bug report
|
||||
title: "[BUG] "
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Deployment details:**
|
||||
- App version [e.g. v1.7.4]:
|
||||
- Platform [e.g. amd64, arm64, arm/v7]:
|
||||
- Docker image tag [e.g. latest, multiarch]:
|
||||
|
||||
---
|
||||
|
||||
**Bug description:**
|
||||
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
---
|
||||
|
||||
**Steps to reproduce:**
|
||||
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,5 +1,4 @@
|
|||
node_modules
|
||||
data
|
||||
public
|
||||
!client/public
|
||||
build.sh
|
||||
!client/public
|
|
@ -1 +1,2 @@
|
|||
*.md
|
||||
*.md
|
||||
docker-compose.yml
|
43
CHANGELOG.md
43
CHANGELOG.md
|
@ -1,3 +1,46 @@
|
|||
### 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))
|
||||
- Empty apps and categories sections will now be hidden from guests ([#210](https://github.com/pawelmalak/flame/issues/210))
|
||||
- Fixed bug with fahrenheit degrees being displayed as float ([#221](https://github.com/pawelmalak/flame/issues/221))
|
||||
- Fixed bug with alphabetical order not working for bookmarks until the page was refreshed ([#224](https://github.com/pawelmalak/flame/issues/224))
|
||||
- Added option to change visibilty of apps, categories and bookmarks directly from table view
|
||||
- Password input will now autofocus when visiting /settings/app
|
||||
|
||||
### v2.0.1 (2021-11-19)
|
||||
- Added option to display humidity in the weather widget ([#136](https://github.com/pawelmalak/flame/issues/136))
|
||||
- Added option to set default theme for all new users ([#165](https://github.com/pawelmalak/flame/issues/165))
|
||||
|
|
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 and 15 built-in color themes
|
||||
- 🔨 Dozens of options to customize Flame interface to your needs, including support for custom CSS, 15 built-in color themes and custom theme builder
|
||||
- ☀️ 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 flame
|
||||
docker run -p 5005:5005 -v /path/to/data:/app/data -e PASSWORD=flame_password pawelmalak/flame
|
||||
```
|
||||
|
||||
#### Building images
|
||||
|
@ -55,19 +55,42 @@ docker buildx build \
|
|||
#### Docker-Compose
|
||||
|
||||
```yaml
|
||||
version: '2.1'
|
||||
version: '3.6'
|
||||
|
||||
services:
|
||||
flame:
|
||||
image: pawelmalak/flame:latest
|
||||
image: pawelmalak/flame
|
||||
container_name: flame
|
||||
volumes:
|
||||
- <host_dir>:/app/data
|
||||
- /var/run/docker.sock:/var/run/docker.sock # optional but required for Docker integration feature
|
||||
- /path/to/host/data:/app/data
|
||||
- /var/run/docker.sock:/var/run/docker.sock # optional but required for Docker integration
|
||||
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
|
||||
|
@ -212,7 +235,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,6 +22,7 @@ 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.0.1
|
||||
REACT_APP_VERSION=2.3.1
|
33592
client/package-lock.json
generated
33592
client/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -11,7 +11,6 @@
|
|||
"@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",
|
||||
|
@ -21,12 +20,11 @@
|
|||
"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": "4.0.3",
|
||||
"react-scripts": "^5.0.1",
|
||||
"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 } from './utility';
|
||||
import { checkVersion, decodeToken, parsePABToTheme } 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 } =
|
||||
const { fetchQueries, setTheme, logout, createNotification, fetchThemes } =
|
||||
bindActionCreators(actionCreators, dispath);
|
||||
|
||||
useEffect(() => {
|
||||
|
@ -51,9 +51,12 @@ export const App = (): JSX.Element => {
|
|||
}
|
||||
}, 1000);
|
||||
|
||||
// load themes
|
||||
fetchThemes();
|
||||
|
||||
// set user theme if present
|
||||
if (localStorage.theme) {
|
||||
setTheme(localStorage.theme);
|
||||
setTheme(parsePABToTheme(localStorage.theme));
|
||||
}
|
||||
|
||||
// check for updated
|
||||
|
@ -68,7 +71,7 @@ export const App = (): JSX.Element => {
|
|||
// If there is no user theme, set the default one
|
||||
useEffect(() => {
|
||||
if (!loading && !localStorage.theme) {
|
||||
setTheme(config.defaultTheme, false);
|
||||
setTheme(parsePABToTheme(config.defaultTheme), false);
|
||||
}
|
||||
}, [loading]);
|
||||
|
||||
|
|
12
client/src/components/Actions/TableActions.module.css
Normal file
12
client/src/components/Actions/TableActions.module.css
Normal file
|
@ -0,0 +1,12 @@
|
|||
.TableActions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.TableAction {
|
||||
width: 22px;
|
||||
}
|
||||
|
||||
.TableAction:hover {
|
||||
cursor: pointer;
|
||||
}
|
81
client/src/components/Actions/TableActions.tsx
Normal file
81
client/src/components/Actions/TableActions.tsx
Normal file
|
@ -0,0 +1,81 @@
|
|||
import { Icon } from '../UI';
|
||||
import classes from './TableActions.module.css';
|
||||
|
||||
interface Entity {
|
||||
id: number;
|
||||
name: string;
|
||||
isPinned?: boolean;
|
||||
isPublic: boolean;
|
||||
}
|
||||
|
||||
interface Props {
|
||||
entity: Entity;
|
||||
deleteHandler: (id: number, name: string) => void;
|
||||
updateHandler: (id: number) => void;
|
||||
pinHanlder?: (id: number) => void;
|
||||
changeVisibilty: (id: number) => void;
|
||||
showPin?: boolean;
|
||||
}
|
||||
|
||||
export const TableActions = (props: Props): JSX.Element => {
|
||||
const {
|
||||
entity,
|
||||
deleteHandler,
|
||||
updateHandler,
|
||||
pinHanlder,
|
||||
changeVisibilty,
|
||||
showPin = true,
|
||||
} = props;
|
||||
|
||||
const _pinHandler = pinHanlder || function () {};
|
||||
|
||||
return (
|
||||
<td className={classes.TableActions}>
|
||||
{/* DELETE */}
|
||||
<div
|
||||
className={classes.TableAction}
|
||||
onClick={() => deleteHandler(entity.id, entity.name)}
|
||||
tabIndex={0}
|
||||
>
|
||||
<Icon icon="mdiDelete" />
|
||||
</div>
|
||||
|
||||
{/* UPDATE */}
|
||||
<div
|
||||
className={classes.TableAction}
|
||||
onClick={() => updateHandler(entity.id)}
|
||||
tabIndex={0}
|
||||
>
|
||||
<Icon icon="mdiPencil" />
|
||||
</div>
|
||||
|
||||
{/* PIN */}
|
||||
{showPin && (
|
||||
<div
|
||||
className={classes.TableAction}
|
||||
onClick={() => _pinHandler(entity.id)}
|
||||
tabIndex={0}
|
||||
>
|
||||
{entity.isPinned ? (
|
||||
<Icon icon="mdiPinOff" color="var(--color-accent)" />
|
||||
) : (
|
||||
<Icon icon="mdiPin" />
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* VISIBILITY */}
|
||||
<div
|
||||
className={classes.TableAction}
|
||||
onClick={() => changeVisibilty(entity.id)}
|
||||
tabIndex={0}
|
||||
>
|
||||
{entity.isPublic ? (
|
||||
<Icon icon="mdiEyeOff" color="var(--color-accent)" />
|
||||
) : (
|
||||
<Icon icon="mdiEye" />
|
||||
)}
|
||||
</div>
|
||||
</td>
|
||||
);
|
||||
};
|
|
@ -8,16 +8,15 @@ import { State } from '../../../store/reducers';
|
|||
|
||||
interface Props {
|
||||
app: App;
|
||||
pinHandler?: Function;
|
||||
}
|
||||
|
||||
export const AppCard = (props: Props): JSX.Element => {
|
||||
export const AppCard = ({ app }: Props): JSX.Element => {
|
||||
const { config } = useSelector((state: State) => state.config);
|
||||
|
||||
const [displayUrl, redirectUrl] = urlParser(props.app.url);
|
||||
const [displayUrl, redirectUrl] = urlParser(app.url);
|
||||
|
||||
let iconEl: JSX.Element;
|
||||
const { icon } = props.app;
|
||||
const { icon } = app;
|
||||
|
||||
if (isImage(icon)) {
|
||||
const source = isUrl(icon) ? icon : `/uploads/${icon}`;
|
||||
|
@ -25,7 +24,7 @@ export const AppCard = (props: Props): JSX.Element => {
|
|||
iconEl = (
|
||||
<img
|
||||
src={source}
|
||||
alt={`${props.app.name} icon`}
|
||||
alt={`${app.name} icon`}
|
||||
className={classes.CustomIcon}
|
||||
/>
|
||||
);
|
||||
|
@ -54,8 +53,8 @@ export const AppCard = (props: Props): JSX.Element => {
|
|||
>
|
||||
<div className={classes.AppCardIcon}>{iconEl}</div>
|
||||
<div className={classes.AppCardDetails}>
|
||||
<h5>{props.app.name}</h5>
|
||||
<span>{displayUrl}</span>
|
||||
<h5>{app.name}</h5>
|
||||
<span>{!app.description.length ? displayUrl : app.description}</span>
|
||||
</div>
|
||||
</a>
|
||||
);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { useState, useEffect, ChangeEvent, SyntheticEvent } from 'react';
|
||||
import { useDispatch } from 'react-redux';
|
||||
import { App, NewApp } from '../../../interfaces';
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
import { NewApp } from '../../../interfaces';
|
||||
|
||||
import classes from './AppForm.module.css';
|
||||
|
||||
|
@ -8,29 +8,32 @@ import { ModalForm, InputGroup, Button } from '../../UI';
|
|||
import { inputHandler, newAppTemplate } from '../../../utility';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import { actionCreators } from '../../../store';
|
||||
import { State } from '../../../store/reducers';
|
||||
|
||||
interface Props {
|
||||
modalHandler: () => void;
|
||||
app?: App;
|
||||
}
|
||||
|
||||
export const AppForm = ({ app, modalHandler }: Props): JSX.Element => {
|
||||
export const AppForm = ({ modalHandler }: Props): JSX.Element => {
|
||||
const { appInUpdate } = useSelector((state: State) => state.apps);
|
||||
|
||||
const dispatch = useDispatch();
|
||||
const { addApp, updateApp } = bindActionCreators(actionCreators, dispatch);
|
||||
const { addApp, updateApp, setEditApp, createNotification } =
|
||||
bindActionCreators(actionCreators, dispatch);
|
||||
|
||||
const [useCustomIcon, toggleUseCustomIcon] = useState<boolean>(false);
|
||||
const [customIcon, setCustomIcon] = useState<File | null>(null);
|
||||
const [formData, setFormData] = useState<NewApp>(newAppTemplate);
|
||||
|
||||
useEffect(() => {
|
||||
if (app) {
|
||||
if (appInUpdate) {
|
||||
setFormData({
|
||||
...app,
|
||||
...appInUpdate,
|
||||
});
|
||||
} else {
|
||||
setFormData(newAppTemplate);
|
||||
}
|
||||
}, [app]);
|
||||
}, [appInUpdate]);
|
||||
|
||||
const inputChangeHandler = (
|
||||
e: ChangeEvent<HTMLInputElement | HTMLSelectElement>,
|
||||
|
@ -53,20 +56,33 @@ export const AppForm = ({ app, 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}`);
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
if (!app) {
|
||||
if (!appInUpdate) {
|
||||
if (customIcon) {
|
||||
const data = createFormData();
|
||||
addApp(data);
|
||||
|
@ -76,21 +92,22 @@ export const AppForm = ({ app, modalHandler }: Props): JSX.Element => {
|
|||
} else {
|
||||
if (customIcon) {
|
||||
const data = createFormData();
|
||||
updateApp(app.id, data);
|
||||
updateApp(appInUpdate.id, data);
|
||||
} else {
|
||||
updateApp(app.id, formData);
|
||||
updateApp(appInUpdate.id, formData);
|
||||
modalHandler();
|
||||
}
|
||||
}
|
||||
|
||||
setFormData(newAppTemplate);
|
||||
setEditApp(null);
|
||||
};
|
||||
|
||||
return (
|
||||
<ModalForm modalHandler={modalHandler} formHandler={formSubmitHandler}>
|
||||
{/* NAME */}
|
||||
<InputGroup>
|
||||
<label htmlFor="name">App Name</label>
|
||||
<label htmlFor="name">App name</label>
|
||||
<input
|
||||
type="text"
|
||||
name="name"
|
||||
|
@ -116,11 +133,27 @@ export const AppForm = ({ app, 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"
|
||||
|
@ -132,7 +165,7 @@ export const AppForm = ({ app, modalHandler }: Props): JSX.Element => {
|
|||
/>
|
||||
<span>
|
||||
Use icon name from MDI or pass a valid URL.
|
||||
<a href="https://materialdesignicons.com/" target="blank">
|
||||
<a href="https://pictogrammers.com/library/mdi/" target="blank">
|
||||
{' '}
|
||||
Click here for reference
|
||||
</a>
|
||||
|
@ -154,7 +187,7 @@ export const AppForm = ({ app, modalHandler }: Props): JSX.Element => {
|
|||
id="icon"
|
||||
required
|
||||
onChange={(e) => fileChangeHandler(e)}
|
||||
accept=".jpg,.jpeg,.png,.svg"
|
||||
accept=".jpg,.jpeg,.png,.svg,.ico"
|
||||
/>
|
||||
<span
|
||||
onClick={() => {
|
||||
|
@ -182,7 +215,7 @@ export const AppForm = ({ app, modalHandler }: Props): JSX.Element => {
|
|||
</select>
|
||||
</InputGroup>
|
||||
|
||||
{!app ? (
|
||||
{!appInUpdate ? (
|
||||
<Button>Add new application</Button>
|
||||
) : (
|
||||
<Button>Update application</Button>
|
||||
|
|
|
@ -20,21 +20,3 @@
|
|||
grid-template-columns: repeat(4, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
.GridMessage {
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.GridMessage a {
|
||||
color: var(--color-accent);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.AppsMessage {
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.AppsMessage a {
|
||||
color: var(--color-accent);
|
||||
font-weight: 600;
|
||||
}
|
|
@ -3,6 +3,7 @@ import { Link } from 'react-router-dom';
|
|||
import { App } from '../../../interfaces/App';
|
||||
|
||||
import { AppCard } from '../AppCard/AppCard';
|
||||
import { Message } from '../../UI';
|
||||
|
||||
interface Props {
|
||||
apps: App[];
|
||||
|
@ -13,36 +14,32 @@ interface Props {
|
|||
export const AppGrid = (props: Props): JSX.Element => {
|
||||
let apps: JSX.Element;
|
||||
|
||||
if (props.apps.length > 0) {
|
||||
apps = (
|
||||
<div className={classes.AppGrid}>
|
||||
{props.apps.map((app: App): JSX.Element => {
|
||||
return <AppCard key={app.id} app={app} />;
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
if (props.totalApps) {
|
||||
if (props.searching) {
|
||||
apps = (
|
||||
<p className={classes.AppsMessage}>
|
||||
No apps match your search criteria
|
||||
</p>
|
||||
);
|
||||
} else {
|
||||
apps = (
|
||||
<p className={classes.AppsMessage}>
|
||||
There are no pinned applications. You can pin them from the{' '}
|
||||
<Link to="/applications">/applications</Link> menu
|
||||
</p>
|
||||
);
|
||||
}
|
||||
if (props.searching || props.apps.length) {
|
||||
if (!props.apps.length) {
|
||||
apps = <Message>No apps match your search criteria</Message>;
|
||||
} else {
|
||||
apps = (
|
||||
<p className={classes.AppsMessage}>
|
||||
<div className={classes.AppGrid}>
|
||||
{props.apps.map((app: App): JSX.Element => {
|
||||
return <AppCard key={app.id} app={app} />;
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if (props.totalApps) {
|
||||
apps = (
|
||||
<Message>
|
||||
There are no pinned applications. You can pin them from the{' '}
|
||||
<Link to="/applications">/applications</Link> menu
|
||||
</Message>
|
||||
);
|
||||
} else {
|
||||
apps = (
|
||||
<Message>
|
||||
You don't have any applications. You can add a new one from{' '}
|
||||
<Link to="/applications">/applications</Link> menu
|
||||
</p>
|
||||
</Message>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Fragment, KeyboardEvent, useState, useEffect } from 'react';
|
||||
import { Fragment, useState, useEffect } from 'react';
|
||||
import {
|
||||
DragDropContext,
|
||||
Droppable,
|
||||
|
@ -9,21 +9,19 @@ import { Link } from 'react-router-dom';
|
|||
|
||||
// Redux
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
|
||||
// Typescript
|
||||
import { App } from '../../../interfaces';
|
||||
|
||||
// CSS
|
||||
import classes from './AppTable.module.css';
|
||||
|
||||
// UI
|
||||
import { Icon, Table } from '../../UI';
|
||||
import { State } from '../../../store/reducers';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import { actionCreators } from '../../../store';
|
||||
|
||||
// Typescript
|
||||
import { App } from '../../../interfaces';
|
||||
|
||||
// Other
|
||||
import { Message, Table } from '../../UI';
|
||||
import { TableActions } from '../../Actions/TableActions';
|
||||
|
||||
interface Props {
|
||||
updateAppHandler: (app: App) => void;
|
||||
openFormForUpdating: (app: App) => void;
|
||||
}
|
||||
|
||||
export const AppTable = (props: Props): JSX.Element => {
|
||||
|
@ -33,49 +31,18 @@ export const AppTable = (props: Props): JSX.Element => {
|
|||
} = useSelector((state: State) => state);
|
||||
|
||||
const dispatch = useDispatch();
|
||||
const { pinApp, deleteApp, reorderApps, updateConfig, createNotification } =
|
||||
const { pinApp, deleteApp, reorderApps, createNotification, updateApp } =
|
||||
bindActionCreators(actionCreators, dispatch);
|
||||
|
||||
const [localApps, setLocalApps] = useState<App[]>([]);
|
||||
const [isCustomOrder, setIsCustomOrder] = useState<boolean>(false);
|
||||
|
||||
// Copy apps array
|
||||
useEffect(() => {
|
||||
setLocalApps([...apps]);
|
||||
}, [apps]);
|
||||
|
||||
// Check ordering
|
||||
useEffect(() => {
|
||||
const order = config.useOrdering;
|
||||
|
||||
if (order === 'orderId') {
|
||||
setIsCustomOrder(true);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const deleteAppHandler = (app: App): void => {
|
||||
const proceed = window.confirm(
|
||||
`Are you sure you want to delete ${app.name} at ${app.url} ?`
|
||||
);
|
||||
|
||||
if (proceed) {
|
||||
deleteApp(app.id);
|
||||
}
|
||||
};
|
||||
|
||||
// Support keyboard navigation for actions
|
||||
const keyboardActionHandler = (
|
||||
e: KeyboardEvent,
|
||||
app: App,
|
||||
handler: Function
|
||||
) => {
|
||||
if (e.key === 'Enter') {
|
||||
handler(app);
|
||||
}
|
||||
};
|
||||
|
||||
const dragEndHanlder = (result: DropResult): void => {
|
||||
if (!isCustomOrder) {
|
||||
if (config.useOrdering !== 'orderId') {
|
||||
createNotification({
|
||||
title: 'Error',
|
||||
message: 'Custom order is disabled',
|
||||
|
@ -95,18 +62,43 @@ export const AppTable = (props: Props): JSX.Element => {
|
|||
reorderApps(tmpApps);
|
||||
};
|
||||
|
||||
// Action handlers
|
||||
const deleteAppHandler = (id: number, name: string) => {
|
||||
const proceed = window.confirm(`Are you sure you want to delete ${name}?`);
|
||||
|
||||
if (proceed) {
|
||||
deleteApp(id);
|
||||
}
|
||||
};
|
||||
|
||||
const updateAppHandler = (id: number) => {
|
||||
const app = apps.find((a) => a.id === id) as App;
|
||||
props.openFormForUpdating(app);
|
||||
};
|
||||
|
||||
const pinAppHandler = (id: number) => {
|
||||
const app = apps.find((a) => a.id === id) as App;
|
||||
pinApp(app);
|
||||
};
|
||||
|
||||
const changeAppVisibiltyHandler = (id: number) => {
|
||||
const app = apps.find((a) => a.id === id) as App;
|
||||
updateApp(id, { ...app, isPublic: !app.isPublic });
|
||||
};
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
<div className={classes.Message}>
|
||||
{isCustomOrder ? (
|
||||
<Message isPrimary={false}>
|
||||
{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{' '}
|
||||
<Link to="/settings/other">settings</Link>
|
||||
Custom order is disabled. You can change it in the{' '}
|
||||
<Link to="/settings/general">settings</Link>
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</Message>
|
||||
|
||||
<DragDropContext onDragEnd={dragEndHanlder}>
|
||||
<Droppable droppableId="apps">
|
||||
{(provided) => (
|
||||
|
@ -143,54 +135,15 @@ export const AppTable = (props: Props): JSX.Element => {
|
|||
<td style={{ width: '200px' }}>
|
||||
{app.isPublic ? 'Visible' : 'Hidden'}
|
||||
</td>
|
||||
|
||||
{!snapshot.isDragging && (
|
||||
<td className={classes.TableActions}>
|
||||
<div
|
||||
className={classes.TableAction}
|
||||
onClick={() => deleteAppHandler(app)}
|
||||
onKeyDown={(e) =>
|
||||
keyboardActionHandler(
|
||||
e,
|
||||
app,
|
||||
deleteAppHandler
|
||||
)
|
||||
}
|
||||
tabIndex={0}
|
||||
>
|
||||
<Icon icon="mdiDelete" />
|
||||
</div>
|
||||
<div
|
||||
className={classes.TableAction}
|
||||
onClick={() => props.updateAppHandler(app)}
|
||||
onKeyDown={(e) =>
|
||||
keyboardActionHandler(
|
||||
e,
|
||||
app,
|
||||
props.updateAppHandler
|
||||
)
|
||||
}
|
||||
tabIndex={0}
|
||||
>
|
||||
<Icon icon="mdiPencil" />
|
||||
</div>
|
||||
<div
|
||||
className={classes.TableAction}
|
||||
onClick={() => pinApp(app)}
|
||||
onKeyDown={(e) =>
|
||||
keyboardActionHandler(e, app, pinApp)
|
||||
}
|
||||
tabIndex={0}
|
||||
>
|
||||
{app.isPinned ? (
|
||||
<Icon
|
||||
icon="mdiPinOff"
|
||||
color="var(--color-accent)"
|
||||
/>
|
||||
) : (
|
||||
<Icon icon="mdiPin" />
|
||||
)}
|
||||
</div>
|
||||
</td>
|
||||
<TableActions
|
||||
entity={app}
|
||||
deleteHandler={deleteAppHandler}
|
||||
updateHandler={updateAppHandler}
|
||||
pinHanlder={pinAppHandler}
|
||||
changeVisibilty={changeAppVisibiltyHandler}
|
||||
/>
|
||||
)}
|
||||
</tr>
|
||||
);
|
||||
|
|
|
@ -19,7 +19,6 @@ import { AppForm } from './AppForm/AppForm';
|
|||
import { AppTable } from './AppTable/AppTable';
|
||||
|
||||
// Utils
|
||||
import { appTemplate } from '../../utility';
|
||||
import { State } from '../../store/reducers';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import { actionCreators } from '../../store';
|
||||
|
@ -29,57 +28,53 @@ interface Props {
|
|||
}
|
||||
|
||||
export const Apps = (props: Props): JSX.Element => {
|
||||
// Get Redux state
|
||||
const {
|
||||
apps: { apps, loading },
|
||||
auth: { isAuthenticated },
|
||||
} = useSelector((state: State) => state);
|
||||
|
||||
// Get Redux action creators
|
||||
const dispatch = useDispatch();
|
||||
const { getApps } = bindActionCreators(actionCreators, dispatch);
|
||||
|
||||
const [modalIsOpen, setModalIsOpen] = useState(false);
|
||||
const [isInEdit, setIsInEdit] = useState(false);
|
||||
const [isInUpdate, setIsInUpdate] = useState(false);
|
||||
const [appInUpdate, setAppInUpdate] = useState<App>(appTemplate);
|
||||
const { getApps, setEditApp } = bindActionCreators(actionCreators, dispatch);
|
||||
|
||||
// Load apps if array is empty
|
||||
useEffect(() => {
|
||||
if (!apps.length) {
|
||||
getApps();
|
||||
}
|
||||
}, []);
|
||||
|
||||
// observe if user is authenticated -> set default view if not
|
||||
// Form
|
||||
const [modalIsOpen, setModalIsOpen] = useState(false);
|
||||
const [showTable, setShowTable] = useState(false);
|
||||
|
||||
// Observe if user is authenticated -> set default view if not
|
||||
useEffect(() => {
|
||||
if (!isAuthenticated) {
|
||||
setIsInEdit(false);
|
||||
setShowTable(false);
|
||||
setModalIsOpen(false);
|
||||
}
|
||||
}, [isAuthenticated]);
|
||||
|
||||
// Form actions
|
||||
const toggleModal = (): void => {
|
||||
setModalIsOpen(!modalIsOpen);
|
||||
setIsInUpdate(false);
|
||||
};
|
||||
|
||||
const toggleEdit = (): void => {
|
||||
setIsInEdit(!isInEdit);
|
||||
setIsInUpdate(false);
|
||||
setShowTable(!showTable);
|
||||
};
|
||||
|
||||
const toggleUpdate = (app: App): void => {
|
||||
setAppInUpdate(app);
|
||||
setIsInUpdate(true);
|
||||
const openFormForUpdating = (app: App): void => {
|
||||
setEditApp(app);
|
||||
setModalIsOpen(true);
|
||||
};
|
||||
|
||||
return (
|
||||
<Container>
|
||||
<Modal isOpen={modalIsOpen} setIsOpen={setModalIsOpen}>
|
||||
{!isInUpdate ? (
|
||||
<AppForm modalHandler={toggleModal} />
|
||||
) : (
|
||||
<AppForm modalHandler={toggleModal} app={appInUpdate} />
|
||||
)}
|
||||
<AppForm modalHandler={toggleModal} />
|
||||
</Modal>
|
||||
|
||||
<Headline
|
||||
|
@ -89,7 +84,14 @@ export const Apps = (props: Props): JSX.Element => {
|
|||
|
||||
{isAuthenticated && (
|
||||
<div className={classes.ActionsContainer}>
|
||||
<ActionButton name="Add" icon="mdiPlusBox" handler={toggleModal} />
|
||||
<ActionButton
|
||||
name="Add"
|
||||
icon="mdiPlusBox"
|
||||
handler={() => {
|
||||
setEditApp(null);
|
||||
toggleModal();
|
||||
}}
|
||||
/>
|
||||
<ActionButton name="Edit" icon="mdiPencil" handler={toggleEdit} />
|
||||
</div>
|
||||
)}
|
||||
|
@ -97,10 +99,10 @@ export const Apps = (props: Props): JSX.Element => {
|
|||
<div className={classes.Apps}>
|
||||
{loading ? (
|
||||
<Spinner />
|
||||
) : !isInEdit ? (
|
||||
) : !showTable ? (
|
||||
<AppGrid apps={apps} searching={props.searching} />
|
||||
) : (
|
||||
<AppTable updateAppHandler={toggleUpdate} />
|
||||
<AppTable openFormForUpdating={openFormForUpdating} />
|
||||
)}
|
||||
</div>
|
||||
</Container>
|
||||
|
|
|
@ -10,6 +10,10 @@
|
|||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.BookmarkHeader:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.Bookmarks {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
|
|
@ -1,28 +1,52 @@
|
|||
import { Fragment } from 'react';
|
||||
|
||||
import { useSelector } from 'react-redux';
|
||||
// Redux
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
import { State } from '../../../store/reducers';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import { actionCreators } from '../../../store';
|
||||
|
||||
// Typescript
|
||||
import { Bookmark, Category } from '../../../interfaces';
|
||||
|
||||
// Other
|
||||
import classes from './BookmarkCard.module.css';
|
||||
|
||||
import { Icon } from '../../UI';
|
||||
|
||||
import { iconParser, isImage, isSvg, isUrl, urlParser } from '../../../utility';
|
||||
|
||||
interface Props {
|
||||
category: Category;
|
||||
fromHomepage?: boolean;
|
||||
}
|
||||
|
||||
export const BookmarkCard = (props: Props): JSX.Element => {
|
||||
const { config } = useSelector((state: State) => state.config);
|
||||
const { category, fromHomepage = false } = props;
|
||||
|
||||
const {
|
||||
config: { config },
|
||||
auth: { isAuthenticated },
|
||||
} = useSelector((state: State) => state);
|
||||
|
||||
const dispatch = useDispatch();
|
||||
const { setEditCategory } = bindActionCreators(actionCreators, dispatch);
|
||||
|
||||
return (
|
||||
<div className={classes.BookmarkCard}>
|
||||
<h3>{props.category.name}</h3>
|
||||
<h3
|
||||
className={
|
||||
fromHomepage || !isAuthenticated ? '' : classes.BookmarkHeader
|
||||
}
|
||||
onClick={() => {
|
||||
if (!fromHomepage && isAuthenticated) {
|
||||
setEditCategory(category);
|
||||
}
|
||||
}}
|
||||
>
|
||||
{category.name}
|
||||
</h3>
|
||||
|
||||
<div className={classes.Bookmarks}>
|
||||
{props.category.bookmarks.map((bookmark: Bookmark) => {
|
||||
{category.bookmarks.map((bookmark: Bookmark) => {
|
||||
const redirectUrl = urlParser(bookmark.url)[1];
|
||||
|
||||
let iconEl: JSX.Element = <Fragment></Fragment>;
|
||||
|
|
|
@ -20,12 +20,3 @@
|
|||
grid-template-columns: repeat(4, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
.BookmarksMessage {
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.BookmarksMessage a {
|
||||
color: var(--color-accent);
|
||||
font-weight: 600;
|
||||
}
|
|
@ -5,48 +5,57 @@ import classes from './BookmarkGrid.module.css';
|
|||
import { Category } from '../../../interfaces';
|
||||
|
||||
import { BookmarkCard } from '../BookmarkCard/BookmarkCard';
|
||||
import { Message } from '../../UI';
|
||||
|
||||
interface Props {
|
||||
categories: Category[];
|
||||
totalCategories?: number;
|
||||
searching: boolean;
|
||||
fromHomepage?: boolean;
|
||||
}
|
||||
|
||||
export const BookmarkGrid = (props: Props): JSX.Element => {
|
||||
const {
|
||||
categories,
|
||||
totalCategories,
|
||||
searching,
|
||||
fromHomepage = false,
|
||||
} = props;
|
||||
|
||||
let bookmarks: JSX.Element;
|
||||
|
||||
if (props.categories.length) {
|
||||
if (props.searching && !props.categories[0].bookmarks.length) {
|
||||
bookmarks = (
|
||||
<p className={classes.BookmarksMessage}>
|
||||
No bookmarks match your search criteria
|
||||
</p>
|
||||
);
|
||||
if (categories.length) {
|
||||
if (searching && !categories[0].bookmarks.length) {
|
||||
bookmarks = <Message>No bookmarks match your search criteria</Message>;
|
||||
} else {
|
||||
bookmarks = (
|
||||
<div className={classes.BookmarkGrid}>
|
||||
{props.categories.map(
|
||||
{categories.map(
|
||||
(category: Category): JSX.Element => (
|
||||
<BookmarkCard category={category} key={category.id} />
|
||||
<BookmarkCard
|
||||
category={category}
|
||||
fromHomepage={fromHomepage}
|
||||
key={category.id}
|
||||
/>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if (props.totalCategories) {
|
||||
if (totalCategories) {
|
||||
bookmarks = (
|
||||
<p className={classes.BookmarksMessage}>
|
||||
<Message>
|
||||
There are no pinned categories. You can pin them from the{' '}
|
||||
<Link to="/bookmarks">/bookmarks</Link> menu
|
||||
</p>
|
||||
</Message>
|
||||
);
|
||||
} else {
|
||||
bookmarks = (
|
||||
<p className={classes.BookmarksMessage}>
|
||||
<Message>
|
||||
You don't have any bookmarks. You can add a new one from{' '}
|
||||
<Link to="/bookmarks">/bookmarks</Link> menu
|
||||
</p>
|
||||
</Message>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
.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;
|
||||
}
|
|
@ -1,272 +0,0 @@
|
|||
import { KeyboardEvent, useState, useEffect, Fragment } from 'react';
|
||||
import {
|
||||
DragDropContext,
|
||||
Droppable,
|
||||
Draggable,
|
||||
DropResult,
|
||||
} from 'react-beautiful-dnd';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
// Redux
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
import { State } from '../../../store/reducers';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import { actionCreators } from '../../../store';
|
||||
|
||||
// Typescript
|
||||
import { Bookmark, Category } from '../../../interfaces';
|
||||
import { ContentType } from '../Bookmarks';
|
||||
|
||||
// CSS
|
||||
import classes from './BookmarkTable.module.css';
|
||||
|
||||
// UI
|
||||
import { Table, Icon } from '../../UI';
|
||||
|
||||
interface Props {
|
||||
contentType: ContentType;
|
||||
categories: Category[];
|
||||
updateHandler: (data: Category | Bookmark) => void;
|
||||
}
|
||||
|
||||
export const BookmarkTable = (props: Props): JSX.Element => {
|
||||
const { config } = useSelector((state: State) => state.config);
|
||||
|
||||
const dispatch = useDispatch();
|
||||
const {
|
||||
pinCategory,
|
||||
deleteCategory,
|
||||
deleteBookmark,
|
||||
createNotification,
|
||||
reorderCategories,
|
||||
} = bindActionCreators(actionCreators, dispatch);
|
||||
|
||||
const [localCategories, setLocalCategories] = useState<Category[]>([]);
|
||||
const [isCustomOrder, setIsCustomOrder] = useState<boolean>(false);
|
||||
|
||||
// Copy categories array
|
||||
useEffect(() => {
|
||||
setLocalCategories([...props.categories]);
|
||||
}, [props.categories]);
|
||||
|
||||
// Check ordering
|
||||
useEffect(() => {
|
||||
const order = config.useOrdering;
|
||||
|
||||
if (order === 'orderId') {
|
||||
setIsCustomOrder(true);
|
||||
}
|
||||
});
|
||||
|
||||
const deleteCategoryHandler = (category: Category): void => {
|
||||
const proceed = window.confirm(
|
||||
`Are you sure you want to delete ${category.name}? It will delete ALL assigned bookmarks`
|
||||
);
|
||||
|
||||
if (proceed) {
|
||||
deleteCategory(category.id);
|
||||
}
|
||||
};
|
||||
|
||||
const deleteBookmarkHandler = (bookmark: Bookmark): void => {
|
||||
const proceed = window.confirm(
|
||||
`Are you sure you want to delete ${bookmark.name}?`
|
||||
);
|
||||
|
||||
if (proceed) {
|
||||
deleteBookmark(bookmark.id, bookmark.categoryId);
|
||||
}
|
||||
};
|
||||
|
||||
const keyboardActionHandler = (
|
||||
e: KeyboardEvent,
|
||||
category: Category,
|
||||
handler: Function
|
||||
) => {
|
||||
if (e.key === 'Enter') {
|
||||
handler(category);
|
||||
}
|
||||
};
|
||||
|
||||
const dragEndHanlder = (result: DropResult): void => {
|
||||
if (!isCustomOrder) {
|
||||
createNotification({
|
||||
title: 'Error',
|
||||
message: 'Custom order is disabled',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!result.destination) {
|
||||
return;
|
||||
}
|
||||
|
||||
const tmpCategories = [...localCategories];
|
||||
const [movedApp] = tmpCategories.splice(result.source.index, 1);
|
||||
tmpCategories.splice(result.destination.index, 0, movedApp);
|
||||
|
||||
setLocalCategories(tmpCategories);
|
||||
reorderCategories(tmpCategories);
|
||||
};
|
||||
|
||||
if (props.contentType === ContentType.category) {
|
||||
return (
|
||||
<Fragment>
|
||||
<div className={classes.Message}>
|
||||
{isCustomOrder ? (
|
||||
<p>You can drag and drop single rows to reorder categories</p>
|
||||
) : (
|
||||
<p>
|
||||
Custom order is disabled. You can change it in{' '}
|
||||
<Link to="/settings/other">settings</Link>
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
<DragDropContext onDragEnd={dragEndHanlder}>
|
||||
<Droppable droppableId="categories">
|
||||
{(provided) => (
|
||||
<Table
|
||||
headers={['Name', 'Visibility', 'Actions']}
|
||||
innerRef={provided.innerRef}
|
||||
>
|
||||
{localCategories.map(
|
||||
(category: Category, index): JSX.Element => {
|
||||
return (
|
||||
<Draggable
|
||||
key={category.id}
|
||||
draggableId={category.id.toString()}
|
||||
index={index}
|
||||
>
|
||||
{(provided, snapshot) => {
|
||||
const style = {
|
||||
border: snapshot.isDragging
|
||||
? '1px solid var(--color-accent)'
|
||||
: 'none',
|
||||
borderRadius: '4px',
|
||||
...provided.draggableProps.style,
|
||||
};
|
||||
|
||||
return (
|
||||
<tr
|
||||
{...provided.draggableProps}
|
||||
{...provided.dragHandleProps}
|
||||
ref={provided.innerRef}
|
||||
style={style}
|
||||
>
|
||||
<td style={{ width: '300px' }}>
|
||||
{category.name}
|
||||
</td>
|
||||
<td style={{ width: '300px' }}>
|
||||
{category.isPublic ? 'Visible' : 'Hidden'}
|
||||
</td>
|
||||
{!snapshot.isDragging && (
|
||||
<td className={classes.TableActions}>
|
||||
<div
|
||||
className={classes.TableAction}
|
||||
onClick={() =>
|
||||
deleteCategoryHandler(category)
|
||||
}
|
||||
onKeyDown={(e) =>
|
||||
keyboardActionHandler(
|
||||
e,
|
||||
category,
|
||||
deleteCategoryHandler
|
||||
)
|
||||
}
|
||||
tabIndex={0}
|
||||
>
|
||||
<Icon icon="mdiDelete" />
|
||||
</div>
|
||||
<div
|
||||
className={classes.TableAction}
|
||||
onClick={() =>
|
||||
props.updateHandler(category)
|
||||
}
|
||||
tabIndex={0}
|
||||
>
|
||||
<Icon icon="mdiPencil" />
|
||||
</div>
|
||||
<div
|
||||
className={classes.TableAction}
|
||||
onClick={() => pinCategory(category)}
|
||||
onKeyDown={(e) =>
|
||||
keyboardActionHandler(
|
||||
e,
|
||||
category,
|
||||
pinCategory
|
||||
)
|
||||
}
|
||||
tabIndex={0}
|
||||
>
|
||||
{category.isPinned ? (
|
||||
<Icon
|
||||
icon="mdiPinOff"
|
||||
color="var(--color-accent)"
|
||||
/>
|
||||
) : (
|
||||
<Icon icon="mdiPin" />
|
||||
)}
|
||||
</div>
|
||||
</td>
|
||||
)}
|
||||
</tr>
|
||||
);
|
||||
}}
|
||||
</Draggable>
|
||||
);
|
||||
}
|
||||
)}
|
||||
</Table>
|
||||
)}
|
||||
</Droppable>
|
||||
</DragDropContext>
|
||||
</Fragment>
|
||||
);
|
||||
} else {
|
||||
const bookmarks: { bookmark: Bookmark; categoryName: string }[] = [];
|
||||
props.categories.forEach((category: Category) => {
|
||||
category.bookmarks.forEach((bookmark: Bookmark) => {
|
||||
bookmarks.push({
|
||||
bookmark,
|
||||
categoryName: category.name,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
return (
|
||||
<Table
|
||||
headers={['Name', 'URL', 'Icon', 'Visibility', 'Category', 'Actions']}
|
||||
>
|
||||
{bookmarks.map(
|
||||
(bookmark: { bookmark: Bookmark; categoryName: string }) => {
|
||||
return (
|
||||
<tr key={bookmark.bookmark.id}>
|
||||
<td>{bookmark.bookmark.name}</td>
|
||||
<td>{bookmark.bookmark.url}</td>
|
||||
<td>{bookmark.bookmark.icon}</td>
|
||||
<td>{bookmark.bookmark.isPublic ? 'Visible' : 'Hidden'}</td>
|
||||
<td>{bookmark.categoryName}</td>
|
||||
<td className={classes.TableActions}>
|
||||
<div
|
||||
className={classes.TableAction}
|
||||
onClick={() => deleteBookmarkHandler(bookmark.bookmark)}
|
||||
tabIndex={0}
|
||||
>
|
||||
<Icon icon="mdiDelete" />
|
||||
</div>
|
||||
<div
|
||||
className={classes.TableAction}
|
||||
onClick={() => props.updateHandler(bookmark.bookmark)}
|
||||
tabIndex={0}
|
||||
>
|
||||
<Icon icon="mdiPencil" />
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
}
|
||||
)}
|
||||
</Table>
|
||||
);
|
||||
}
|
||||
};
|
|
@ -14,15 +14,19 @@ import { Category, Bookmark } from '../../interfaces';
|
|||
import classes from './Bookmarks.module.css';
|
||||
|
||||
// UI
|
||||
import { Container, Headline, ActionButton, Spinner, Modal } from '../UI';
|
||||
import {
|
||||
Container,
|
||||
Headline,
|
||||
ActionButton,
|
||||
Spinner,
|
||||
Modal,
|
||||
Message,
|
||||
} from '../UI';
|
||||
|
||||
// Components
|
||||
import { BookmarkGrid } from './BookmarkGrid/BookmarkGrid';
|
||||
import { BookmarkTable } from './BookmarkTable/BookmarkTable';
|
||||
import { Form } from './Form/Form';
|
||||
|
||||
// Utils
|
||||
import { bookmarkTemplate, categoryTemplate } from '../../utility';
|
||||
import { Table } from './Table/Table';
|
||||
|
||||
interface Props {
|
||||
searching: boolean;
|
||||
|
@ -34,74 +38,99 @@ export enum ContentType {
|
|||
}
|
||||
|
||||
export const Bookmarks = (props: Props): JSX.Element => {
|
||||
// Get Redux state
|
||||
const {
|
||||
bookmarks: { loading, categories },
|
||||
bookmarks: { loading, categories, categoryInEdit },
|
||||
auth: { isAuthenticated },
|
||||
} = useSelector((state: State) => state);
|
||||
|
||||
// Get Redux action creators
|
||||
const dispatch = useDispatch();
|
||||
const { getCategories } = bindActionCreators(actionCreators, dispatch);
|
||||
|
||||
const [modalIsOpen, setModalIsOpen] = useState(false);
|
||||
const [formContentType, setFormContentType] = useState(ContentType.category);
|
||||
const [isInEdit, setIsInEdit] = useState(false);
|
||||
const [tableContentType, setTableContentType] = useState(
|
||||
ContentType.category
|
||||
);
|
||||
const [isInUpdate, setIsInUpdate] = useState(false);
|
||||
const [categoryInUpdate, setCategoryInUpdate] =
|
||||
useState<Category>(categoryTemplate);
|
||||
const [bookmarkInUpdate, setBookmarkInUpdate] =
|
||||
useState<Bookmark>(bookmarkTemplate);
|
||||
const { getCategories, setEditCategory, setEditBookmark } =
|
||||
bindActionCreators(actionCreators, dispatch);
|
||||
|
||||
// Load categories if array is empty
|
||||
useEffect(() => {
|
||||
if (!categories.length) {
|
||||
getCategories();
|
||||
}
|
||||
}, []);
|
||||
|
||||
// observe if user is authenticated -> set default view if not
|
||||
// Form
|
||||
const [modalIsOpen, setModalIsOpen] = useState(false);
|
||||
const [formContentType, setFormContentType] = useState(ContentType.category);
|
||||
const [isInUpdate, setIsInUpdate] = useState(false);
|
||||
|
||||
// Table
|
||||
const [showTable, setShowTable] = useState(false);
|
||||
const [tableContentType, setTableContentType] = useState(
|
||||
ContentType.category
|
||||
);
|
||||
|
||||
// Observe if user is authenticated -> set default view (grid) if not
|
||||
useEffect(() => {
|
||||
if (!isAuthenticated) {
|
||||
setIsInEdit(false);
|
||||
setShowTable(false);
|
||||
setModalIsOpen(false);
|
||||
}
|
||||
}, [isAuthenticated]);
|
||||
|
||||
useEffect(() => {
|
||||
if (categoryInEdit && !modalIsOpen) {
|
||||
setTableContentType(ContentType.bookmark);
|
||||
setShowTable(true);
|
||||
}
|
||||
}, [categoryInEdit]);
|
||||
|
||||
useEffect(() => {
|
||||
setShowTable(false);
|
||||
setEditCategory(null);
|
||||
}, []);
|
||||
|
||||
// Form actions
|
||||
const toggleModal = (): void => {
|
||||
setModalIsOpen(!modalIsOpen);
|
||||
};
|
||||
|
||||
const addActionHandler = (contentType: ContentType) => {
|
||||
const openFormForAdding = (contentType: ContentType) => {
|
||||
setFormContentType(contentType);
|
||||
setIsInUpdate(false);
|
||||
toggleModal();
|
||||
};
|
||||
|
||||
const editActionHandler = (contentType: ContentType) => {
|
||||
// We're in the edit mode and the same button was clicked - go back to list
|
||||
if (isInEdit && contentType === tableContentType) {
|
||||
setIsInEdit(false);
|
||||
const openFormForUpdating = (data: Category | Bookmark): void => {
|
||||
setIsInUpdate(true);
|
||||
|
||||
const instanceOfCategory = (object: any): object is Category => {
|
||||
return 'bookmarks' in object;
|
||||
};
|
||||
|
||||
if (instanceOfCategory(data)) {
|
||||
setFormContentType(ContentType.category);
|
||||
setEditCategory(data);
|
||||
} else {
|
||||
setIsInEdit(true);
|
||||
setFormContentType(ContentType.bookmark);
|
||||
setEditBookmark(data);
|
||||
}
|
||||
|
||||
toggleModal();
|
||||
};
|
||||
|
||||
// Table actions
|
||||
const showTableForEditing = (contentType: ContentType) => {
|
||||
// We're in the edit mode and the same button was clicked - go back to list
|
||||
if (showTable && contentType === tableContentType) {
|
||||
setEditCategory(null);
|
||||
setShowTable(false);
|
||||
} else {
|
||||
setShowTable(true);
|
||||
setTableContentType(contentType);
|
||||
}
|
||||
};
|
||||
|
||||
const instanceOfCategory = (object: any): object is Category => {
|
||||
return 'bookmarks' in object;
|
||||
};
|
||||
|
||||
const goToUpdateMode = (data: Category | Bookmark): void => {
|
||||
setIsInUpdate(true);
|
||||
if (instanceOfCategory(data)) {
|
||||
setFormContentType(ContentType.category);
|
||||
setCategoryInUpdate(data);
|
||||
} else {
|
||||
setFormContentType(ContentType.bookmark);
|
||||
setBookmarkInUpdate(data);
|
||||
}
|
||||
toggleModal();
|
||||
const finishEditing = () => {
|
||||
setShowTable(false);
|
||||
setEditCategory(null);
|
||||
};
|
||||
|
||||
return (
|
||||
|
@ -111,8 +140,6 @@ export const Bookmarks = (props: Props): JSX.Element => {
|
|||
modalHandler={toggleModal}
|
||||
contentType={formContentType}
|
||||
inUpdate={isInUpdate}
|
||||
category={categoryInUpdate}
|
||||
bookmark={bookmarkInUpdate}
|
||||
/>
|
||||
</Modal>
|
||||
|
||||
|
@ -123,35 +150,44 @@ export const Bookmarks = (props: Props): JSX.Element => {
|
|||
<ActionButton
|
||||
name="Add Category"
|
||||
icon="mdiPlusBox"
|
||||
handler={() => addActionHandler(ContentType.category)}
|
||||
handler={() => openFormForAdding(ContentType.category)}
|
||||
/>
|
||||
<ActionButton
|
||||
name="Add Bookmark"
|
||||
icon="mdiPlusBox"
|
||||
handler={() => addActionHandler(ContentType.bookmark)}
|
||||
handler={() => openFormForAdding(ContentType.bookmark)}
|
||||
/>
|
||||
<ActionButton
|
||||
name="Edit Categories"
|
||||
icon="mdiPencil"
|
||||
handler={() => editActionHandler(ContentType.category)}
|
||||
/>
|
||||
<ActionButton
|
||||
name="Edit Bookmarks"
|
||||
icon="mdiPencil"
|
||||
handler={() => editActionHandler(ContentType.bookmark)}
|
||||
handler={() => showTableForEditing(ContentType.category)}
|
||||
/>
|
||||
{showTable && tableContentType === ContentType.bookmark && (
|
||||
<ActionButton
|
||||
name="Finish Editing"
|
||||
icon="mdiPencil"
|
||||
handler={finishEditing}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{categories.length && isAuthenticated && !showTable ? (
|
||||
<Message isPrimary={false}>
|
||||
Click on category name to edit its bookmarks
|
||||
</Message>
|
||||
) : (
|
||||
<></>
|
||||
)}
|
||||
|
||||
{loading ? (
|
||||
<Spinner />
|
||||
) : !isInEdit ? (
|
||||
) : !showTable ? (
|
||||
<BookmarkGrid categories={categories} searching={props.searching} />
|
||||
) : (
|
||||
<BookmarkTable
|
||||
<Table
|
||||
contentType={tableContentType}
|
||||
categories={categories}
|
||||
updateHandler={goToUpdateMode}
|
||||
openFormForUpdating={openFormForUpdating}
|
||||
/>
|
||||
)}
|
||||
</Container>
|
||||
|
|
|
@ -69,6 +69,17 @@ 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) {
|
||||
|
@ -137,15 +148,15 @@ export const BookmarksForm = ({
|
|||
}
|
||||
|
||||
modalHandler();
|
||||
|
||||
setFormData(newBookmarkTemplate);
|
||||
|
||||
setCustomIcon(null);
|
||||
}
|
||||
|
||||
setFormData({ ...newBookmarkTemplate, categoryId: formData.categoryId });
|
||||
setCustomIcon(null);
|
||||
};
|
||||
|
||||
return (
|
||||
<ModalForm modalHandler={modalHandler} formHandler={formSubmitHandler}>
|
||||
{/* NAME */}
|
||||
<InputGroup>
|
||||
<label htmlFor="name">Bookmark Name</label>
|
||||
<input
|
||||
|
@ -159,6 +170,7 @@ export const BookmarksForm = ({
|
|||
/>
|
||||
</InputGroup>
|
||||
|
||||
{/* URL */}
|
||||
<InputGroup>
|
||||
<label htmlFor="url">Bookmark URL</label>
|
||||
<input
|
||||
|
@ -172,6 +184,7 @@ export const BookmarksForm = ({
|
|||
/>
|
||||
</InputGroup>
|
||||
|
||||
{/* CATEGORY */}
|
||||
<InputGroup>
|
||||
<label htmlFor="categoryId">Bookmark Category</label>
|
||||
<select
|
||||
|
@ -192,6 +205,7 @@ export const BookmarksForm = ({
|
|||
</select>
|
||||
</InputGroup>
|
||||
|
||||
{/* ICON */}
|
||||
{!useCustomIcon ? (
|
||||
// mdi
|
||||
<InputGroup>
|
||||
|
@ -227,7 +241,7 @@ export const BookmarksForm = ({
|
|||
name="icon"
|
||||
id="icon"
|
||||
onChange={(e) => fileChangeHandler(e)}
|
||||
accept=".jpg,.jpeg,.png,.svg"
|
||||
accept=".jpg,.jpeg,.png,.svg,.ico"
|
||||
/>
|
||||
<span
|
||||
onClick={() => {
|
||||
|
@ -241,6 +255,7 @@ export const BookmarksForm = ({
|
|||
</InputGroup>
|
||||
)}
|
||||
|
||||
{/* VISIBILTY */}
|
||||
<InputGroup>
|
||||
<label htmlFor="isPublic">Bookmark visibility</label>
|
||||
<select
|
||||
|
|
|
@ -60,10 +60,10 @@ export const CategoryForm = ({
|
|||
addCategory(formData);
|
||||
} else {
|
||||
updateCategory(category.id, formData);
|
||||
modalHandler();
|
||||
}
|
||||
|
||||
setFormData(newCategoryTemplate);
|
||||
modalHandler();
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
|
@ -1,22 +1,26 @@
|
|||
// Typescript
|
||||
import { Bookmark, Category } from '../../../interfaces';
|
||||
import { ContentType } from '../Bookmarks';
|
||||
|
||||
// Utils
|
||||
import { CategoryForm } from './CategoryForm';
|
||||
import { BookmarksForm } from './BookmarksForm';
|
||||
import { Fragment } from 'react';
|
||||
import { useSelector } from 'react-redux';
|
||||
import { State } from '../../../store/reducers';
|
||||
import { bookmarkTemplate, categoryTemplate } from '../../../utility';
|
||||
|
||||
interface Props {
|
||||
modalHandler: () => void;
|
||||
contentType: ContentType;
|
||||
inUpdate?: boolean;
|
||||
category?: Category;
|
||||
bookmark?: Bookmark;
|
||||
}
|
||||
|
||||
export const Form = (props: Props): JSX.Element => {
|
||||
const { modalHandler, contentType, inUpdate, category, bookmark } = props;
|
||||
const { categoryInEdit, bookmarkInEdit } = useSelector(
|
||||
(state: State) => state.bookmarks
|
||||
);
|
||||
|
||||
const { modalHandler, contentType, inUpdate } = props;
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
|
@ -33,9 +37,15 @@ export const Form = (props: Props): JSX.Element => {
|
|||
// form: update
|
||||
<Fragment>
|
||||
{contentType === ContentType.category ? (
|
||||
<CategoryForm modalHandler={modalHandler} category={category} />
|
||||
<CategoryForm
|
||||
modalHandler={modalHandler}
|
||||
category={categoryInEdit || categoryTemplate}
|
||||
/>
|
||||
) : (
|
||||
<BookmarksForm modalHandler={modalHandler} bookmark={bookmark} />
|
||||
<BookmarksForm
|
||||
modalHandler={modalHandler}
|
||||
bookmark={bookmarkInEdit || bookmarkTemplate}
|
||||
/>
|
||||
)}
|
||||
</Fragment>
|
||||
)}
|
||||
|
|
188
client/src/components/Bookmarks/Table/BookmarksTable.tsx
Normal file
188
client/src/components/Bookmarks/Table/BookmarksTable.tsx
Normal file
|
@ -0,0 +1,188 @@
|
|||
import { useState, useEffect, Fragment } from 'react';
|
||||
import {
|
||||
DragDropContext,
|
||||
Droppable,
|
||||
Draggable,
|
||||
DropResult,
|
||||
} from 'react-beautiful-dnd';
|
||||
|
||||
// Redux
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
import { State } from '../../../store/reducers';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import { actionCreators } from '../../../store';
|
||||
|
||||
// Typescript
|
||||
import { Bookmark, Category } from '../../../interfaces';
|
||||
|
||||
// UI
|
||||
import { Message, Table } from '../../UI';
|
||||
import { TableActions } from '../../Actions/TableActions';
|
||||
import { bookmarkTemplate } from '../../../utility';
|
||||
|
||||
interface Props {
|
||||
openFormForUpdating: (data: Category | Bookmark) => void;
|
||||
}
|
||||
|
||||
export const BookmarksTable = ({ openFormForUpdating }: Props): JSX.Element => {
|
||||
const {
|
||||
bookmarks: { categoryInEdit },
|
||||
config: { config },
|
||||
} = useSelector((state: State) => state);
|
||||
|
||||
const dispatch = useDispatch();
|
||||
const {
|
||||
deleteBookmark,
|
||||
updateBookmark,
|
||||
createNotification,
|
||||
reorderBookmarks,
|
||||
} = bindActionCreators(actionCreators, dispatch);
|
||||
|
||||
const [localBookmarks, setLocalBookmarks] = useState<Bookmark[]>([]);
|
||||
|
||||
// Copy bookmarks array
|
||||
useEffect(() => {
|
||||
if (categoryInEdit) {
|
||||
setLocalBookmarks([...categoryInEdit.bookmarks]);
|
||||
}
|
||||
}, [categoryInEdit]);
|
||||
|
||||
// Drag and drop handler
|
||||
const dragEndHanlder = (result: DropResult): void => {
|
||||
if (config.useOrdering !== 'orderId') {
|
||||
createNotification({
|
||||
title: 'Error',
|
||||
message: 'Custom order is disabled',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!result.destination) {
|
||||
return;
|
||||
}
|
||||
|
||||
const tmpBookmarks = [...localBookmarks];
|
||||
const [movedBookmark] = tmpBookmarks.splice(result.source.index, 1);
|
||||
tmpBookmarks.splice(result.destination.index, 0, movedBookmark);
|
||||
|
||||
setLocalBookmarks(tmpBookmarks);
|
||||
|
||||
const categoryId = categoryInEdit?.id || -1;
|
||||
reorderBookmarks(tmpBookmarks, categoryId);
|
||||
};
|
||||
|
||||
// Action hanlders
|
||||
const deleteBookmarkHandler = (id: number, name: string) => {
|
||||
const categoryId = categoryInEdit?.id || -1;
|
||||
|
||||
const proceed = window.confirm(`Are you sure you want to delete ${name}?`);
|
||||
if (proceed) {
|
||||
deleteBookmark(id, categoryId);
|
||||
}
|
||||
};
|
||||
|
||||
const updateBookmarkHandler = (id: number) => {
|
||||
const bookmark =
|
||||
categoryInEdit?.bookmarks.find((b) => b.id === id) || bookmarkTemplate;
|
||||
|
||||
openFormForUpdating(bookmark);
|
||||
};
|
||||
|
||||
const changeBookmarkVisibiltyHandler = (id: number) => {
|
||||
const bookmark =
|
||||
categoryInEdit?.bookmarks.find((b) => b.id === id) || bookmarkTemplate;
|
||||
|
||||
const categoryId = categoryInEdit?.id || -1;
|
||||
const [prev, curr] = [categoryId, categoryId];
|
||||
|
||||
updateBookmark(
|
||||
id,
|
||||
{ ...bookmark, isPublic: !bookmark.isPublic },
|
||||
{ prev, curr }
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
{!categoryInEdit ? (
|
||||
<Message isPrimary={false}>
|
||||
Switch to grid view and click on the name of category you want to edit
|
||||
</Message>
|
||||
) : (
|
||||
<Message isPrimary={false}>
|
||||
Editing bookmarks from <span>{categoryInEdit.name}</span>
|
||||
category
|
||||
</Message>
|
||||
)}
|
||||
|
||||
{categoryInEdit && (
|
||||
<DragDropContext onDragEnd={dragEndHanlder}>
|
||||
<Droppable droppableId="bookmarks">
|
||||
{(provided) => (
|
||||
<Table
|
||||
headers={[
|
||||
'Name',
|
||||
'URL',
|
||||
'Icon',
|
||||
'Visibility',
|
||||
'Category',
|
||||
'Actions',
|
||||
]}
|
||||
innerRef={provided.innerRef}
|
||||
>
|
||||
{localBookmarks.map((bookmark, index): JSX.Element => {
|
||||
return (
|
||||
<Draggable
|
||||
key={bookmark.id}
|
||||
draggableId={bookmark.id.toString()}
|
||||
index={index}
|
||||
>
|
||||
{(provided, snapshot) => {
|
||||
const style = {
|
||||
border: snapshot.isDragging
|
||||
? '1px solid var(--color-accent)'
|
||||
: 'none',
|
||||
borderRadius: '4px',
|
||||
...provided.draggableProps.style,
|
||||
};
|
||||
|
||||
return (
|
||||
<tr
|
||||
{...provided.draggableProps}
|
||||
{...provided.dragHandleProps}
|
||||
ref={provided.innerRef}
|
||||
style={style}
|
||||
>
|
||||
<td style={{ width: '200px' }}>{bookmark.name}</td>
|
||||
<td style={{ width: '200px' }}>{bookmark.url}</td>
|
||||
<td style={{ width: '200px' }}>{bookmark.icon}</td>
|
||||
<td style={{ width: '200px' }}>
|
||||
{bookmark.isPublic ? 'Visible' : 'Hidden'}
|
||||
</td>
|
||||
<td style={{ width: '200px' }}>
|
||||
{categoryInEdit.name}
|
||||
</td>
|
||||
|
||||
{!snapshot.isDragging && (
|
||||
<TableActions
|
||||
entity={bookmark}
|
||||
deleteHandler={deleteBookmarkHandler}
|
||||
updateHandler={updateBookmarkHandler}
|
||||
changeVisibilty={changeBookmarkVisibiltyHandler}
|
||||
showPin={false}
|
||||
/>
|
||||
)}
|
||||
</tr>
|
||||
);
|
||||
}}
|
||||
</Draggable>
|
||||
);
|
||||
})}
|
||||
</Table>
|
||||
)}
|
||||
</Droppable>
|
||||
</DragDropContext>
|
||||
)}
|
||||
</Fragment>
|
||||
);
|
||||
};
|
166
client/src/components/Bookmarks/Table/CategoryTable.tsx
Normal file
166
client/src/components/Bookmarks/Table/CategoryTable.tsx
Normal file
|
@ -0,0 +1,166 @@
|
|||
import { useState, useEffect, Fragment } from 'react';
|
||||
import {
|
||||
DragDropContext,
|
||||
Droppable,
|
||||
Draggable,
|
||||
DropResult,
|
||||
} from 'react-beautiful-dnd';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
// Redux
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
import { State } from '../../../store/reducers';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import { actionCreators } from '../../../store';
|
||||
|
||||
// Typescript
|
||||
import { Bookmark, Category } from '../../../interfaces';
|
||||
|
||||
// UI
|
||||
import { Message, Table } from '../../UI';
|
||||
import { TableActions } from '../../Actions/TableActions';
|
||||
|
||||
interface Props {
|
||||
openFormForUpdating: (data: Category | Bookmark) => void;
|
||||
}
|
||||
|
||||
export const CategoryTable = ({ openFormForUpdating }: Props): JSX.Element => {
|
||||
const {
|
||||
config: { config },
|
||||
bookmarks: { categories },
|
||||
} = useSelector((state: State) => state);
|
||||
|
||||
const dispatch = useDispatch();
|
||||
const {
|
||||
pinCategory,
|
||||
deleteCategory,
|
||||
createNotification,
|
||||
reorderCategories,
|
||||
updateCategory,
|
||||
} = bindActionCreators(actionCreators, dispatch);
|
||||
|
||||
const [localCategories, setLocalCategories] = useState<Category[]>([]);
|
||||
|
||||
// Copy categories array
|
||||
useEffect(() => {
|
||||
setLocalCategories([...categories]);
|
||||
}, [categories]);
|
||||
|
||||
// Drag and drop handler
|
||||
const dragEndHanlder = (result: DropResult): void => {
|
||||
if (config.useOrdering !== 'orderId') {
|
||||
createNotification({
|
||||
title: 'Error',
|
||||
message: 'Custom order is disabled',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!result.destination) {
|
||||
return;
|
||||
}
|
||||
|
||||
const tmpCategories = [...localCategories];
|
||||
const [movedCategory] = tmpCategories.splice(result.source.index, 1);
|
||||
tmpCategories.splice(result.destination.index, 0, movedCategory);
|
||||
|
||||
setLocalCategories(tmpCategories);
|
||||
reorderCategories(tmpCategories);
|
||||
};
|
||||
|
||||
// Action handlers
|
||||
const deleteCategoryHandler = (id: number, name: string) => {
|
||||
const proceed = window.confirm(
|
||||
`Are you sure you want to delete ${name}? It will delete ALL assigned bookmarks`
|
||||
);
|
||||
|
||||
if (proceed) {
|
||||
deleteCategory(id);
|
||||
}
|
||||
};
|
||||
|
||||
const updateCategoryHandler = (id: number) => {
|
||||
const category = categories.find((c) => c.id === id) as Category;
|
||||
openFormForUpdating(category);
|
||||
};
|
||||
|
||||
const pinCategoryHandler = (id: number) => {
|
||||
const category = categories.find((c) => c.id === id) as Category;
|
||||
pinCategory(category);
|
||||
};
|
||||
|
||||
const changeCategoryVisibiltyHandler = (id: number) => {
|
||||
const category = categories.find((c) => c.id === id) as Category;
|
||||
updateCategory(id, { ...category, isPublic: !category.isPublic });
|
||||
};
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
<Message isPrimary={false}>
|
||||
{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>
|
||||
</p>
|
||||
)}
|
||||
</Message>
|
||||
|
||||
<DragDropContext onDragEnd={dragEndHanlder}>
|
||||
<Droppable droppableId="categories">
|
||||
{(provided) => (
|
||||
<Table
|
||||
headers={['Name', 'Visibility', 'Actions']}
|
||||
innerRef={provided.innerRef}
|
||||
>
|
||||
{localCategories.map((category, index): JSX.Element => {
|
||||
return (
|
||||
<Draggable
|
||||
key={category.id}
|
||||
draggableId={category.id.toString()}
|
||||
index={index}
|
||||
>
|
||||
{(provided, snapshot) => {
|
||||
const style = {
|
||||
border: snapshot.isDragging
|
||||
? '1px solid var(--color-accent)'
|
||||
: 'none',
|
||||
borderRadius: '4px',
|
||||
...provided.draggableProps.style,
|
||||
};
|
||||
|
||||
return (
|
||||
<tr
|
||||
{...provided.draggableProps}
|
||||
{...provided.dragHandleProps}
|
||||
ref={provided.innerRef}
|
||||
style={style}
|
||||
>
|
||||
<td style={{ width: '300px' }}>{category.name}</td>
|
||||
<td style={{ width: '300px' }}>
|
||||
{category.isPublic ? 'Visible' : 'Hidden'}
|
||||
</td>
|
||||
|
||||
{!snapshot.isDragging && (
|
||||
<TableActions
|
||||
entity={category}
|
||||
deleteHandler={deleteCategoryHandler}
|
||||
updateHandler={updateCategoryHandler}
|
||||
pinHanlder={pinCategoryHandler}
|
||||
changeVisibilty={changeCategoryVisibiltyHandler}
|
||||
/>
|
||||
)}
|
||||
</tr>
|
||||
);
|
||||
}}
|
||||
</Draggable>
|
||||
);
|
||||
})}
|
||||
</Table>
|
||||
)}
|
||||
</Droppable>
|
||||
</DragDropContext>
|
||||
</Fragment>
|
||||
);
|
||||
};
|
20
client/src/components/Bookmarks/Table/Table.tsx
Normal file
20
client/src/components/Bookmarks/Table/Table.tsx
Normal file
|
@ -0,0 +1,20 @@
|
|||
import { Category, Bookmark } from '../../../interfaces';
|
||||
import { ContentType } from '../Bookmarks';
|
||||
import { BookmarksTable } from './BookmarksTable';
|
||||
import { CategoryTable } from './CategoryTable';
|
||||
|
||||
interface Props {
|
||||
contentType: ContentType;
|
||||
openFormForUpdating: (data: Category | Bookmark) => void;
|
||||
}
|
||||
|
||||
export const Table = (props: Props): JSX.Element => {
|
||||
const tableEl =
|
||||
props.contentType === ContentType.category ? (
|
||||
<CategoryTable openFormForUpdating={props.openFormForUpdating} />
|
||||
) : (
|
||||
<BookmarksTable openFormForUpdating={props.openFormForUpdating} />
|
||||
);
|
||||
|
||||
return tableEl;
|
||||
};
|
|
@ -11,7 +11,7 @@ import { actionCreators } from '../../store';
|
|||
import { App, Category } from '../../interfaces';
|
||||
|
||||
// UI
|
||||
import { Icon, Container, SectionHeadline, Spinner } from '../UI';
|
||||
import { Icon, Container, SectionHeadline, Spinner, Message } from '../UI';
|
||||
|
||||
// CSS
|
||||
import classes from './Home.module.css';
|
||||
|
@ -30,6 +30,7 @@ export const Home = (): JSX.Element => {
|
|||
apps: { apps, loading: appsLoading },
|
||||
bookmarks: { categories, loading: bookmarksLoading },
|
||||
config: { config },
|
||||
auth: { isAuthenticated },
|
||||
} = useSelector((state: State) => state);
|
||||
|
||||
const dispatch = useDispatch();
|
||||
|
@ -63,8 +64,10 @@ export const Home = (): JSX.Element => {
|
|||
if (localSearch) {
|
||||
// Search through apps
|
||||
setAppSearchResult([
|
||||
...apps.filter(({ name }) =>
|
||||
new RegExp(escapeRegex(localSearch), 'i').test(name)
|
||||
...apps.filter(({ name, description }) =>
|
||||
new RegExp(escapeRegex(localSearch), 'i').test(
|
||||
`${name} ${description}`
|
||||
)
|
||||
),
|
||||
]);
|
||||
|
||||
|
@ -100,7 +103,18 @@ export const Home = (): JSX.Element => {
|
|||
|
||||
<Header />
|
||||
|
||||
{!config.hideApps ? (
|
||||
{!isAuthenticated &&
|
||||
!apps.some((a) => a.isPinned) &&
|
||||
!categories.some((c) => c.isPinned) ? (
|
||||
<Message>
|
||||
Welcome to Flame! Go to <Link to="/settings/app">/settings</Link>,
|
||||
login and start customizing your new homepage
|
||||
</Message>
|
||||
) : (
|
||||
<></>
|
||||
)}
|
||||
|
||||
{!config.hideApps && (isAuthenticated || apps.some((a) => a.isPinned)) ? (
|
||||
<Fragment>
|
||||
<SectionHeadline title="Applications" link="/applications" />
|
||||
{appsLoading ? (
|
||||
|
@ -119,10 +133,11 @@ export const Home = (): JSX.Element => {
|
|||
<div className={classes.HomeSpace}></div>
|
||||
</Fragment>
|
||||
) : (
|
||||
<div></div>
|
||||
<></>
|
||||
)}
|
||||
|
||||
{!config.hideCategories ? (
|
||||
{!config.hideCategories &&
|
||||
(isAuthenticated || categories.some((c) => c.isPinned)) ? (
|
||||
<Fragment>
|
||||
<SectionHeadline title="Bookmarks" link="/bookmarks" />
|
||||
{bookmarksLoading ? (
|
||||
|
@ -138,11 +153,12 @@ export const Home = (): JSX.Element => {
|
|||
}
|
||||
totalCategories={categories.length}
|
||||
searching={!!localSearch}
|
||||
fromHomepage={true}
|
||||
/>
|
||||
)}
|
||||
</Fragment>
|
||||
) : (
|
||||
<div></div>
|
||||
<></>
|
||||
)}
|
||||
|
||||
<Link to="/settings" className={classes.SettingsButton}>
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
border-bottom: 2px solid var(--color-accent);
|
||||
opacity: 0.5;
|
||||
transition: all 0.2s;
|
||||
border-radius: 0px;
|
||||
}
|
||||
|
||||
.SearchBar:focus {
|
||||
|
|
|
@ -64,16 +64,22 @@ export const SearchBar = (props: Props): JSX.Element => {
|
|||
};
|
||||
|
||||
const searchHandler = (e: KeyboardEvent<HTMLInputElement>) => {
|
||||
const { isLocal, search, query, isURL, sameTab } = searchParser(
|
||||
inputRef.current.value
|
||||
);
|
||||
const {
|
||||
isLocal,
|
||||
encodedURL,
|
||||
primarySearch,
|
||||
secondarySearch,
|
||||
isURL,
|
||||
sameTab,
|
||||
rawQuery,
|
||||
} = searchParser(inputRef.current.value);
|
||||
|
||||
if (isLocal) {
|
||||
setLocalSearch(search);
|
||||
setLocalSearch(encodedURL);
|
||||
}
|
||||
|
||||
if (e.code === 'Enter' || e.code === 'NumpadEnter') {
|
||||
if (!query.prefix) {
|
||||
if (!primarySearch.prefix) {
|
||||
// Prefix not found -> emit notification
|
||||
createNotification({
|
||||
title: 'Error',
|
||||
|
@ -90,19 +96,21 @@ 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
|
||||
let template = query.template;
|
||||
// no local results -> search the internet with the default search provider if query is not empty
|
||||
if (!/^ *$/.test(rawQuery)) {
|
||||
let template = primarySearch.template;
|
||||
|
||||
if (query.prefix === 'l') {
|
||||
template = 'https://duckduckgo.com/?q=';
|
||||
if (primarySearch.prefix === 'l') {
|
||||
template = secondarySearch.template;
|
||||
}
|
||||
|
||||
const url = `${template}${encodedURL}`;
|
||||
redirectUrl(url, sameTab);
|
||||
}
|
||||
|
||||
const url = `${template}${search}`;
|
||||
redirectUrl(url, sameTab);
|
||||
}
|
||||
} else {
|
||||
// Valid query -> redirect to search results
|
||||
const url = `${query.template}${search}`;
|
||||
const url = `${primarySearch.template}${encodedURL}`;
|
||||
redirectUrl(url, sameTab);
|
||||
}
|
||||
} else if (e.code === 'Escape') {
|
||||
|
|
|
@ -1,43 +1,57 @@
|
|||
import { Fragment } from 'react';
|
||||
|
||||
// UI
|
||||
import { Button, SettingsHeadline } from '../../UI';
|
||||
import classes from './AppDetails.module.css';
|
||||
import { checkVersion } from '../../../utility';
|
||||
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';
|
||||
|
||||
export const AppDetails = (): JSX.Element => {
|
||||
const { isAuthenticated } = useSelector((state: State) => state.auth);
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
<SettingsHeadline text="Authentication" />
|
||||
<AuthForm />
|
||||
|
||||
<hr className={classes.separator} />
|
||||
{isAuthenticated && (
|
||||
<Fragment>
|
||||
<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>
|
||||
<Button click={() => checkVersion(true)}>Check for updates</Button>
|
||||
</div>
|
||||
</Fragment>
|
||||
)}
|
||||
</Fragment>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { FormEvent, Fragment, useEffect, useState } from 'react';
|
||||
import { FormEvent, Fragment, useEffect, useState, useRef } from 'react';
|
||||
|
||||
// Redux
|
||||
import { useSelector, useDispatch } from 'react-redux';
|
||||
|
@ -23,6 +23,12 @@ export const AuthForm = (): JSX.Element => {
|
|||
duration: '14d',
|
||||
});
|
||||
|
||||
const passwordInputRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
passwordInputRef.current?.focus();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (token) {
|
||||
const decoded = decodeToken(token);
|
||||
|
@ -52,6 +58,7 @@ export const AuthForm = (): JSX.Element => {
|
|||
name="password"
|
||||
placeholder="••••••"
|
||||
autoComplete="current-password"
|
||||
ref={passwordInputRef}
|
||||
value={formData.password}
|
||||
onChange={(e) =>
|
||||
setFormData({ ...formData, password: e.target.value })
|
||||
|
|
|
@ -9,11 +9,8 @@ import { actionCreators } from '../../../../store';
|
|||
// Typescript
|
||||
import { Query } from '../../../../interfaces';
|
||||
|
||||
// CSS
|
||||
import classes from './CustomQueries.module.css';
|
||||
|
||||
// UI
|
||||
import { Modal, Icon, Button } from '../../../UI';
|
||||
import { Modal, Icon, Button, CompactTable, ActionIcons } from '../../../UI';
|
||||
|
||||
// Components
|
||||
import { QueriesForm } from './QueriesForm';
|
||||
|
@ -67,33 +64,27 @@ export const CustomQueries = (): JSX.Element => {
|
|||
)}
|
||||
</Modal>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
) : (
|
||||
<></>
|
||||
)}
|
||||
|
||||
<Button
|
||||
click={() => {
|
||||
|
@ -103,7 +94,7 @@ export const CustomQueries = (): JSX.Element => {
|
|||
>
|
||||
Add new search provider
|
||||
</Button>
|
||||
</div>
|
||||
</section>
|
||||
</Fragment>
|
||||
);
|
||||
};
|
|
@ -0,0 +1,242 @@
|
|||
// 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>
|
||||
);
|
||||
};
|
|
@ -1,30 +0,0 @@
|
|||
.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;
|
||||
}
|
|
@ -1,141 +0,0 @@
|
|||
// 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 { SearchSettings } from './SearchSettings/SearchSettings';
|
||||
import { GeneralSettings } from './GeneralSettings/GeneralSettings';
|
||||
import { DockerSettings } from './DockerSettings/DockerSettings';
|
||||
import { ProtectedRoute } from '../Routing/ProtectedRoute';
|
||||
|
||||
|
@ -24,9 +24,11 @@ import { ProtectedRoute } from '../Routing/ProtectedRoute';
|
|||
import { Container, Headline } from '../UI';
|
||||
|
||||
// Data
|
||||
import { routes } from './settings.json';
|
||||
import clientRoutes 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);
|
||||
|
@ -59,8 +61,8 @@ export const Settings = (): JSX.Element => {
|
|||
component={WeatherSettings}
|
||||
/>
|
||||
<ProtectedRoute
|
||||
path="/settings/search"
|
||||
component={SearchSettings}
|
||||
path="/settings/general"
|
||||
component={GeneralSettings}
|
||||
/>
|
||||
<ProtectedRoute path="/settings/interface" component={UISettings} />
|
||||
<ProtectedRoute
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
.ThemeBuilder {
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.Buttons button:not(:last-child) {
|
||||
margin-right: 10px;
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
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>
|
||||
);
|
||||
};
|
|
@ -0,0 +1,5 @@
|
|||
.ColorsContainer {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
grid-gap: 10px;
|
||||
}
|
|
@ -0,0 +1,152 @@
|
|||
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>
|
||||
);
|
||||
};
|
|
@ -0,0 +1,57 @@
|
|||
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>
|
||||
);
|
||||
};
|
|
@ -15,4 +15,4 @@
|
|||
.ThemerGrid {
|
||||
grid-template-columns: 1fr 1fr 1fr;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
// 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>
|
||||
);
|
||||
};
|
|
@ -1,32 +0,0 @@
|
|||
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>
|
||||
);
|
||||
};
|
|
@ -0,0 +1,38 @@
|
|||
// 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>
|
||||
);
|
||||
};
|
|
@ -4,31 +4,32 @@ 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 { ThemePreview } from './ThemePreview';
|
||||
import { Button, InputGroup, SettingsHeadline } from '../../UI';
|
||||
import { Button, InputGroup, SettingsHeadline, Spinner } from '../../UI';
|
||||
import { ThemeBuilder } from './ThemeBuilder/ThemeBuilder';
|
||||
import { ThemeGrid } from './ThemeGrid/ThemeGrid';
|
||||
|
||||
// Other
|
||||
import classes from './Themer.module.css';
|
||||
import { themes } from './themes.json';
|
||||
import { State } from '../../../store/reducers';
|
||||
import { inputHandler, themeSettingsTemplate } from '../../../utility';
|
||||
import {
|
||||
inputHandler,
|
||||
parseThemeToPAB,
|
||||
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 { setTheme, updateConfig } = bindActionCreators(
|
||||
actionCreators,
|
||||
dispatch
|
||||
);
|
||||
const { updateConfig } = bindActionCreators(actionCreators, dispatch);
|
||||
|
||||
// Initial state
|
||||
const [formData, setFormData] = useState<ThemeSettingsForm>(
|
||||
|
@ -47,7 +48,7 @@ export const Themer = (): JSX.Element => {
|
|||
e.preventDefault();
|
||||
|
||||
// Save settings
|
||||
await updateConfig(formData);
|
||||
await updateConfig({ ...formData });
|
||||
};
|
||||
|
||||
// Input handler
|
||||
|
@ -63,31 +64,34 @@ export const Themer = (): JSX.Element => {
|
|||
});
|
||||
};
|
||||
|
||||
const customThemesEl = (
|
||||
<Fragment>
|
||||
<SettingsHeadline text="User themes" />
|
||||
<ThemeBuilder themes={userThemes} />
|
||||
</Fragment>
|
||||
);
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
<SettingsHeadline text="Set theme" />
|
||||
<div className={classes.ThemerGrid}>
|
||||
{themes.map(
|
||||
(theme: Theme, idx: number): JSX.Element => (
|
||||
<ThemePreview key={idx} theme={theme} applyTheme={setTheme} />
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
<SettingsHeadline text="App themes" />
|
||||
{!themes.length ? <Spinner /> : <ThemeGrid themes={themes} />}
|
||||
|
||||
{!userThemes.length ? isAuthenticated && customThemesEl : customThemesEl}
|
||||
|
||||
{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.map((theme: Theme, idx) => (
|
||||
<option key={idx} value={theme.name}>
|
||||
{theme.name}
|
||||
{[...themes, ...userThemes].map((theme: Theme, idx) => (
|
||||
<option key={idx} value={parseThemeToPAB(theme.colors)}>
|
||||
{theme.isCustom && '+'} {theme.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
|
|
|
@ -7,27 +7,22 @@ import { bindActionCreators } from 'redux';
|
|||
import { actionCreators } from '../../../store';
|
||||
|
||||
// Typescript
|
||||
import { OtherSettingsForm } from '../../../interfaces';
|
||||
import { UISettingsForm } from '../../../interfaces';
|
||||
|
||||
// UI
|
||||
import { InputGroup, Button, SettingsHeadline } from '../../UI';
|
||||
|
||||
// Utils
|
||||
import { otherSettingsTemplate, inputHandler } from '../../../utility';
|
||||
import { uiSettingsTemplate, inputHandler } from '../../../utility';
|
||||
|
||||
export const UISettings = (): JSX.Element => {
|
||||
const { loading, config } = useSelector((state: State) => state.config);
|
||||
|
||||
const dispatch = useDispatch();
|
||||
const { updateConfig, sortApps, sortCategories } = bindActionCreators(
|
||||
actionCreators,
|
||||
dispatch
|
||||
);
|
||||
const { updateConfig } = bindActionCreators(actionCreators, dispatch);
|
||||
|
||||
// Initial state
|
||||
const [formData, setFormData] = useState<OtherSettingsForm>(
|
||||
otherSettingsTemplate
|
||||
);
|
||||
const [formData, setFormData] = useState<UISettingsForm>(uiSettingsTemplate);
|
||||
|
||||
// Get config
|
||||
useEffect(() => {
|
||||
|
@ -45,10 +40,6 @@ export const UISettings = (): JSX.Element => {
|
|||
|
||||
// Update local page title
|
||||
document.title = formData.customTitle;
|
||||
|
||||
// Sort apps and categories with new settings
|
||||
sortApps();
|
||||
sortCategories();
|
||||
};
|
||||
|
||||
// Input handler
|
||||
|
@ -56,7 +47,7 @@ export const UISettings = (): JSX.Element => {
|
|||
e: ChangeEvent<HTMLInputElement | HTMLSelectElement>,
|
||||
options?: { isNumber?: boolean; isBool?: boolean }
|
||||
) => {
|
||||
inputHandler<OtherSettingsForm>({
|
||||
inputHandler<UISettingsForm>({
|
||||
e,
|
||||
options,
|
||||
setStateHandler: setFormData,
|
||||
|
@ -81,11 +72,43 @@ 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 */}
|
||||
<InputGroup>
|
||||
<label htmlFor="hideHeader">Hide greetings</label>
|
||||
<label htmlFor="hideHeader">
|
||||
Hide headline (greetings and weather)
|
||||
</label>
|
||||
<select
|
||||
id="hideHeader"
|
||||
name="hideHeader"
|
||||
|
@ -151,8 +174,8 @@ export const UISettings = (): JSX.Element => {
|
|||
onChange={(e) => inputChangeHandler(e)}
|
||||
/>
|
||||
<span>
|
||||
Greetings must be separated with semicolon. Only 4 messages can be
|
||||
used
|
||||
Greetings must be separated with semicolon. All 4 messages must be
|
||||
filled, even if they are the same
|
||||
</span>
|
||||
</InputGroup>
|
||||
|
||||
|
@ -184,85 +207,8 @@ export const UISettings = (): JSX.Element => {
|
|||
<span>Names must be separated with semicolon</span>
|
||||
</InputGroup>
|
||||
|
||||
{/* === 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" />
|
||||
{/* === SECTIONS OPTIONS === */}
|
||||
<SettingsHeadline text="Sections" />
|
||||
{/* HIDE APPS */}
|
||||
<InputGroup>
|
||||
<label htmlFor="hideApps">Hide applications</label>
|
||||
|
@ -277,9 +223,9 @@ export const UISettings = (): JSX.Element => {
|
|||
</select>
|
||||
</InputGroup>
|
||||
|
||||
{/* HIDE CATEGORIES */}
|
||||
{/* HIDE BOOKMARK CATEGORIES */}
|
||||
<InputGroup>
|
||||
<label htmlFor="hideCategories">Hide categories</label>
|
||||
<label htmlFor="hideCategories">Hide bookmarks</label>
|
||||
<select
|
||||
id="hideCategories"
|
||||
name="hideCategories"
|
||||
|
|
|
@ -82,6 +82,19 @@ 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" />
|
||||
|
@ -120,15 +133,8 @@ export const WeatherSettings = (): JSX.Element => {
|
|||
step="any"
|
||||
lang="en-150"
|
||||
/>
|
||||
<span>
|
||||
You can use
|
||||
<a
|
||||
href="https://www.latlong.net/convert-address-to-lat-long.html"
|
||||
target="blank"
|
||||
>
|
||||
{' '}
|
||||
latlong.net
|
||||
</a>
|
||||
<span onClick={getLocation}>
|
||||
<a href="#">Click to get current location</a>
|
||||
</span>
|
||||
</InputGroup>
|
||||
|
||||
|
|
|
@ -6,13 +6,8 @@
|
|||
"authRequired": false
|
||||
},
|
||||
{
|
||||
"name": "Weather",
|
||||
"dest": "/settings/weather",
|
||||
"authRequired": true
|
||||
},
|
||||
{
|
||||
"name": "Search",
|
||||
"dest": "/settings/search",
|
||||
"name": "General",
|
||||
"dest": "/settings/general",
|
||||
"authRequired": true
|
||||
},
|
||||
{
|
||||
|
@ -20,6 +15,11 @@
|
|||
"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,4 +37,14 @@
|
|||
.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 @@
|
|||
const classes = require('./SettingsHeadline.module.css');
|
||||
import classes from './SettingsHeadline.module.css';
|
||||
|
||||
interface Props {
|
||||
text: string;
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
.ActionIcons {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.ActionIcons svg {
|
||||
width: 20px;
|
||||
}
|
||||
|
||||
.ActionIcons svg:hover {
|
||||
cursor: pointer;
|
||||
}
|
10
client/src/components/UI/Icons/ActionIcons/ActionIcons.tsx
Normal file
10
client/src/components/UI/Icons/ActionIcons/ActionIcons.tsx
Normal file
|
@ -0,0 +1,10 @@
|
|||
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 { theme } = useSelector((state: State) => state.theme);
|
||||
const { activeTheme } = 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: theme.colors.accent });
|
||||
const skycons = new Skycons({ color: activeTheme.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, theme.colors.accent]);
|
||||
}, [props.weatherStatusCode, icon, activeTheme.colors.accent]);
|
||||
|
||||
return <canvas id={`weather-icon`} width="50" height="50"></canvas>;
|
||||
};
|
||||
|
|
|
@ -6,24 +6,32 @@ interface Props {
|
|||
isOpen: boolean;
|
||||
setIsOpen: Function;
|
||||
children: ReactNode;
|
||||
cb?: Function;
|
||||
}
|
||||
|
||||
export const Modal = (props: Props): JSX.Element => {
|
||||
export const Modal = ({
|
||||
isOpen,
|
||||
setIsOpen,
|
||||
children,
|
||||
cb,
|
||||
}: Props): JSX.Element => {
|
||||
const modalRef = useRef(null);
|
||||
const modalClasses = [
|
||||
classes.Modal,
|
||||
props.isOpen ? classes.ModalOpen : classes.ModalClose,
|
||||
isOpen ? classes.ModalOpen : classes.ModalClose,
|
||||
].join(' ');
|
||||
|
||||
const clickHandler = (e: MouseEvent) => {
|
||||
if (e.target === modalRef.current) {
|
||||
props.setIsOpen(false);
|
||||
setIsOpen(false);
|
||||
|
||||
if (cb) cb();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={modalClasses} onClick={clickHandler} ref={modalRef}>
|
||||
{props.children}
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
.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;
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
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>
|
||||
);
|
||||
};
|
|
@ -1,17 +1,13 @@
|
|||
.TableActions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
.message {
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.TableAction {
|
||||
width: 22px;
|
||||
.message a {
|
||||
color: var(--color-accent);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.TableAction:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.Message {
|
||||
.messageCenter {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
|
@ -20,10 +16,11 @@
|
|||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.Message a {
|
||||
.messageCenter a,
|
||||
.messageCenter span {
|
||||
color: var(--color-accent);
|
||||
}
|
||||
|
||||
.Message a:hover {
|
||||
.messageCenter a:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
14
client/src/components/UI/Text/Message/Message.tsx
Normal file
14
client/src/components/UI/Text/Message/Message.tsx
Normal file
|
@ -0,0 +1,14 @@
|
|||
import { ReactNode } from 'react';
|
||||
|
||||
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>;
|
||||
};
|
|
@ -1,10 +1,12 @@
|
|||
export * from './Table/Table';
|
||||
export * from './Tables/Table/Table';
|
||||
export * from './Tables/CompactTable/CompactTable';
|
||||
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';
|
||||
|
@ -12,3 +14,4 @@ export * from './Forms/InputGroup/InputGroup';
|
|||
export * from './Forms/ModalForm/ModalForm';
|
||||
export * from './Buttons/ActionButton/ActionButton';
|
||||
export * from './Buttons/Button/Button';
|
||||
export * from './Text/Message/Message';
|
||||
|
|
|
@ -71,7 +71,7 @@ export const WeatherWidget = (): JSX.Element => {
|
|||
{config.isCelsius ? (
|
||||
<span>{weather.tempC}°C</span>
|
||||
) : (
|
||||
<span>{weather.tempF}°F</span>
|
||||
<span>{Math.round(weather.tempF)}°F</span>
|
||||
)}
|
||||
|
||||
{/* ADDITIONAL DATA */}
|
||||
|
|
|
@ -5,6 +5,7 @@ export interface NewApp {
|
|||
url: string;
|
||||
icon: string;
|
||||
isPublic: boolean;
|
||||
description: string;
|
||||
}
|
||||
|
||||
export interface App extends Model, NewApp {
|
||||
|
|
|
@ -8,4 +8,6 @@ export interface NewBookmark {
|
|||
isPublic: boolean;
|
||||
}
|
||||
|
||||
export interface Bookmark extends Model, NewBookmark {}
|
||||
export interface Bookmark extends Model, NewBookmark {
|
||||
orderId: number;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ export interface Config {
|
|||
hideCategories: boolean;
|
||||
hideSearch: boolean;
|
||||
defaultSearchProvider: string;
|
||||
secondarySearchProvider: string;
|
||||
dockerApps: boolean;
|
||||
dockerHost: string;
|
||||
kubernetesApps: boolean;
|
||||
|
|
|
@ -8,29 +8,30 @@ export interface WeatherForm {
|
|||
weatherData: WeatherData;
|
||||
}
|
||||
|
||||
export interface SearchForm {
|
||||
hideSearch: boolean;
|
||||
export interface GeneralForm {
|
||||
defaultSearchProvider: string;
|
||||
secondarySearchProvider: string;
|
||||
searchSameTab: boolean;
|
||||
disableAutofocus: boolean;
|
||||
}
|
||||
|
||||
export interface OtherSettingsForm {
|
||||
customTitle: string;
|
||||
pinAppsByDefault: boolean;
|
||||
pinCategoriesByDefault: boolean;
|
||||
hideHeader: boolean;
|
||||
hideApps: boolean;
|
||||
hideCategories: boolean;
|
||||
useOrdering: string;
|
||||
appsSameTab: boolean;
|
||||
bookmarksSameTab: boolean;
|
||||
}
|
||||
|
||||
export interface UISettingsForm {
|
||||
customTitle: string;
|
||||
hideHeader: boolean;
|
||||
hideApps: boolean;
|
||||
hideCategories: boolean;
|
||||
useAmericanDate: boolean;
|
||||
greetingsSchema: string;
|
||||
daySchema: string;
|
||||
monthSchema: string;
|
||||
showTime: boolean;
|
||||
hideDate: boolean;
|
||||
hideSearch: boolean;
|
||||
disableAutofocus: boolean;
|
||||
}
|
||||
|
||||
export interface DockerSettingsForm {
|
||||
|
|
|
@ -4,6 +4,8 @@ export interface SearchResult {
|
|||
isLocal: boolean;
|
||||
isURL: boolean;
|
||||
sameTab: boolean;
|
||||
search: string;
|
||||
query: Query;
|
||||
encodedURL: string;
|
||||
primarySearch: Query;
|
||||
secondarySearch: Query;
|
||||
rawQuery: string;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
export interface ThemeColors {
|
||||
background: string;
|
||||
primary: string;
|
||||
accent: string;
|
||||
}
|
||||
|
||||
export interface Theme {
|
||||
name: string;
|
||||
colors: {
|
||||
background: string;
|
||||
primary: string;
|
||||
accent: string;
|
||||
}
|
||||
}
|
||||
colors: ThemeColors;
|
||||
isCustom: boolean;
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import {
|
|||
GetAppsAction,
|
||||
PinAppAction,
|
||||
ReorderAppsAction,
|
||||
SetEditAppAction,
|
||||
SortAppsAction,
|
||||
UpdateAppAction,
|
||||
} from '../actions/app';
|
||||
|
@ -196,3 +197,11 @@ export const sortApps = () => async (dispatch: Dispatch<SortAppsAction>) => {
|
|||
console.log(err);
|
||||
}
|
||||
};
|
||||
|
||||
export const setEditApp =
|
||||
(app: App | null) => (dispatch: Dispatch<SetEditAppAction>) => {
|
||||
dispatch({
|
||||
type: ActionType.setEditApp,
|
||||
payload: app,
|
||||
});
|
||||
};
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
import axios from 'axios';
|
||||
import { Dispatch } from 'redux';
|
||||
import { applyAuth } from '../../utility';
|
||||
import { ActionType } from '../action-types';
|
||||
|
||||
import {
|
||||
ApiResponse,
|
||||
Bookmark,
|
||||
|
@ -8,8 +11,7 @@ import {
|
|||
NewBookmark,
|
||||
NewCategory,
|
||||
} from '../../interfaces';
|
||||
import { applyAuth } from '../../utility';
|
||||
import { ActionType } from '../action-types';
|
||||
|
||||
import {
|
||||
AddBookmarkAction,
|
||||
AddCategoryAction,
|
||||
|
@ -17,7 +19,11 @@ import {
|
|||
DeleteCategoryAction,
|
||||
GetCategoriesAction,
|
||||
PinCategoryAction,
|
||||
ReorderBookmarksAction,
|
||||
ReorderCategoriesAction,
|
||||
SetEditBookmarkAction,
|
||||
SetEditCategoryAction,
|
||||
SortBookmarksAction,
|
||||
SortCategoriesAction,
|
||||
UpdateBookmarkAction,
|
||||
UpdateCategoryAction,
|
||||
|
@ -95,6 +101,8 @@ export const addBookmark =
|
|||
type: ActionType.addBookmark,
|
||||
payload: res.data.data,
|
||||
});
|
||||
|
||||
dispatch<any>(sortBookmarks(res.data.data.categoryId));
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
|
@ -266,6 +274,8 @@ export const updateBookmark =
|
|||
payload: res.data.data,
|
||||
});
|
||||
}
|
||||
|
||||
dispatch<any>(sortBookmarks(res.data.data.categoryId));
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
|
@ -319,3 +329,73 @@ export const reorderCategories =
|
|||
console.log(err);
|
||||
}
|
||||
};
|
||||
|
||||
export const setEditCategory =
|
||||
(category: Category | null) =>
|
||||
(dispatch: Dispatch<SetEditCategoryAction>) => {
|
||||
dispatch({
|
||||
type: ActionType.setEditCategory,
|
||||
payload: category,
|
||||
});
|
||||
};
|
||||
|
||||
export const setEditBookmark =
|
||||
(bookmark: Bookmark | null) =>
|
||||
(dispatch: Dispatch<SetEditBookmarkAction>) => {
|
||||
dispatch({
|
||||
type: ActionType.setEditBookmark,
|
||||
payload: bookmark,
|
||||
});
|
||||
};
|
||||
|
||||
export const reorderBookmarks =
|
||||
(bookmarks: Bookmark[], categoryId: number) =>
|
||||
async (dispatch: Dispatch<ReorderBookmarksAction>) => {
|
||||
interface ReorderQuery {
|
||||
bookmarks: {
|
||||
id: number;
|
||||
orderId: number;
|
||||
}[];
|
||||
}
|
||||
|
||||
try {
|
||||
const updateQuery: ReorderQuery = { bookmarks: [] };
|
||||
|
||||
bookmarks.forEach((bookmark, index) =>
|
||||
updateQuery.bookmarks.push({
|
||||
id: bookmark.id,
|
||||
orderId: index + 1,
|
||||
})
|
||||
);
|
||||
|
||||
await axios.put<ApiResponse<{}>>(
|
||||
'/api/bookmarks/0/reorder',
|
||||
updateQuery,
|
||||
{ headers: applyAuth() }
|
||||
);
|
||||
|
||||
dispatch({
|
||||
type: ActionType.reorderBookmarks,
|
||||
payload: { bookmarks, categoryId },
|
||||
});
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
};
|
||||
|
||||
export const sortBookmarks =
|
||||
(categoryId: number) => async (dispatch: Dispatch<SortBookmarksAction>) => {
|
||||
try {
|
||||
const res = await axios.get<ApiResponse<Config>>('/api/config');
|
||||
|
||||
dispatch({
|
||||
type: ActionType.sortBookmarks,
|
||||
payload: {
|
||||
orderType: res.data.data.useOrdering,
|
||||
categoryId,
|
||||
},
|
||||
});
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -7,7 +7,7 @@ import {
|
|||
UpdateConfigAction,
|
||||
UpdateQueryAction,
|
||||
} from '../actions/config';
|
||||
import axios from 'axios';
|
||||
import axios, { AxiosError } from 'axios';
|
||||
import { ApiResponse, Config, Query } from '../../interfaces';
|
||||
import { ActionType } from '../action-types';
|
||||
import { storeUIConfig, applyAuth } from '../../utility';
|
||||
|
@ -103,7 +103,15 @@ export const addQuery =
|
|||
payload: res.data.data,
|
||||
});
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
const error = err as AxiosError<{ error: string }>;
|
||||
|
||||
dispatch<any>({
|
||||
type: ActionType.createNotification,
|
||||
payload: {
|
||||
title: 'Error',
|
||||
message: error.response?.data.error,
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1,30 +1,128 @@
|
|||
import { Dispatch } from 'redux';
|
||||
import { SetThemeAction } from '../actions/theme';
|
||||
import {
|
||||
AddThemeAction,
|
||||
DeleteThemeAction,
|
||||
EditThemeAction,
|
||||
FetchThemesAction,
|
||||
SetThemeAction,
|
||||
UpdateThemeAction,
|
||||
} from '../actions/theme';
|
||||
import { ActionType } from '../action-types';
|
||||
import { Theme } from '../../interfaces/Theme';
|
||||
import { themes } from '../../components/Settings/Themer/themes.json';
|
||||
import { Theme, ApiResponse, ThemeColors } from '../../interfaces';
|
||||
import { applyAuth, parseThemeToPAB } from '../../utility';
|
||||
import axios, { AxiosError } from 'axios';
|
||||
|
||||
export const setTheme =
|
||||
(name: string, remeberTheme: boolean = true) =>
|
||||
(colors: ThemeColors, remeberTheme: boolean = true) =>
|
||||
(dispatch: Dispatch<SetThemeAction>) => {
|
||||
const theme = themes.find((theme) => theme.name === name);
|
||||
if (remeberTheme) {
|
||||
localStorage.setItem('theme', parseThemeToPAB(colors));
|
||||
}
|
||||
|
||||
if (theme) {
|
||||
if (remeberTheme) {
|
||||
localStorage.setItem('theme', name);
|
||||
}
|
||||
for (const [key, value] of Object.entries(colors)) {
|
||||
document.body.style.setProperty(`--color-${key}`, value);
|
||||
}
|
||||
|
||||
loadTheme(theme);
|
||||
dispatch({
|
||||
type: ActionType.setTheme,
|
||||
payload: colors,
|
||||
});
|
||||
};
|
||||
|
||||
export const fetchThemes =
|
||||
() => async (dispatch: Dispatch<FetchThemesAction>) => {
|
||||
try {
|
||||
const res = await axios.get<ApiResponse<Theme[]>>('/api/themes');
|
||||
|
||||
dispatch({
|
||||
type: ActionType.setTheme,
|
||||
payload: theme,
|
||||
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,
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const loadTheme = (theme: Theme): void => {
|
||||
for (const [key, value] of Object.entries(theme.colors)) {
|
||||
document.body.style.setProperty(`--color-${key}`, value);
|
||||
}
|
||||
};
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
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',
|
||||
|
@ -23,6 +28,7 @@ export enum ActionType {
|
|||
updateApp = 'UPDATE_APP',
|
||||
reorderApps = 'REORDER_APPS',
|
||||
sortApps = 'SORT_APPS',
|
||||
setEditApp = 'SET_EDIT_APP',
|
||||
// CATEGORES
|
||||
getCategories = 'GET_CATEGORIES',
|
||||
getCategoriesSuccess = 'GET_CATEGORIES_SUCCESS',
|
||||
|
@ -33,10 +39,14 @@ export enum ActionType {
|
|||
updateCategory = 'UPDATE_CATEGORY',
|
||||
sortCategories = 'SORT_CATEGORIES',
|
||||
reorderCategories = 'REORDER_CATEGORIES',
|
||||
setEditCategory = 'SET_EDIT_CATEGORY',
|
||||
// BOOKMARKS
|
||||
addBookmark = 'ADD_BOOKMARK',
|
||||
deleteBookmark = 'DELETE_BOOKMARK',
|
||||
updateBookmark = 'UPDATE_BOOKMARK',
|
||||
setEditBookmark = 'SET_EDIT_BOOKMARK',
|
||||
reorderBookmarks = 'REORDER_BOOKMARKS',
|
||||
sortBookmarks = 'SORT_BOOKMARKS',
|
||||
// AUTH
|
||||
login = 'LOGIN',
|
||||
logout = 'LOGOUT',
|
||||
|
|
|
@ -36,3 +36,8 @@ export interface SortAppsAction {
|
|||
type: ActionType.sortApps;
|
||||
payload: string;
|
||||
}
|
||||
|
||||
export interface SetEditAppAction {
|
||||
type: ActionType.setEditApp;
|
||||
payload: App | null;
|
||||
}
|
||||
|
|
|
@ -56,3 +56,29 @@ export interface ReorderCategoriesAction {
|
|||
type: ActionType.reorderCategories;
|
||||
payload: Category[];
|
||||
}
|
||||
|
||||
export interface SetEditCategoryAction {
|
||||
type: ActionType.setEditCategory;
|
||||
payload: Category | null;
|
||||
}
|
||||
|
||||
export interface SetEditBookmarkAction {
|
||||
type: ActionType.setEditBookmark;
|
||||
payload: Bookmark | null;
|
||||
}
|
||||
|
||||
export interface ReorderBookmarksAction {
|
||||
type: ActionType.reorderBookmarks;
|
||||
payload: {
|
||||
bookmarks: Bookmark[];
|
||||
categoryId: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface SortBookmarksAction {
|
||||
type: ActionType.sortBookmarks;
|
||||
payload: {
|
||||
orderType: string;
|
||||
categoryId: number;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
import { App } from '../../interfaces';
|
||||
|
||||
import { SetThemeAction } from './theme';
|
||||
import {
|
||||
AddThemeAction,
|
||||
DeleteThemeAction,
|
||||
EditThemeAction,
|
||||
FetchThemesAction,
|
||||
SetThemeAction,
|
||||
UpdateThemeAction,
|
||||
} from './theme';
|
||||
|
||||
import {
|
||||
AddQueryAction,
|
||||
|
@ -24,6 +31,7 @@ import {
|
|||
UpdateAppAction,
|
||||
ReorderAppsAction,
|
||||
SortAppsAction,
|
||||
SetEditAppAction,
|
||||
} from './app';
|
||||
|
||||
import {
|
||||
|
@ -37,6 +45,10 @@ import {
|
|||
AddBookmarkAction,
|
||||
DeleteBookmarkAction,
|
||||
UpdateBookmarkAction,
|
||||
SetEditCategoryAction,
|
||||
SetEditBookmarkAction,
|
||||
ReorderBookmarksAction,
|
||||
SortBookmarksAction,
|
||||
} from './bookmark';
|
||||
|
||||
import {
|
||||
|
@ -49,6 +61,11 @@ import {
|
|||
export type Action =
|
||||
// Theme
|
||||
| SetThemeAction
|
||||
| FetchThemesAction
|
||||
| AddThemeAction
|
||||
| DeleteThemeAction
|
||||
| UpdateThemeAction
|
||||
| EditThemeAction
|
||||
// Config
|
||||
| GetConfigAction
|
||||
| UpdateConfigAction
|
||||
|
@ -67,6 +84,7 @@ export type Action =
|
|||
| UpdateAppAction
|
||||
| ReorderAppsAction
|
||||
| SortAppsAction
|
||||
| SetEditAppAction
|
||||
// Categories
|
||||
| GetCategoriesAction<any>
|
||||
| AddCategoryAction
|
||||
|
@ -75,10 +93,14 @@ export type Action =
|
|||
| UpdateCategoryAction
|
||||
| SortCategoriesAction
|
||||
| ReorderCategoriesAction
|
||||
| SetEditCategoryAction
|
||||
// Bookmarks
|
||||
| AddBookmarkAction
|
||||
| DeleteBookmarkAction
|
||||
| UpdateBookmarkAction
|
||||
| SetEditBookmarkAction
|
||||
| ReorderBookmarksAction
|
||||
| SortBookmarksAction
|
||||
// Auth
|
||||
| LoginAction
|
||||
| LogoutAction
|
||||
|
|
|
@ -1,7 +1,32 @@
|
|||
import { ActionType } from '../action-types';
|
||||
import { Theme } from '../../interfaces';
|
||||
import { Theme, ThemeColors } 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;
|
||||
}
|
||||
|
|
|
@ -7,12 +7,14 @@ interface AppsState {
|
|||
loading: boolean;
|
||||
apps: App[];
|
||||
errors: string | undefined;
|
||||
appInUpdate: App | null;
|
||||
}
|
||||
|
||||
const initialState: AppsState = {
|
||||
loading: true,
|
||||
apps: [],
|
||||
errors: undefined,
|
||||
appInUpdate: null,
|
||||
};
|
||||
|
||||
export const appsReducer = (
|
||||
|
@ -20,71 +22,86 @@ export const appsReducer = (
|
|||
action: Action
|
||||
): AppsState => {
|
||||
switch (action.type) {
|
||||
case ActionType.getApps:
|
||||
case ActionType.getApps: {
|
||||
return {
|
||||
...state,
|
||||
loading: true,
|
||||
errors: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.getAppsSuccess:
|
||||
case ActionType.getAppsSuccess: {
|
||||
return {
|
||||
...state,
|
||||
loading: false,
|
||||
apps: action.payload || [],
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.pinApp:
|
||||
const pinnedAppIdx = state.apps.findIndex(
|
||||
case ActionType.pinApp: {
|
||||
const appIdx = state.apps.findIndex(
|
||||
(app) => app.id === action.payload.id
|
||||
);
|
||||
|
||||
return {
|
||||
...state,
|
||||
apps: [
|
||||
...state.apps.slice(0, pinnedAppIdx),
|
||||
...state.apps.slice(0, appIdx),
|
||||
action.payload,
|
||||
...state.apps.slice(pinnedAppIdx + 1),
|
||||
...state.apps.slice(appIdx + 1),
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.addAppSuccess:
|
||||
case ActionType.addAppSuccess: {
|
||||
return {
|
||||
...state,
|
||||
apps: [...state.apps, action.payload],
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.deleteApp:
|
||||
case ActionType.deleteApp: {
|
||||
return {
|
||||
...state,
|
||||
apps: [...state.apps].filter((app) => app.id !== action.payload),
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.updateApp:
|
||||
const updatedAppIdx = state.apps.findIndex(
|
||||
case ActionType.updateApp: {
|
||||
const appIdx = state.apps.findIndex(
|
||||
(app) => app.id === action.payload.id
|
||||
);
|
||||
|
||||
return {
|
||||
...state,
|
||||
apps: [
|
||||
...state.apps.slice(0, updatedAppIdx),
|
||||
...state.apps.slice(0, appIdx),
|
||||
action.payload,
|
||||
...state.apps.slice(updatedAppIdx + 1),
|
||||
...state.apps.slice(appIdx + 1),
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.reorderApps:
|
||||
case ActionType.reorderApps: {
|
||||
return {
|
||||
...state,
|
||||
apps: action.payload,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.sortApps:
|
||||
case ActionType.sortApps: {
|
||||
return {
|
||||
...state,
|
||||
apps: sortData<App>(state.apps, action.payload),
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.setEditApp: {
|
||||
return {
|
||||
...state,
|
||||
appInUpdate: action.payload,
|
||||
};
|
||||
}
|
||||
|
||||
default:
|
||||
return state;
|
||||
|
|
|
@ -22,24 +22,28 @@ export const authReducer = (
|
|||
token: action.payload,
|
||||
isAuthenticated: true,
|
||||
};
|
||||
|
||||
case ActionType.logout:
|
||||
return {
|
||||
...state,
|
||||
token: null,
|
||||
isAuthenticated: false,
|
||||
};
|
||||
|
||||
case ActionType.autoLogin:
|
||||
return {
|
||||
...state,
|
||||
token: action.payload,
|
||||
isAuthenticated: true,
|
||||
};
|
||||
|
||||
case ActionType.authError:
|
||||
return {
|
||||
...state,
|
||||
token: null,
|
||||
isAuthenticated: false,
|
||||
};
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Category } from '../../interfaces';
|
||||
import { Bookmark, Category } from '../../interfaces';
|
||||
import { sortData } from '../../utility';
|
||||
import { ActionType } from '../action-types';
|
||||
import { Action } from '../actions';
|
||||
|
@ -7,12 +7,16 @@ interface BookmarksState {
|
|||
loading: boolean;
|
||||
errors: string | undefined;
|
||||
categories: Category[];
|
||||
categoryInEdit: Category | null;
|
||||
bookmarkInEdit: Bookmark | null;
|
||||
}
|
||||
|
||||
const initialState: BookmarksState = {
|
||||
loading: true,
|
||||
errors: undefined,
|
||||
categories: [],
|
||||
categoryInEdit: null,
|
||||
bookmarkInEdit: null,
|
||||
};
|
||||
|
||||
export const bookmarksReducer = (
|
||||
|
@ -20,27 +24,181 @@ export const bookmarksReducer = (
|
|||
action: Action
|
||||
): BookmarksState => {
|
||||
switch (action.type) {
|
||||
case ActionType.getCategories:
|
||||
case ActionType.getCategories: {
|
||||
return {
|
||||
...state,
|
||||
loading: true,
|
||||
errors: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.getCategoriesSuccess:
|
||||
case ActionType.getCategoriesSuccess: {
|
||||
return {
|
||||
...state,
|
||||
loading: false,
|
||||
categories: action.payload,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.addCategory:
|
||||
case ActionType.addCategory: {
|
||||
return {
|
||||
...state,
|
||||
categories: [...state.categories, { ...action.payload, bookmarks: [] }],
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.addBookmark:
|
||||
case ActionType.addBookmark: {
|
||||
const categoryIdx = state.categories.findIndex(
|
||||
(category) => category.id === action.payload.categoryId
|
||||
);
|
||||
|
||||
const targetCategory = {
|
||||
...state.categories[categoryIdx],
|
||||
bookmarks: [...state.categories[categoryIdx].bookmarks, action.payload],
|
||||
};
|
||||
|
||||
return {
|
||||
...state,
|
||||
categories: [
|
||||
...state.categories.slice(0, categoryIdx),
|
||||
targetCategory,
|
||||
...state.categories.slice(categoryIdx + 1),
|
||||
],
|
||||
categoryInEdit: targetCategory,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.pinCategory: {
|
||||
const categoryIdx = state.categories.findIndex(
|
||||
(category) => category.id === action.payload.id
|
||||
);
|
||||
|
||||
return {
|
||||
...state,
|
||||
categories: [
|
||||
...state.categories.slice(0, categoryIdx),
|
||||
{
|
||||
...action.payload,
|
||||
bookmarks: [...state.categories[categoryIdx].bookmarks],
|
||||
},
|
||||
...state.categories.slice(categoryIdx + 1),
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.deleteCategory: {
|
||||
const categoryIdx = state.categories.findIndex(
|
||||
(category) => category.id === action.payload
|
||||
);
|
||||
|
||||
return {
|
||||
...state,
|
||||
categories: [
|
||||
...state.categories.slice(0, categoryIdx),
|
||||
...state.categories.slice(categoryIdx + 1),
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.updateCategory: {
|
||||
const categoryIdx = state.categories.findIndex(
|
||||
(category) => category.id === action.payload.id
|
||||
);
|
||||
|
||||
return {
|
||||
...state,
|
||||
categories: [
|
||||
...state.categories.slice(0, categoryIdx),
|
||||
{
|
||||
...action.payload,
|
||||
bookmarks: [...state.categories[categoryIdx].bookmarks],
|
||||
},
|
||||
...state.categories.slice(categoryIdx + 1),
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.deleteBookmark: {
|
||||
const categoryIdx = state.categories.findIndex(
|
||||
(category) => category.id === action.payload.categoryId
|
||||
);
|
||||
|
||||
const targetCategory = {
|
||||
...state.categories[categoryIdx],
|
||||
bookmarks: state.categories[categoryIdx].bookmarks.filter(
|
||||
(bookmark) => bookmark.id !== action.payload.bookmarkId
|
||||
),
|
||||
};
|
||||
|
||||
return {
|
||||
...state,
|
||||
categories: [
|
||||
...state.categories.slice(0, categoryIdx),
|
||||
targetCategory,
|
||||
...state.categories.slice(categoryIdx + 1),
|
||||
],
|
||||
categoryInEdit: targetCategory,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.updateBookmark: {
|
||||
const categoryIdx = state.categories.findIndex(
|
||||
(category) => category.id === action.payload.categoryId
|
||||
);
|
||||
|
||||
const bookmarkIdx = state.categories[categoryIdx].bookmarks.findIndex(
|
||||
(bookmark) => bookmark.id === action.payload.id
|
||||
);
|
||||
|
||||
const targetCategory = {
|
||||
...state.categories[categoryIdx],
|
||||
bookmarks: [
|
||||
...state.categories[categoryIdx].bookmarks.slice(0, bookmarkIdx),
|
||||
action.payload,
|
||||
...state.categories[categoryIdx].bookmarks.slice(bookmarkIdx + 1),
|
||||
],
|
||||
};
|
||||
|
||||
return {
|
||||
...state,
|
||||
categories: [
|
||||
...state.categories.slice(0, categoryIdx),
|
||||
targetCategory,
|
||||
...state.categories.slice(categoryIdx + 1),
|
||||
],
|
||||
categoryInEdit: targetCategory,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.sortCategories: {
|
||||
return {
|
||||
...state,
|
||||
categories: sortData<Category>(state.categories, action.payload),
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.reorderCategories: {
|
||||
return {
|
||||
...state,
|
||||
categories: action.payload,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.setEditCategory: {
|
||||
return {
|
||||
...state,
|
||||
categoryInEdit: action.payload,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.setEditBookmark: {
|
||||
return {
|
||||
...state,
|
||||
bookmarkInEdit: action.payload,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.reorderBookmarks: {
|
||||
const categoryIdx = state.categories.findIndex(
|
||||
(category) => category.id === action.payload.categoryId
|
||||
);
|
||||
|
@ -51,121 +209,36 @@ export const bookmarksReducer = (
|
|||
...state.categories.slice(0, categoryIdx),
|
||||
{
|
||||
...state.categories[categoryIdx],
|
||||
bookmarks: [
|
||||
...state.categories[categoryIdx].bookmarks,
|
||||
action.payload,
|
||||
],
|
||||
bookmarks: action.payload.bookmarks,
|
||||
},
|
||||
...state.categories.slice(categoryIdx + 1),
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.pinCategory:
|
||||
const pinnedCategoryIdx = state.categories.findIndex(
|
||||
(category) => category.id === action.payload.id
|
||||
);
|
||||
|
||||
return {
|
||||
...state,
|
||||
categories: [
|
||||
...state.categories.slice(0, pinnedCategoryIdx),
|
||||
{
|
||||
...action.payload,
|
||||
bookmarks: [...state.categories[pinnedCategoryIdx].bookmarks],
|
||||
},
|
||||
...state.categories.slice(pinnedCategoryIdx + 1),
|
||||
],
|
||||
};
|
||||
|
||||
case ActionType.deleteCategory:
|
||||
const deletedCategoryIdx = state.categories.findIndex(
|
||||
(category) => category.id === action.payload
|
||||
);
|
||||
|
||||
return {
|
||||
...state,
|
||||
categories: [
|
||||
...state.categories.slice(0, deletedCategoryIdx),
|
||||
...state.categories.slice(deletedCategoryIdx + 1),
|
||||
],
|
||||
};
|
||||
|
||||
case ActionType.updateCategory:
|
||||
const updatedCategoryIdx = state.categories.findIndex(
|
||||
(category) => category.id === action.payload.id
|
||||
);
|
||||
|
||||
return {
|
||||
...state,
|
||||
categories: [
|
||||
...state.categories.slice(0, updatedCategoryIdx),
|
||||
{
|
||||
...action.payload,
|
||||
bookmarks: [...state.categories[updatedCategoryIdx].bookmarks],
|
||||
},
|
||||
...state.categories.slice(updatedCategoryIdx + 1),
|
||||
],
|
||||
};
|
||||
|
||||
case ActionType.deleteBookmark:
|
||||
const categoryInUpdateIdx = state.categories.findIndex(
|
||||
case ActionType.sortBookmarks: {
|
||||
const categoryIdx = state.categories.findIndex(
|
||||
(category) => category.id === action.payload.categoryId
|
||||
);
|
||||
|
||||
return {
|
||||
...state,
|
||||
categories: [
|
||||
...state.categories.slice(0, categoryInUpdateIdx),
|
||||
{
|
||||
...state.categories[categoryInUpdateIdx],
|
||||
bookmarks: state.categories[categoryInUpdateIdx].bookmarks.filter(
|
||||
(bookmark) => bookmark.id !== action.payload.bookmarkId
|
||||
),
|
||||
},
|
||||
...state.categories.slice(categoryInUpdateIdx + 1),
|
||||
],
|
||||
};
|
||||
|
||||
case ActionType.updateBookmark:
|
||||
const parentCategoryIdx = state.categories.findIndex(
|
||||
(category) => category.id === action.payload.categoryId
|
||||
const sortedBookmarks = sortData<Bookmark>(
|
||||
state.categories[categoryIdx].bookmarks,
|
||||
action.payload.orderType
|
||||
);
|
||||
const updatedBookmarkIdx = state.categories[
|
||||
parentCategoryIdx
|
||||
].bookmarks.findIndex((bookmark) => bookmark.id === action.payload.id);
|
||||
|
||||
return {
|
||||
...state,
|
||||
categories: [
|
||||
...state.categories.slice(0, parentCategoryIdx),
|
||||
...state.categories.slice(0, categoryIdx),
|
||||
{
|
||||
...state.categories[parentCategoryIdx],
|
||||
bookmarks: [
|
||||
...state.categories[parentCategoryIdx].bookmarks.slice(
|
||||
0,
|
||||
updatedBookmarkIdx
|
||||
),
|
||||
action.payload,
|
||||
...state.categories[parentCategoryIdx].bookmarks.slice(
|
||||
updatedBookmarkIdx + 1
|
||||
),
|
||||
],
|
||||
...state.categories[categoryIdx],
|
||||
bookmarks: sortedBookmarks,
|
||||
},
|
||||
...state.categories.slice(parentCategoryIdx + 1),
|
||||
...state.categories.slice(categoryIdx + 1),
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.sortCategories:
|
||||
return {
|
||||
...state,
|
||||
categories: sortData<Category>(state.categories, action.payload),
|
||||
};
|
||||
|
||||
case ActionType.reorderCategories:
|
||||
return {
|
||||
...state,
|
||||
categories: action.payload,
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
|
|
@ -26,26 +26,31 @@ export const configReducer = (
|
|||
loading: false,
|
||||
config: action.payload,
|
||||
};
|
||||
|
||||
case ActionType.updateConfig:
|
||||
return {
|
||||
...state,
|
||||
config: action.payload,
|
||||
};
|
||||
|
||||
case ActionType.fetchQueries:
|
||||
return {
|
||||
...state,
|
||||
customQueries: action.payload,
|
||||
};
|
||||
|
||||
case ActionType.addQuery:
|
||||
return {
|
||||
...state,
|
||||
customQueries: [...state.customQueries, action.payload],
|
||||
};
|
||||
|
||||
case ActionType.deleteQuery:
|
||||
return {
|
||||
...state,
|
||||
customQueries: action.payload,
|
||||
};
|
||||
|
||||
case ActionType.updateQuery:
|
||||
return {
|
||||
...state,
|
||||
|
|
|
@ -29,6 +29,7 @@ export const notificationReducer = (
|
|||
],
|
||||
idCounter: state.idCounter + 1,
|
||||
};
|
||||
|
||||
case ActionType.clearNotification:
|
||||
return {
|
||||
...state,
|
||||
|
|
|
@ -1,20 +1,30 @@
|
|||
import { Action } from '../actions';
|
||||
import { ActionType } from '../action-types';
|
||||
import { Theme } from '../../interfaces/Theme';
|
||||
import { arrayPartition, parsePABToTheme } from '../../utility';
|
||||
|
||||
interface ThemeState {
|
||||
theme: Theme;
|
||||
activeTheme: Theme;
|
||||
themes: Theme[];
|
||||
userThemes: Theme[];
|
||||
themeInEdit: Theme | null;
|
||||
}
|
||||
|
||||
const savedTheme = localStorage.theme
|
||||
? parsePABToTheme(localStorage.theme)
|
||||
: parsePABToTheme('#effbff;#6ee2ff;#242b33');
|
||||
|
||||
const initialState: ThemeState = {
|
||||
theme: {
|
||||
name: 'tron',
|
||||
activeTheme: {
|
||||
name: 'main',
|
||||
isCustom: false,
|
||||
colors: {
|
||||
background: '#242B33',
|
||||
primary: '#EFFBFF',
|
||||
accent: '#6EE2FF',
|
||||
...savedTheme,
|
||||
},
|
||||
},
|
||||
themes: [],
|
||||
userThemes: [],
|
||||
themeInEdit: null,
|
||||
};
|
||||
|
||||
export const themeReducer = (
|
||||
|
@ -22,8 +32,57 @@ export const themeReducer = (
|
|||
action: Action
|
||||
): ThemeState => {
|
||||
switch (action.type) {
|
||||
case ActionType.setTheme:
|
||||
return { theme: action.payload };
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
import {
|
||||
DockerSettingsForm,
|
||||
OtherSettingsForm,
|
||||
SearchForm,
|
||||
UISettingsForm,
|
||||
GeneralForm,
|
||||
ThemeSettingsForm,
|
||||
WeatherForm,
|
||||
} from '../interfaces';
|
||||
|
||||
export type ConfigFormData =
|
||||
| WeatherForm
|
||||
| SearchForm
|
||||
| GeneralForm
|
||||
| DockerSettingsForm
|
||||
| OtherSettingsForm
|
||||
| UISettingsForm
|
||||
| ThemeSettingsForm;
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue