Compare commits

...

65 Commits
v2.0 ... v2.2.2

Author SHA1 Message Date
pawelmalak
baac78021a Merge pull request #312 from pawelmalak/feature
Version 2.2.2
2022-03-21 15:05:07 +01:00
Paweł Malak
c2e81832a9 Added build scripts. Pushed version 2.2.2 2022-03-21 12:16:48 +01:00
pawelmalak
58d021dde6 Merge pull request #314 from LuckyF/chown-on-startup
fix: Update Permissions on Startup
2022-03-21 11:46:57 +01:00
Lukas Frischknecht
1098a04fb9 fix: Update Permissions on Startup 2022-02-17 19:27:40 +01:00
Paweł Malak
76dc3c44c8 Added option to get user location directly from the app 2022-02-14 13:58:57 +01:00
Paweł Malak
2d5cce9fdb Fixed bug with app description not updating. Fixed bug with local search prefix not working 2022-02-14 13:22:41 +01:00
Paweł Malak
12295a6f68 Moved some settings between general and ui tabs - continued. Fixed settings links in apps and categories tables 2022-02-04 15:01:40 +01:00
Paweł Malak
500e138643 Moved some settings between general and ui tabs 2022-02-04 14:59:48 +01:00
Paweł Malak
04e80b339c Changed order and names of some setting tabs 2022-02-04 13:09:47 +01:00
pawelmalak
750891cffa Merge pull request #288 from pawelmalak/feature
Version 2.2.1
2022-01-08 14:49:07 +01:00
Paweł Malak
fac8ef4027 Pushed version 2.2.1 2022-01-08 14:03:10 +01:00
Paweł Malak
19fb14d553 Merge branch 'feature' of https://github.com/pawelmalak/flame into feature 2022-01-08 13:17:26 +01:00
pawelmalak
5c84d90bf1 Merge pull request #278 from soulteary/bugfix/local-search-support-cjk
bugfix: local-search support CJK
2022-01-08 13:17:22 +01:00
Paweł Malak
6767b1dac0 Merge branch 'feature' of https://github.com/pawelmalak/flame into feature 2022-01-08 12:58:11 +01:00
pawelmalak
e0ecf34ced Merge pull request #282 from soulteary/chore/background-task-optimization
chore: bg-task optimization
2022-01-08 12:58:06 +01:00
Paweł Malak
396c442062 Added app descriptions to local search parser 2022-01-08 12:48:33 +01:00
soulteary
0044d265d1 chore: bg-task optimization 2022-01-04 14:18:54 +08:00
soulteary
19a910a91c bugfix: local-search support cjk 2022-01-04 13:26:50 +08:00
pawelmalak
6d8ce5361a Merge pull request #262 from pawelmalak/feature
Version 2.2.0
2021-12-17 13:41:29 +01:00
Paweł Malak
d2f99a5ec0 Pushed version 2.2.0 2021-12-17 12:56:51 +01:00
pawelmalak
c985fc17bf Merge pull request #254 from grahamhelton/master
Changed docker-run syntax to be more user friendly
2021-12-17 12:30:25 +01:00
pawelmalak
73cf66c592 Merge pull request #261 from pawelmalak/bug-k3s
Bug k3s
2021-12-17 12:29:49 +01:00
Paweł Malak
ee044ed2ff Fixed fatal error while deploying flame to cluster 2021-12-17 12:28:37 +01:00
pawelmalak
9dd3bd1f53 Merge pull request #248 from IDevJoe/master
Remove fatal error from docker secrets
2021-12-17 11:30:19 +01:00
Graham Helton
55a064c2a4 Changed docker-run syntax to be more user friendly 2021-12-11 23:39:23 -05:00
Joe Longendyke
c8436aaf03 Use tagged idevjoe/docker-secret 2021-12-08 08:19:42 +09:00
Joe Longendyke
edc01a341c Modify package.json for fixed docker-secret 2021-12-08 06:12:37 +09:00
Paweł Malak
531ede0adf Added option to set custom description for apps 2021-12-07 16:48:24 +01:00
Joe Longendyke
a536ad49ea Remove fatal error from docker secrets
This commit fixes #242 by catching the error thrown by getSecrets(). The underlying issue exists in docker-secret and has to do with the serviceAccount secret installed automatically by kubernetes.
2021-12-06 12:37:28 +09:00
pawelmalak
b08181e712 Merge pull request #241 from pawelmalak/feature
Version 2.1.1
2021-12-02 17:32:40 +01:00
Paweł Malak
bc077b658d Pushed version 2.1.1 2021-12-02 17:05:20 +01:00
Paweł Malak
48b91581b8 Docker secrets integration 2021-12-02 16:43:13 +01:00
pawelmalak
d1d32cdbe6 Merge pull request #211 from abbiewade/feature-docker-secret-integration
Add integration for docker secrets
2021-12-02 14:23:57 +01:00
pawelmalak
2b25a67bbf Merge branch 'feature' into feature-docker-secret-integration 2021-12-02 14:23:31 +01:00
Paweł Malak
64f1f28982 Added docker-secret for PR review. Updated some dependencies 2021-12-02 14:21:43 +01:00
Paweł Malak
f49ab6fd0d Updated node to version 16 2021-12-02 14:18:09 +01:00
Paweł Malak
068c8ab2e7 Changed some messages and buttons to make it easier to open bookmarks editor 2021-12-02 14:12:23 +01:00
pawelmalak
2ca90a18e1 Merge pull request #226 from pawelmalak/feature
Version 2.1.0
2021-11-26 14:52:32 +01:00
Paweł Malak
fcf2b87d1c Pushed version 2.1.0 2021-11-26 14:40:52 +01:00
Paweł Malak
d5610ad6be Fixed bug with alphabetical order not working for bookmarks. Minor changes related to bookmarks form 2021-11-26 14:04:46 +01:00
Paweł Malak
ec5f50aba4 Added option to reorder bookmarks 2021-11-25 16:54:27 +01:00
Paweł Malak
a02814aa02 Split BookmarksTable into separate components. Minor changes to reducers 2021-11-25 16:44:24 +01:00
Paweł Malak
e15c2a2f07 Reorder bookmarks action. Small refactor of state reducers 2021-11-22 17:15:01 +01:00
Paweł Malak
f1f7b698f8 Db migration to support custom order of bookmarks. Created route to reorder bookmarks. Added more sorting options to bookmark controllers. Simplified ordering in getAllApps controller 2021-11-22 16:45:59 +01:00
Paweł Malak
dfdd49cf4a Moved entityInUpdate to app state. It applies for apps, categories and bookmarks 2021-11-22 14:36:00 +01:00
Paweł Malak
d110d9b732 Empty sections will be hidden from guests. Fixed temperature value rounding. Added welcome message 2021-11-22 12:29:47 +01:00
Paweł Malak
882f011d07 Cleaned up Apps and Bookmarks containers. Changed AppTable to use TableActions component 2021-11-20 14:51:47 +01:00
Paweł Malak
8941f8f2f4 Added support for .ico files 2021-11-20 14:18:42 +01:00
Paweł Malak
089ace562a Moved table actions to separate component 2021-11-20 14:17:51 +01:00
pawelmalak
f963c1980b Merge pull request #216 from pawelmalak/fix
Fixed failing migration
2021-11-20 11:36:39 +01:00
Paweł Malak
1ff2c7afd9 Fixed failing migration 2021-11-20 11:19:53 +01:00
Abbie Wade
7a8808df4f added integration for docker secrets 2021-11-20 10:54:34 +11:00
pawelmalak
4c1c0087c7 Update issue templates 2021-11-19 22:07:03 +01:00
pawelmalak
fd7d8e65c8 Merge pull request #206 from pawelmalak/feature
Version 2.0.1
2021-11-19 15:02:58 +01:00
Paweł Malak
55b70eebbd Updated changelog 2021-11-19 15:02:33 +01:00
Paweł Malak
d13b890e16 Fixed bug with value parsing if custom icon was used 2021-11-19 14:06:38 +01:00
Paweł Malak
c2e9f82cd6 Improved default theme setting. Pushed version 2.0.1 2021-11-19 13:24:07 +01:00
pawelmalak
e0f6034868 Merge pull request #205 from pawelmalak/auth-header
Changed auth header
2021-11-19 12:42:05 +01:00
Paweł Malak
e13f6f2612 Changed auth header 2021-11-19 12:41:32 +01:00
Paweł Malak
85a65aef52 Added option to hide header greetings and date separately 2021-11-18 16:03:44 +01:00
Paweł Malak
5cf7708ab8 Added humidity option to weather widget 2021-11-18 15:14:53 +01:00
Paweł Malak
a549149452 Database migration to support more weather properties 2021-11-18 14:16:57 +01:00
Paweł Malak
e2285e2deb Moved Themer to Settings. Added option to set default theme 2021-11-18 13:47:27 +01:00
Paweł Malak
426766225b Fixed bug with custom icons not working with apps 2021-11-18 13:05:32 +01:00
pawelmalak
1220c56fc5 Fixed bug with adding new apps with custom icon (#180)
* Bump url-parse from 1.5.1 to 1.5.3 in /client

Bumps [url-parse](https://github.com/unshiftio/url-parse) from 1.5.1 to 1.5.3.
- [Release notes](https://github.com/unshiftio/url-parse/releases)
- [Commits](https://github.com/unshiftio/url-parse/compare/1.5.1...1.5.3)

---
updated-dependencies:
- dependency-name: url-parse
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump dns-packet from 1.3.1 to 1.3.4 in /client

Bumps [dns-packet](https://github.com/mafintosh/dns-packet) from 1.3.1 to 1.3.4.
- [Release notes](https://github.com/mafintosh/dns-packet/releases)
- [Changelog](https://github.com/mafintosh/dns-packet/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mafintosh/dns-packet/compare/v1.3.1...v1.3.4)

---
updated-dependencies:
- dependency-name: dns-packet
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump ws from 6.2.1 to 6.2.2 in /client

Bumps [ws](https://github.com/websockets/ws) from 6.2.1 to 6.2.2.
- [Release notes](https://github.com/websockets/ws/releases)
- [Commits](https://github.com/websockets/ws/compare/6.2.1...6.2.2)

---
updated-dependencies:
- dependency-name: ws
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

* Fixed #177

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-11-15 16:34:12 +01:00
122 changed files with 28421 additions and 1457 deletions

2
.dev/build_latest.sh Normal file
View File

@@ -0,0 +1,2 @@
docker build -t pawelmalak/flame -t "pawelmalak/flame:$1" -f .docker/Dockerfile "$2" \
&& docker push pawelmalak/flame && docker push "pawelmalak/flame:$1"

6
.dev/build_multiarch.sh Normal file
View 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 "$2"

View File

@@ -1,4 +1,4 @@
FROM node:14 as builder FROM node:16 as builder
WORKDIR /app WORKDIR /app
@@ -16,7 +16,7 @@ RUN mkdir -p ./public ./data \
&& mv ./client/build/* ./public \ && mv ./client/build/* ./public \
&& rm -rf ./client && rm -rf ./client
FROM node:14-alpine FROM node:16-alpine
COPY --from=builder /app /app COPY --from=builder /app /app
@@ -27,4 +27,4 @@ EXPOSE 5005
ENV NODE_ENV=production ENV NODE_ENV=production
ENV PASSWORD=flame_password ENV PASSWORD=flame_password
CMD ["node", "server.js"] CMD ["sh", "-c", "chown -R node /app/data && node server.js"]

View File

@@ -1,10 +1,10 @@
FROM node:14-alpine3.11 as builder FROM node:16-alpine3.11 as builder
WORKDIR /app WORKDIR /app
COPY package*.json ./ 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 && npm install --production
COPY . . COPY . .
@@ -17,7 +17,7 @@ RUN mkdir -p ./public ./data \
&& mv ./client/build/* ./public \ && mv ./client/build/* ./public \
&& rm -rf ./client && rm -rf ./client
FROM node:14-alpine3.11 FROM node:16-alpine3.11
COPY --from=builder /app /app COPY --from=builder /app /app
@@ -28,4 +28,4 @@ EXPOSE 5005
ENV NODE_ENV=production ENV NODE_ENV=production
ENV PASSWORD=flame_password ENV PASSWORD=flame_password
CMD ["node", "server.js"] CMD ["sh", "-c", "chown -R node /app/data && node server.js"]

View File

@@ -1,12 +1,22 @@
version: '3' version: '3.6'
services: services:
flame: flame:
image: pawelmalak/flame image: pawelmalak/flame
container_name: flame container_name: flame
volumes: 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: ports:
- 5005:5005 - 5005:5005
# secrets:
# - password # optional but required for (1)
environment: environment:
- PASSWORD=flame_password - PASSWORD=flame_password
# - PASSWORD_FILE=/run/secrets/password # optional but required for (1)
restart: unless-stopped restart: unless-stopped
# optional but required for Docker secrets (1)
# secrets:
# password:
# file: /path/to/secrets/password

View File

@@ -2,4 +2,5 @@ node_modules
.github .github
public public
k8s k8s
skaffold.yaml skaffold.yaml
data

2
.env
View File

@@ -1,5 +1,5 @@
PORT=5005 PORT=5005
NODE_ENV=development NODE_ENV=development
VERSION=2.0.0 VERSION=2.2.2
PASSWORD=flame_password PASSWORD=flame_password
SECRET=e02eb43d69953658c6d07311d6313f2d4467672cb881f96b29368ba1f3f4da4b SECRET=e02eb43d69953658c6d07311d6313f2d4467672cb881f96b29368ba1f3f4da4b

27
.github/ISSUE_TEMPLATE/bug_report.md vendored Normal file
View 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
View File

@@ -1,5 +1,4 @@
node_modules node_modules
data data
public public
!client/public !client/public
build.sh

View File

@@ -1 +1,2 @@
*.md *.md
docker-compose.yml

View File

@@ -1,3 +1,40 @@
### 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))
- Added option to hide header greetings and date separately ([#200](https://github.com/pawelmalak/flame/issues/200))
- Fixed bug with broken basic auth ([#202](https://github.com/pawelmalak/flame/issues/202))
- Fixed bug with parsing visibility value for apps and bookmarks when custom icon was used ([#203](https://github.com/pawelmalak/flame/issues/203))
- Fixed bug with custom icons not working with apps when "pin by default" was disabled
### v2.0.0 (2021-11-15) ### v2.0.0 (2021-11-15)
- Added authentication system: - Added authentication system:
- Only logged in user can access settings ([#33](https://github.com/pawelmalak/flame/issues/33)) - Only logged in user can access settings ([#33](https://github.com/pawelmalak/flame/issues/33))

View File

@@ -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 - 📌 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 - 🔍 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 - 🔑 Authentication system to protect your settings, apps and bookmarks
- 🔨 Dozens of option 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 and 15 built-in color themes
- ☀️ Weather widget with current temperature, cloud coverage and animated weather status - ☀️ Weather widget with current temperature, cloud coverage and animated weather status
- 🐳 Docker integration to automatically pick and add apps based on their labels - 🐳 Docker integration to automatically pick and add apps based on their labels
@@ -35,7 +35,7 @@ docker pull pawelmalak/flame:2.0.0
```sh ```sh
# run container # 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 #### Building images
@@ -55,19 +55,42 @@ docker buildx build \
#### Docker-Compose #### Docker-Compose
```yaml ```yaml
version: '2.1' version: '3.6'
services: services:
flame: flame:
image: pawelmalak/flame:latest image: pawelmalak/flame
container_name: flame container_name: flame
volumes: volumes:
- <host_dir>:/app/data - /path/to/host/data:/app/data
- /var/run/docker.sock:/var/run/docker.sock # optional but required for Docker integration feature - /var/run/docker.sock:/var/run/docker.sock # optional but required for Docker integration
ports: ports:
- 5005:5005 - 5005:5005
secrets:
- password # optional but required for (1)
environment: environment:
- PASSWORD=flame_password - PASSWORD=flame_password
- PASSWORD_FILE=/run/secrets/password # optional but required for (1)
restart: unless-stopped 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 #### Skaffold
@@ -212,7 +235,7 @@ metadata:
- Backup your `db.sqlite` before running script! - Backup your `db.sqlite` before running script!
- Known Issues: - Known Issues:
- generated icons are sometimes incorrect - generated icons are sometimes incorrect
```bash ```bash
pip3 install Pillow, beautifulsoup4 pip3 install Pillow, beautifulsoup4

View File

@@ -1 +1 @@
REACT_APP_VERSION=2.0.0 REACT_APP_VERSION=2.2.2

21815
client/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -11,7 +11,6 @@
"@types/jest": "^27.0.2", "@types/jest": "^27.0.2",
"@types/node": "^16.11.6", "@types/node": "^16.11.6",
"@types/react": "^17.0.34", "@types/react": "^17.0.34",
"@types/react-autosuggest": "^10.1.5",
"@types/react-beautiful-dnd": "^13.1.2", "@types/react-beautiful-dnd": "^13.1.2",
"@types/react-dom": "^17.0.11", "@types/react-dom": "^17.0.11",
"@types/react-redux": "^7.1.20", "@types/react-redux": "^7.1.20",
@@ -21,7 +20,6 @@
"http-proxy-middleware": "^2.0.1", "http-proxy-middleware": "^2.0.1",
"jwt-decode": "^3.1.2", "jwt-decode": "^3.1.2",
"react": "^17.0.2", "react": "^17.0.2",
"react-autosuggest": "^10.1.0",
"react-beautiful-dnd": "^13.1.0", "react-beautiful-dnd": "^13.1.0",
"react-dom": "^17.0.2", "react-dom": "^17.0.2",
"react-redux": "^7.2.6", "react-redux": "^7.2.6",

View File

@@ -1,7 +1,13 @@
import { useEffect } from 'react';
import { BrowserRouter, Route, Switch } from 'react-router-dom'; import { BrowserRouter, Route, Switch } from 'react-router-dom';
import 'external-svg-loader';
// Redux
import { useDispatch, useSelector } from 'react-redux';
import { bindActionCreators } from 'redux';
import { autoLogin, getConfig } from './store/action-creators'; import { autoLogin, getConfig } from './store/action-creators';
import { actionCreators, store } from './store'; import { actionCreators, store } from './store';
import 'external-svg-loader'; import { State } from './store/reducers';
// Utils // Utils
import { checkVersion, decodeToken } from './utility'; import { checkVersion, decodeToken } from './utility';
@@ -12,9 +18,6 @@ import { Apps } from './components/Apps/Apps';
import { Settings } from './components/Settings/Settings'; import { Settings } from './components/Settings/Settings';
import { Bookmarks } from './components/Bookmarks/Bookmarks'; import { Bookmarks } from './components/Bookmarks/Bookmarks';
import { NotificationCenter } from './components/NotificationCenter/NotificationCenter'; import { NotificationCenter } from './components/NotificationCenter/NotificationCenter';
import { useDispatch } from 'react-redux';
import { bindActionCreators } from 'redux';
import { useEffect } from 'react';
// Get config // Get config
store.dispatch<any>(getConfig()); store.dispatch<any>(getConfig());
@@ -25,6 +28,8 @@ if (localStorage.token) {
} }
export const App = (): JSX.Element => { export const App = (): JSX.Element => {
const { config, loading } = useSelector((state: State) => state.config);
const dispath = useDispatch(); const dispath = useDispatch();
const { fetchQueries, setTheme, logout, createNotification } = const { fetchQueries, setTheme, logout, createNotification } =
bindActionCreators(actionCreators, dispath); bindActionCreators(actionCreators, dispath);
@@ -46,7 +51,7 @@ export const App = (): JSX.Element => {
} }
}, 1000); }, 1000);
// set theme // set user theme if present
if (localStorage.theme) { if (localStorage.theme) {
setTheme(localStorage.theme); setTheme(localStorage.theme);
} }
@@ -60,6 +65,13 @@ export const App = (): JSX.Element => {
return () => window.clearInterval(tokenIsValid); return () => window.clearInterval(tokenIsValid);
}, []); }, []);
// If there is no user theme, set the default one
useEffect(() => {
if (!loading && !localStorage.theme) {
setTheme(config.defaultTheme, false);
}
}, [loading]);
return ( return (
<> <>
<BrowserRouter> <BrowserRouter>

View File

@@ -0,0 +1,12 @@
.TableActions {
display: flex;
align-items: center;
}
.TableAction {
width: 22px;
}
.TableAction:hover {
cursor: pointer;
}

View 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>
);
};

View File

@@ -8,16 +8,15 @@ import { State } from '../../../store/reducers';
interface Props { interface Props {
app: App; 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 { config } = useSelector((state: State) => state.config);
const [displayUrl, redirectUrl] = urlParser(props.app.url); const [displayUrl, redirectUrl] = urlParser(app.url);
let iconEl: JSX.Element; let iconEl: JSX.Element;
const { icon } = props.app; const { icon } = app;
if (isImage(icon)) { if (isImage(icon)) {
const source = isUrl(icon) ? icon : `/uploads/${icon}`; const source = isUrl(icon) ? icon : `/uploads/${icon}`;
@@ -25,7 +24,7 @@ export const AppCard = (props: Props): JSX.Element => {
iconEl = ( iconEl = (
<img <img
src={source} src={source}
alt={`${props.app.name} icon`} alt={`${app.name} icon`}
className={classes.CustomIcon} className={classes.CustomIcon}
/> />
); );
@@ -54,8 +53,8 @@ export const AppCard = (props: Props): JSX.Element => {
> >
<div className={classes.AppCardIcon}>{iconEl}</div> <div className={classes.AppCardIcon}>{iconEl}</div>
<div className={classes.AppCardDetails}> <div className={classes.AppCardDetails}>
<h5>{props.app.name}</h5> <h5>{app.name}</h5>
<span>{displayUrl}</span> <span>{!app.description.length ? displayUrl : app.description}</span>
</div> </div>
</a> </a>
); );

View File

@@ -1,6 +1,6 @@
import { useState, useEffect, ChangeEvent, SyntheticEvent } from 'react'; import { useState, useEffect, ChangeEvent, SyntheticEvent } from 'react';
import { useDispatch } from 'react-redux'; import { useDispatch, useSelector } from 'react-redux';
import { App, NewApp } from '../../../interfaces'; import { NewApp } from '../../../interfaces';
import classes from './AppForm.module.css'; import classes from './AppForm.module.css';
@@ -8,29 +8,34 @@ import { ModalForm, InputGroup, Button } from '../../UI';
import { inputHandler, newAppTemplate } from '../../../utility'; import { inputHandler, newAppTemplate } from '../../../utility';
import { bindActionCreators } from 'redux'; import { bindActionCreators } from 'redux';
import { actionCreators } from '../../../store'; import { actionCreators } from '../../../store';
import { State } from '../../../store/reducers';
interface Props { interface Props {
modalHandler: () => void; 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 dispatch = useDispatch();
const { addApp, updateApp } = bindActionCreators(actionCreators, dispatch); const { addApp, updateApp, setEditApp } = bindActionCreators(
actionCreators,
dispatch
);
const [useCustomIcon, toggleUseCustomIcon] = useState<boolean>(false); const [useCustomIcon, toggleUseCustomIcon] = useState<boolean>(false);
const [customIcon, setCustomIcon] = useState<File | null>(null); const [customIcon, setCustomIcon] = useState<File | null>(null);
const [formData, setFormData] = useState<NewApp>(newAppTemplate); const [formData, setFormData] = useState<NewApp>(newAppTemplate);
useEffect(() => { useEffect(() => {
if (app) { if (appInUpdate) {
setFormData({ setFormData({
...app, ...appInUpdate,
}); });
} else { } else {
setFormData(newAppTemplate); setFormData(newAppTemplate);
} }
}, [app]); }, [appInUpdate]);
const inputChangeHandler = ( const inputChangeHandler = (
e: ChangeEvent<HTMLInputElement | HTMLSelectElement>, e: ChangeEvent<HTMLInputElement | HTMLSelectElement>,
@@ -59,14 +64,16 @@ export const AppForm = ({ app, modalHandler }: Props): JSX.Element => {
if (customIcon) { if (customIcon) {
data.append('icon', customIcon); data.append('icon', customIcon);
} }
data.append('name', formData.name); data.append('name', formData.name);
data.append('description', formData.description);
data.append('url', formData.url); data.append('url', formData.url);
data.append('isPublic', `${formData.isPublic}`); data.append('isPublic', `${formData.isPublic ? 1 : 0}`);
return data; return data;
}; };
if (!app) { if (!appInUpdate) {
if (customIcon) { if (customIcon) {
const data = createFormData(); const data = createFormData();
addApp(data); addApp(data);
@@ -76,21 +83,22 @@ export const AppForm = ({ app, modalHandler }: Props): JSX.Element => {
} else { } else {
if (customIcon) { if (customIcon) {
const data = createFormData(); const data = createFormData();
updateApp(app.id, data); updateApp(appInUpdate.id, data);
} else { } else {
updateApp(app.id, formData); updateApp(appInUpdate.id, formData);
modalHandler(); modalHandler();
} }
} }
setFormData(newAppTemplate); setFormData(newAppTemplate);
setEditApp(null);
}; };
return ( return (
<ModalForm modalHandler={modalHandler} formHandler={formSubmitHandler}> <ModalForm modalHandler={modalHandler} formHandler={formSubmitHandler}>
{/* NAME */} {/* NAME */}
<InputGroup> <InputGroup>
<label htmlFor="name">App Name</label> <label htmlFor="name">App name</label>
<input <input
type="text" type="text"
name="name" name="name"
@@ -116,11 +124,27 @@ export const AppForm = ({ app, modalHandler }: Props): JSX.Element => {
/> />
</InputGroup> </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 */} {/* ICON */}
{!useCustomIcon ? ( {!useCustomIcon ? (
// use mdi icon // use mdi icon
<InputGroup> <InputGroup>
<label htmlFor="icon">App Icon</label> <label htmlFor="icon">App icon</label>
<input <input
type="text" type="text"
name="icon" name="icon"
@@ -154,7 +178,7 @@ export const AppForm = ({ app, modalHandler }: Props): JSX.Element => {
id="icon" id="icon"
required required
onChange={(e) => fileChangeHandler(e)} onChange={(e) => fileChangeHandler(e)}
accept=".jpg,.jpeg,.png,.svg" accept=".jpg,.jpeg,.png,.svg,.ico"
/> />
<span <span
onClick={() => { onClick={() => {
@@ -182,7 +206,7 @@ export const AppForm = ({ app, modalHandler }: Props): JSX.Element => {
</select> </select>
</InputGroup> </InputGroup>
{!app ? ( {!appInUpdate ? (
<Button>Add new application</Button> <Button>Add new application</Button>
) : ( ) : (
<Button>Update application</Button> <Button>Update application</Button>

View File

@@ -20,21 +20,3 @@
grid-template-columns: repeat(4, 1fr); 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;
}

View File

@@ -3,6 +3,7 @@ import { Link } from 'react-router-dom';
import { App } from '../../../interfaces/App'; import { App } from '../../../interfaces/App';
import { AppCard } from '../AppCard/AppCard'; import { AppCard } from '../AppCard/AppCard';
import { Message } from '../../UI';
interface Props { interface Props {
apps: App[]; apps: App[];
@@ -13,36 +14,32 @@ interface Props {
export const AppGrid = (props: Props): JSX.Element => { export const AppGrid = (props: Props): JSX.Element => {
let apps: JSX.Element; let apps: JSX.Element;
if (props.apps.length > 0) { if (props.searching || props.apps.length) {
apps = ( if (!props.apps.length) {
<div className={classes.AppGrid}> apps = <Message>No apps match your search criteria</Message>;
{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>
);
}
} else { } else {
apps = ( 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{' '} You don't have any applications. You can add a new one from{' '}
<Link to="/applications">/applications</Link> menu <Link to="/applications">/applications</Link> menu
</p> </Message>
); );
} }
} }

View File

@@ -1,4 +1,4 @@
import { Fragment, KeyboardEvent, useState, useEffect } from 'react'; import { Fragment, useState, useEffect } from 'react';
import { import {
DragDropContext, DragDropContext,
Droppable, Droppable,
@@ -9,21 +9,19 @@ import { Link } from 'react-router-dom';
// Redux // Redux
import { useDispatch, useSelector } from 'react-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 { State } from '../../../store/reducers';
import { bindActionCreators } from 'redux'; import { bindActionCreators } from 'redux';
import { actionCreators } from '../../../store'; import { actionCreators } from '../../../store';
// Typescript
import { App } from '../../../interfaces';
// Other
import { Message, Table } from '../../UI';
import { TableActions } from '../../Actions/TableActions';
interface Props { interface Props {
updateAppHandler: (app: App) => void; openFormForUpdating: (app: App) => void;
} }
export const AppTable = (props: Props): JSX.Element => { export const AppTable = (props: Props): JSX.Element => {
@@ -33,49 +31,18 @@ export const AppTable = (props: Props): JSX.Element => {
} = useSelector((state: State) => state); } = useSelector((state: State) => state);
const dispatch = useDispatch(); const dispatch = useDispatch();
const { pinApp, deleteApp, reorderApps, updateConfig, createNotification } = const { pinApp, deleteApp, reorderApps, createNotification, updateApp } =
bindActionCreators(actionCreators, dispatch); bindActionCreators(actionCreators, dispatch);
const [localApps, setLocalApps] = useState<App[]>([]); const [localApps, setLocalApps] = useState<App[]>([]);
const [isCustomOrder, setIsCustomOrder] = useState<boolean>(false);
// Copy apps array // Copy apps array
useEffect(() => { useEffect(() => {
setLocalApps([...apps]); setLocalApps([...apps]);
}, [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 => { const dragEndHanlder = (result: DropResult): void => {
if (!isCustomOrder) { if (config.useOrdering !== 'orderId') {
createNotification({ createNotification({
title: 'Error', title: 'Error',
message: 'Custom order is disabled', message: 'Custom order is disabled',
@@ -95,18 +62,43 @@ export const AppTable = (props: Props): JSX.Element => {
reorderApps(tmpApps); 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 ( return (
<Fragment> <Fragment>
<div className={classes.Message}> <Message isPrimary={false}>
{isCustomOrder ? ( {config.useOrdering === 'orderId' ? (
<p>You can drag and drop single rows to reorder application</p> <p>You can drag and drop single rows to reorder application</p>
) : ( ) : (
<p> <p>
Custom order is disabled. You can change it in{' '} Custom order is disabled. You can change it in the{' '}
<Link to="/settings/other">settings</Link> <Link to="/settings/general">settings</Link>
</p> </p>
)} )}
</div> </Message>
<DragDropContext onDragEnd={dragEndHanlder}> <DragDropContext onDragEnd={dragEndHanlder}>
<Droppable droppableId="apps"> <Droppable droppableId="apps">
{(provided) => ( {(provided) => (
@@ -143,54 +135,15 @@ export const AppTable = (props: Props): JSX.Element => {
<td style={{ width: '200px' }}> <td style={{ width: '200px' }}>
{app.isPublic ? 'Visible' : 'Hidden'} {app.isPublic ? 'Visible' : 'Hidden'}
</td> </td>
{!snapshot.isDragging && ( {!snapshot.isDragging && (
<td className={classes.TableActions}> <TableActions
<div entity={app}
className={classes.TableAction} deleteHandler={deleteAppHandler}
onClick={() => deleteAppHandler(app)} updateHandler={updateAppHandler}
onKeyDown={(e) => pinHanlder={pinAppHandler}
keyboardActionHandler( changeVisibilty={changeAppVisibiltyHandler}
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>
)} )}
</tr> </tr>
); );

View File

@@ -19,7 +19,6 @@ import { AppForm } from './AppForm/AppForm';
import { AppTable } from './AppTable/AppTable'; import { AppTable } from './AppTable/AppTable';
// Utils // Utils
import { appTemplate } from '../../utility';
import { State } from '../../store/reducers'; import { State } from '../../store/reducers';
import { bindActionCreators } from 'redux'; import { bindActionCreators } from 'redux';
import { actionCreators } from '../../store'; import { actionCreators } from '../../store';
@@ -29,57 +28,53 @@ interface Props {
} }
export const Apps = (props: Props): JSX.Element => { export const Apps = (props: Props): JSX.Element => {
// Get Redux state
const { const {
apps: { apps, loading }, apps: { apps, loading },
auth: { isAuthenticated }, auth: { isAuthenticated },
} = useSelector((state: State) => state); } = useSelector((state: State) => state);
// Get Redux action creators
const dispatch = useDispatch(); const dispatch = useDispatch();
const { getApps } = bindActionCreators(actionCreators, dispatch); const { getApps, setEditApp } = bindActionCreators(actionCreators, dispatch);
const [modalIsOpen, setModalIsOpen] = useState(false);
const [isInEdit, setIsInEdit] = useState(false);
const [isInUpdate, setIsInUpdate] = useState(false);
const [appInUpdate, setAppInUpdate] = useState<App>(appTemplate);
// Load apps if array is empty
useEffect(() => { useEffect(() => {
if (!apps.length) { if (!apps.length) {
getApps(); 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(() => { useEffect(() => {
if (!isAuthenticated) { if (!isAuthenticated) {
setIsInEdit(false); setShowTable(false);
setModalIsOpen(false); setModalIsOpen(false);
} }
}, [isAuthenticated]); }, [isAuthenticated]);
// Form actions
const toggleModal = (): void => { const toggleModal = (): void => {
setModalIsOpen(!modalIsOpen); setModalIsOpen(!modalIsOpen);
setIsInUpdate(false);
}; };
const toggleEdit = (): void => { const toggleEdit = (): void => {
setIsInEdit(!isInEdit); setShowTable(!showTable);
setIsInUpdate(false);
}; };
const toggleUpdate = (app: App): void => { const openFormForUpdating = (app: App): void => {
setAppInUpdate(app); setEditApp(app);
setIsInUpdate(true);
setModalIsOpen(true); setModalIsOpen(true);
}; };
return ( return (
<Container> <Container>
<Modal isOpen={modalIsOpen} setIsOpen={setModalIsOpen}> <Modal isOpen={modalIsOpen} setIsOpen={setModalIsOpen}>
{!isInUpdate ? ( <AppForm modalHandler={toggleModal} />
<AppForm modalHandler={toggleModal} />
) : (
<AppForm modalHandler={toggleModal} app={appInUpdate} />
)}
</Modal> </Modal>
<Headline <Headline
@@ -89,7 +84,14 @@ export const Apps = (props: Props): JSX.Element => {
{isAuthenticated && ( {isAuthenticated && (
<div className={classes.ActionsContainer}> <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} /> <ActionButton name="Edit" icon="mdiPencil" handler={toggleEdit} />
</div> </div>
)} )}
@@ -97,10 +99,10 @@ export const Apps = (props: Props): JSX.Element => {
<div className={classes.Apps}> <div className={classes.Apps}>
{loading ? ( {loading ? (
<Spinner /> <Spinner />
) : !isInEdit ? ( ) : !showTable ? (
<AppGrid apps={apps} searching={props.searching} /> <AppGrid apps={apps} searching={props.searching} />
) : ( ) : (
<AppTable updateAppHandler={toggleUpdate} /> <AppTable openFormForUpdating={openFormForUpdating} />
)} )}
</div> </div>
</Container> </Container>

View File

@@ -10,6 +10,10 @@
text-transform: uppercase; text-transform: uppercase;
} }
.BookmarkHeader:hover {
cursor: pointer;
}
.Bookmarks { .Bookmarks {
display: flex; display: flex;
flex-direction: column; flex-direction: column;

View File

@@ -1,28 +1,52 @@
import { Fragment } from 'react'; import { Fragment } from 'react';
import { useSelector } from 'react-redux'; // Redux
import { useDispatch, useSelector } from 'react-redux';
import { State } from '../../../store/reducers'; import { State } from '../../../store/reducers';
import { bindActionCreators } from 'redux';
import { actionCreators } from '../../../store';
// Typescript
import { Bookmark, Category } from '../../../interfaces'; import { Bookmark, Category } from '../../../interfaces';
// Other
import classes from './BookmarkCard.module.css'; import classes from './BookmarkCard.module.css';
import { Icon } from '../../UI'; import { Icon } from '../../UI';
import { iconParser, isImage, isSvg, isUrl, urlParser } from '../../../utility'; import { iconParser, isImage, isSvg, isUrl, urlParser } from '../../../utility';
interface Props { interface Props {
category: Category; category: Category;
fromHomepage?: boolean;
} }
export const BookmarkCard = (props: Props): JSX.Element => { 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 ( return (
<div className={classes.BookmarkCard}> <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}> <div className={classes.Bookmarks}>
{props.category.bookmarks.map((bookmark: Bookmark) => { {category.bookmarks.map((bookmark: Bookmark) => {
const redirectUrl = urlParser(bookmark.url)[1]; const redirectUrl = urlParser(bookmark.url)[1];
let iconEl: JSX.Element = <Fragment></Fragment>; let iconEl: JSX.Element = <Fragment></Fragment>;

View File

@@ -20,12 +20,3 @@
grid-template-columns: repeat(4, 1fr); grid-template-columns: repeat(4, 1fr);
} }
} }
.BookmarksMessage {
color: var(--color-primary);
}
.BookmarksMessage a {
color: var(--color-accent);
font-weight: 600;
}

View File

@@ -5,48 +5,57 @@ import classes from './BookmarkGrid.module.css';
import { Category } from '../../../interfaces'; import { Category } from '../../../interfaces';
import { BookmarkCard } from '../BookmarkCard/BookmarkCard'; import { BookmarkCard } from '../BookmarkCard/BookmarkCard';
import { Message } from '../../UI';
interface Props { interface Props {
categories: Category[]; categories: Category[];
totalCategories?: number; totalCategories?: number;
searching: boolean; searching: boolean;
fromHomepage?: boolean;
} }
export const BookmarkGrid = (props: Props): JSX.Element => { export const BookmarkGrid = (props: Props): JSX.Element => {
const {
categories,
totalCategories,
searching,
fromHomepage = false,
} = props;
let bookmarks: JSX.Element; let bookmarks: JSX.Element;
if (props.categories.length) { if (categories.length) {
if (props.searching && !props.categories[0].bookmarks.length) { if (searching && !categories[0].bookmarks.length) {
bookmarks = ( bookmarks = <Message>No bookmarks match your search criteria</Message>;
<p className={classes.BookmarksMessage}>
No bookmarks match your search criteria
</p>
);
} else { } else {
bookmarks = ( bookmarks = (
<div className={classes.BookmarkGrid}> <div className={classes.BookmarkGrid}>
{props.categories.map( {categories.map(
(category: Category): JSX.Element => ( (category: Category): JSX.Element => (
<BookmarkCard category={category} key={category.id} /> <BookmarkCard
category={category}
fromHomepage={fromHomepage}
key={category.id}
/>
) )
)} )}
</div> </div>
); );
} }
} else { } else {
if (props.totalCategories) { if (totalCategories) {
bookmarks = ( bookmarks = (
<p className={classes.BookmarksMessage}> <Message>
There are no pinned categories. You can pin them from the{' '} There are no pinned categories. You can pin them from the{' '}
<Link to="/bookmarks">/bookmarks</Link> menu <Link to="/bookmarks">/bookmarks</Link> menu
</p> </Message>
); );
} else { } else {
bookmarks = ( bookmarks = (
<p className={classes.BookmarksMessage}> <Message>
You don't have any bookmarks. You can add a new one from{' '} You don't have any bookmarks. You can add a new one from{' '}
<Link to="/bookmarks">/bookmarks</Link> menu <Link to="/bookmarks">/bookmarks</Link> menu
</p> </Message>
); );
} }
} }

View File

@@ -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;
}

View File

@@ -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>
);
}
};

View File

@@ -14,15 +14,19 @@ import { Category, Bookmark } from '../../interfaces';
import classes from './Bookmarks.module.css'; import classes from './Bookmarks.module.css';
// UI // UI
import { Container, Headline, ActionButton, Spinner, Modal } from '../UI'; import {
Container,
Headline,
ActionButton,
Spinner,
Modal,
Message,
} from '../UI';
// Components // Components
import { BookmarkGrid } from './BookmarkGrid/BookmarkGrid'; import { BookmarkGrid } from './BookmarkGrid/BookmarkGrid';
import { BookmarkTable } from './BookmarkTable/BookmarkTable';
import { Form } from './Form/Form'; import { Form } from './Form/Form';
import { Table } from './Table/Table';
// Utils
import { bookmarkTemplate, categoryTemplate } from '../../utility';
interface Props { interface Props {
searching: boolean; searching: boolean;
@@ -34,74 +38,99 @@ export enum ContentType {
} }
export const Bookmarks = (props: Props): JSX.Element => { export const Bookmarks = (props: Props): JSX.Element => {
// Get Redux state
const { const {
bookmarks: { loading, categories }, bookmarks: { loading, categories, categoryInEdit },
auth: { isAuthenticated }, auth: { isAuthenticated },
} = useSelector((state: State) => state); } = useSelector((state: State) => state);
// Get Redux action creators
const dispatch = useDispatch(); const dispatch = useDispatch();
const { getCategories } = bindActionCreators(actionCreators, dispatch); const { getCategories, setEditCategory, setEditBookmark } =
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);
// Load categories if array is empty
useEffect(() => { useEffect(() => {
if (!categories.length) { if (!categories.length) {
getCategories(); 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(() => { useEffect(() => {
if (!isAuthenticated) { if (!isAuthenticated) {
setIsInEdit(false); setShowTable(false);
setModalIsOpen(false); setModalIsOpen(false);
} }
}, [isAuthenticated]); }, [isAuthenticated]);
useEffect(() => {
if (categoryInEdit && !modalIsOpen) {
setTableContentType(ContentType.bookmark);
setShowTable(true);
}
}, [categoryInEdit]);
useEffect(() => {
setShowTable(false);
setEditCategory(null);
}, []);
// Form actions
const toggleModal = (): void => { const toggleModal = (): void => {
setModalIsOpen(!modalIsOpen); setModalIsOpen(!modalIsOpen);
}; };
const addActionHandler = (contentType: ContentType) => { const openFormForAdding = (contentType: ContentType) => {
setFormContentType(contentType); setFormContentType(contentType);
setIsInUpdate(false); setIsInUpdate(false);
toggleModal(); toggleModal();
}; };
const editActionHandler = (contentType: ContentType) => { const openFormForUpdating = (data: Category | Bookmark): void => {
// We're in the edit mode and the same button was clicked - go back to list setIsInUpdate(true);
if (isInEdit && contentType === tableContentType) {
setIsInEdit(false); const instanceOfCategory = (object: any): object is Category => {
return 'bookmarks' in object;
};
if (instanceOfCategory(data)) {
setFormContentType(ContentType.category);
setEditCategory(data);
} else { } 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); setTableContentType(contentType);
} }
}; };
const instanceOfCategory = (object: any): object is Category => { const finishEditing = () => {
return 'bookmarks' in object; setShowTable(false);
}; setEditCategory(null);
const goToUpdateMode = (data: Category | Bookmark): void => {
setIsInUpdate(true);
if (instanceOfCategory(data)) {
setFormContentType(ContentType.category);
setCategoryInUpdate(data);
} else {
setFormContentType(ContentType.bookmark);
setBookmarkInUpdate(data);
}
toggleModal();
}; };
return ( return (
@@ -111,8 +140,6 @@ export const Bookmarks = (props: Props): JSX.Element => {
modalHandler={toggleModal} modalHandler={toggleModal}
contentType={formContentType} contentType={formContentType}
inUpdate={isInUpdate} inUpdate={isInUpdate}
category={categoryInUpdate}
bookmark={bookmarkInUpdate}
/> />
</Modal> </Modal>
@@ -123,35 +150,44 @@ export const Bookmarks = (props: Props): JSX.Element => {
<ActionButton <ActionButton
name="Add Category" name="Add Category"
icon="mdiPlusBox" icon="mdiPlusBox"
handler={() => addActionHandler(ContentType.category)} handler={() => openFormForAdding(ContentType.category)}
/> />
<ActionButton <ActionButton
name="Add Bookmark" name="Add Bookmark"
icon="mdiPlusBox" icon="mdiPlusBox"
handler={() => addActionHandler(ContentType.bookmark)} handler={() => openFormForAdding(ContentType.bookmark)}
/> />
<ActionButton <ActionButton
name="Edit Categories" name="Edit Categories"
icon="mdiPencil" icon="mdiPencil"
handler={() => editActionHandler(ContentType.category)} handler={() => showTableForEditing(ContentType.category)}
/>
<ActionButton
name="Edit Bookmarks"
icon="mdiPencil"
handler={() => editActionHandler(ContentType.bookmark)}
/> />
{showTable && tableContentType === ContentType.bookmark && (
<ActionButton
name="Finish Editing"
icon="mdiPencil"
handler={finishEditing}
/>
)}
</div> </div>
)} )}
{categories.length && isAuthenticated && !showTable ? (
<Message isPrimary={false}>
Click on category name to edit its bookmarks
</Message>
) : (
<></>
)}
{loading ? ( {loading ? (
<Spinner /> <Spinner />
) : !isInEdit ? ( ) : !showTable ? (
<BookmarkGrid categories={categories} searching={props.searching} /> <BookmarkGrid categories={categories} searching={props.searching} />
) : ( ) : (
<BookmarkTable <Table
contentType={tableContentType} contentType={tableContentType}
categories={categories} openFormForUpdating={openFormForUpdating}
updateHandler={goToUpdateMode}
/> />
)} )}
</Container> </Container>

View File

@@ -77,7 +77,7 @@ export const BookmarksForm = ({
data.append('name', formData.name); data.append('name', formData.name);
data.append('url', formData.url); data.append('url', formData.url);
data.append('categoryId', `${formData.categoryId}`); data.append('categoryId', `${formData.categoryId}`);
data.append('isPublic', `${formData.isPublic}`); data.append('isPublic', `${formData.isPublic ? 1 : 0}`);
return data; return data;
}; };
@@ -137,15 +137,15 @@ export const BookmarksForm = ({
} }
modalHandler(); modalHandler();
setFormData(newBookmarkTemplate);
setCustomIcon(null);
} }
setFormData({ ...newBookmarkTemplate, categoryId: formData.categoryId });
setCustomIcon(null);
}; };
return ( return (
<ModalForm modalHandler={modalHandler} formHandler={formSubmitHandler}> <ModalForm modalHandler={modalHandler} formHandler={formSubmitHandler}>
{/* NAME */}
<InputGroup> <InputGroup>
<label htmlFor="name">Bookmark Name</label> <label htmlFor="name">Bookmark Name</label>
<input <input
@@ -159,6 +159,7 @@ export const BookmarksForm = ({
/> />
</InputGroup> </InputGroup>
{/* URL */}
<InputGroup> <InputGroup>
<label htmlFor="url">Bookmark URL</label> <label htmlFor="url">Bookmark URL</label>
<input <input
@@ -172,6 +173,7 @@ export const BookmarksForm = ({
/> />
</InputGroup> </InputGroup>
{/* CATEGORY */}
<InputGroup> <InputGroup>
<label htmlFor="categoryId">Bookmark Category</label> <label htmlFor="categoryId">Bookmark Category</label>
<select <select
@@ -192,6 +194,7 @@ export const BookmarksForm = ({
</select> </select>
</InputGroup> </InputGroup>
{/* ICON */}
{!useCustomIcon ? ( {!useCustomIcon ? (
// mdi // mdi
<InputGroup> <InputGroup>
@@ -227,7 +230,7 @@ export const BookmarksForm = ({
name="icon" name="icon"
id="icon" id="icon"
onChange={(e) => fileChangeHandler(e)} onChange={(e) => fileChangeHandler(e)}
accept=".jpg,.jpeg,.png,.svg" accept=".jpg,.jpeg,.png,.svg,.ico"
/> />
<span <span
onClick={() => { onClick={() => {
@@ -241,6 +244,7 @@ export const BookmarksForm = ({
</InputGroup> </InputGroup>
)} )}
{/* VISIBILTY */}
<InputGroup> <InputGroup>
<label htmlFor="isPublic">Bookmark visibility</label> <label htmlFor="isPublic">Bookmark visibility</label>
<select <select

View File

@@ -60,10 +60,10 @@ export const CategoryForm = ({
addCategory(formData); addCategory(formData);
} else { } else {
updateCategory(category.id, formData); updateCategory(category.id, formData);
modalHandler();
} }
setFormData(newCategoryTemplate); setFormData(newCategoryTemplate);
modalHandler();
}; };
return ( return (

View File

@@ -1,22 +1,26 @@
// Typescript // Typescript
import { Bookmark, Category } from '../../../interfaces';
import { ContentType } from '../Bookmarks'; import { ContentType } from '../Bookmarks';
// Utils // Utils
import { CategoryForm } from './CategoryForm'; import { CategoryForm } from './CategoryForm';
import { BookmarksForm } from './BookmarksForm'; import { BookmarksForm } from './BookmarksForm';
import { Fragment } from 'react'; import { Fragment } from 'react';
import { useSelector } from 'react-redux';
import { State } from '../../../store/reducers';
import { bookmarkTemplate, categoryTemplate } from '../../../utility';
interface Props { interface Props {
modalHandler: () => void; modalHandler: () => void;
contentType: ContentType; contentType: ContentType;
inUpdate?: boolean; inUpdate?: boolean;
category?: Category;
bookmark?: Bookmark;
} }
export const Form = (props: Props): JSX.Element => { 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 ( return (
<Fragment> <Fragment>
@@ -33,9 +37,15 @@ export const Form = (props: Props): JSX.Element => {
// form: update // form: update
<Fragment> <Fragment>
{contentType === ContentType.category ? ( {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> </Fragment>
)} )}

View 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&nbsp;<span>{categoryInEdit.name}</span>
&nbsp;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>
);
};

View 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>
);
};

View 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;
};

View File

@@ -1,6 +1,10 @@
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
// Redux
import { useSelector } from 'react-redux';
import { State } from '../../../store/reducers';
// CSS // CSS
import classes from './Header.module.css'; import classes from './Header.module.css';
@@ -12,6 +16,10 @@ import { getDateTime } from './functions/getDateTime';
import { greeter } from './functions/greeter'; import { greeter } from './functions/greeter';
export const Header = (): JSX.Element => { export const Header = (): JSX.Element => {
const { hideHeader, hideDate, showTime } = useSelector(
(state: State) => state.config.config
);
const [dateTime, setDateTime] = useState<string>(getDateTime()); const [dateTime, setDateTime] = useState<string>(getDateTime());
const [greeting, setGreeting] = useState<string>(greeter()); const [greeting, setGreeting] = useState<string>(greeter());
@@ -28,14 +36,18 @@ export const Header = (): JSX.Element => {
return ( return (
<header className={classes.Header}> <header className={classes.Header}>
<p>{dateTime}</p> {(!hideDate || showTime) && <p>{dateTime}</p>}
<Link to="/settings" className={classes.SettingsLink}> <Link to="/settings" className={classes.SettingsLink}>
Go to Settings Go to Settings
</Link> </Link>
<span className={classes.HeaderMain}>
<h1>{greeting}</h1> {!hideHeader && (
<WeatherWidget /> <span className={classes.HeaderMain}>
</span> <h1>{greeting}</h1>
<WeatherWidget />
</span>
)}
</header> </header>
); );
}; };

View File

@@ -30,22 +30,42 @@ export const getDateTime = (): string => {
const useAmericanDate = localStorage.useAmericanDate === 'true'; const useAmericanDate = localStorage.useAmericanDate === 'true';
const showTime = localStorage.showTime === 'true'; const showTime = localStorage.showTime === 'true';
const hideDate = localStorage.hideDate === 'true';
const p = parseTime; // Date
let dateEl = '';
const time = `${p(now.getHours())}:${p(now.getMinutes())}:${p( if (!hideDate) {
now.getSeconds() if (!useAmericanDate) {
)}`; dateEl = `${days[now.getDay()]}, ${now.getDate()} ${
months[now.getMonth()]
const timeEl = showTime ? ` - ${time}` : ''; } ${now.getFullYear()}`;
} else {
if (!useAmericanDate) { dateEl = `${days[now.getDay()]}, ${
return `${days[now.getDay()]}, ${now.getDate()} ${ months[now.getMonth()]
months[now.getMonth()] } ${now.getDate()} ${now.getFullYear()}`;
} ${now.getFullYear()}${timeEl}`; }
} else {
return `${days[now.getDay()]}, ${
months[now.getMonth()]
} ${now.getDate()} ${now.getFullYear()}${timeEl}`;
} }
// Time
const p = parseTime;
let timeEl = '';
if (showTime) {
const time = `${p(now.getHours())}:${p(now.getMinutes())}:${p(
now.getSeconds()
)}`;
timeEl = time;
}
// Separator
let separator = '';
if (!hideDate && showTime) {
separator = ' - ';
}
// Output
return `${dateEl}${separator}${timeEl}`;
}; };

View File

@@ -11,7 +11,7 @@ import { actionCreators } from '../../store';
import { App, Category } from '../../interfaces'; import { App, Category } from '../../interfaces';
// UI // UI
import { Icon, Container, SectionHeadline, Spinner } from '../UI'; import { Icon, Container, SectionHeadline, Spinner, Message } from '../UI';
// CSS // CSS
import classes from './Home.module.css'; import classes from './Home.module.css';
@@ -30,6 +30,7 @@ export const Home = (): JSX.Element => {
apps: { apps, loading: appsLoading }, apps: { apps, loading: appsLoading },
bookmarks: { categories, loading: bookmarksLoading }, bookmarks: { categories, loading: bookmarksLoading },
config: { config }, config: { config },
auth: { isAuthenticated },
} = useSelector((state: State) => state); } = useSelector((state: State) => state);
const dispatch = useDispatch(); const dispatch = useDispatch();
@@ -63,8 +64,10 @@ export const Home = (): JSX.Element => {
if (localSearch) { if (localSearch) {
// Search through apps // Search through apps
setAppSearchResult([ setAppSearchResult([
...apps.filter(({ name }) => ...apps.filter(({ name, description }) =>
new RegExp(escapeRegex(localSearch), 'i').test(name) new RegExp(escapeRegex(localSearch), 'i').test(
`${name} ${description}`
)
), ),
]); ]);
@@ -98,9 +101,20 @@ export const Home = (): JSX.Element => {
<div></div> <div></div>
)} )}
{!config.hideHeader ? <Header /> : <div></div>} <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> <Fragment>
<SectionHeadline title="Applications" link="/applications" /> <SectionHeadline title="Applications" link="/applications" />
{appsLoading ? ( {appsLoading ? (
@@ -119,10 +133,11 @@ export const Home = (): JSX.Element => {
<div className={classes.HomeSpace}></div> <div className={classes.HomeSpace}></div>
</Fragment> </Fragment>
) : ( ) : (
<div></div> <></>
)} )}
{!config.hideCategories ? ( {!config.hideCategories &&
(isAuthenticated || categories.some((c) => c.isPinned)) ? (
<Fragment> <Fragment>
<SectionHeadline title="Bookmarks" link="/bookmarks" /> <SectionHeadline title="Bookmarks" link="/bookmarks" />
{bookmarksLoading ? ( {bookmarksLoading ? (
@@ -138,11 +153,12 @@ export const Home = (): JSX.Element => {
} }
totalCategories={categories.length} totalCategories={categories.length}
searching={!!localSearch} searching={!!localSearch}
fromHomepage={true}
/> />
)} )}
</Fragment> </Fragment>
) : ( ) : (
<div></div> <></>
)} )}
<Link to="/settings" className={classes.SettingsButton}> <Link to="/settings" className={classes.SettingsButton}>

View File

@@ -1,43 +1,57 @@
import { Fragment } from 'react'; import { Fragment } from 'react';
// UI
import { Button, SettingsHeadline } from '../../UI'; import { Button, SettingsHeadline } from '../../UI';
import classes from './AppDetails.module.css';
import { checkVersion } from '../../../utility';
import { AuthForm } from './AuthForm/AuthForm'; 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 => { export const AppDetails = (): JSX.Element => {
const { isAuthenticated } = useSelector((state: State) => state.auth);
return ( return (
<Fragment> <Fragment>
<SettingsHeadline text="Authentication" /> <SettingsHeadline text="Authentication" />
<AuthForm /> <AuthForm />
<hr className={classes.separator} /> {isAuthenticated && (
<Fragment>
<hr className={classes.separator} />
<div> <div>
<SettingsHeadline text="App version" /> <SettingsHeadline text="App version" />
<p className={classes.text}> <p className={classes.text}>
<a <a
href="https://github.com/pawelmalak/flame" href="https://github.com/pawelmalak/flame"
target="_blank" target="_blank"
rel="noreferrer" rel="noreferrer"
> >
Flame Flame
</a>{' '} </a>{' '}
version {process.env.REACT_APP_VERSION} version {process.env.REACT_APP_VERSION}
</p> </p>
<p className={classes.text}> <p className={classes.text}>
See changelog{' '} See changelog{' '}
<a <a
href="https://github.com/pawelmalak/flame/blob/master/CHANGELOG.md" href="https://github.com/pawelmalak/flame/blob/master/CHANGELOG.md"
target="_blank" target="_blank"
rel="noreferrer" rel="noreferrer"
> >
here here
</a> </a>
</p> </p>
<Button click={() => checkVersion(true)}>Check for updates</Button> <Button click={() => checkVersion(true)}>Check for updates</Button>
</div> </div>
</Fragment>
)}
</Fragment> </Fragment>
); );
}; };

View File

@@ -1,4 +1,4 @@
import { FormEvent, Fragment, useEffect, useState } from 'react'; import { FormEvent, Fragment, useEffect, useState, useRef } from 'react';
// Redux // Redux
import { useSelector, useDispatch } from 'react-redux'; import { useSelector, useDispatch } from 'react-redux';
@@ -23,6 +23,12 @@ export const AuthForm = (): JSX.Element => {
duration: '14d', duration: '14d',
}); });
const passwordInputRef = useRef<HTMLInputElement>(null);
useEffect(() => {
passwordInputRef.current?.focus();
}, []);
useEffect(() => { useEffect(() => {
if (token) { if (token) {
const decoded = decodeToken(token); const decoded = decodeToken(token);
@@ -52,6 +58,7 @@ export const AuthForm = (): JSX.Element => {
name="password" name="password"
placeholder="••••••" placeholder="••••••"
autoComplete="current-password" autoComplete="current-password"
ref={passwordInputRef}
value={formData.password} value={formData.password}
onChange={(e) => onChange={(e) =>
setFormData({ ...formData, password: e.target.value }) setFormData({ ...formData, password: e.target.value })

View File

@@ -59,7 +59,7 @@ export const DockerSettings = (): JSX.Element => {
<SettingsHeadline text="Docker" /> <SettingsHeadline text="Docker" />
{/* CUSTOM DOCKER SOCKET HOST */} {/* CUSTOM DOCKER SOCKET HOST */}
<InputGroup> <InputGroup>
<label htmlFor="dockerHost">Docker Host</label> <label htmlFor="dockerHost">Docker host</label>
<input <input
type="text" type="text"
id="dockerHost" id="dockerHost"

View File

@@ -0,0 +1,212 @@
// 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 { queries } 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);
// 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 SETTINGS */}
<SettingsHeadline text="Search" />
<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>
<Button>Save changes</Button>
</form>
{/* CUSTOM QUERIES */}
<SettingsHeadline text="Custom search providers" />
<CustomQueries />
</Fragment>
);
};

View File

@@ -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>
);
};

View File

@@ -11,12 +11,12 @@ import { Route as SettingsRoute } from '../../interfaces';
import classes from './Settings.module.css'; import classes from './Settings.module.css';
// Components // Components
import { Themer } from '../Themer/Themer'; import { Themer } from './Themer/Themer';
import { WeatherSettings } from './WeatherSettings/WeatherSettings'; import { WeatherSettings } from './WeatherSettings/WeatherSettings';
import { UISettings } from './UISettings/UISettings'; import { UISettings } from './UISettings/UISettings';
import { AppDetails } from './AppDetails/AppDetails'; import { AppDetails } from './AppDetails/AppDetails';
import { StyleSettings } from './StyleSettings/StyleSettings'; import { StyleSettings } from './StyleSettings/StyleSettings';
import { SearchSettings } from './SearchSettings/SearchSettings'; import { GeneralSettings } from './GeneralSettings/GeneralSettings';
import { DockerSettings } from './DockerSettings/DockerSettings'; import { DockerSettings } from './DockerSettings/DockerSettings';
import { ProtectedRoute } from '../Routing/ProtectedRoute'; import { ProtectedRoute } from '../Routing/ProtectedRoute';
@@ -59,8 +59,8 @@ export const Settings = (): JSX.Element => {
component={WeatherSettings} component={WeatherSettings}
/> />
<ProtectedRoute <ProtectedRoute
path="/settings/search" path="/settings/general"
component={SearchSettings} component={GeneralSettings}
/> />
<ProtectedRoute path="/settings/interface" component={UISettings} /> <ProtectedRoute path="/settings/interface" component={UISettings} />
<ProtectedRoute <ProtectedRoute

View File

@@ -14,7 +14,6 @@
text-transform: capitalize; text-transform: capitalize;
margin: 8px 0; margin: 8px 0;
color: var(--color-primary); color: var(--color-primary);
/* align-self: flex-start; */
} }
.ColorsPreview { .ColorsPreview {
@@ -32,4 +31,4 @@
width: 40px; width: 40px;
height: 40px; height: 40px;
} }
} }

View File

@@ -1,4 +1,4 @@
import { Theme } from '../../interfaces/Theme'; import { Theme } from '../../../interfaces/Theme';
import classes from './ThemePreview.module.css'; import classes from './ThemePreview.module.css';
interface Props { interface Props {

View File

@@ -0,0 +1,101 @@
import { ChangeEvent, FormEvent, Fragment, useEffect, useState } from 'react';
// Redux
import { useDispatch, useSelector } from 'react-redux';
import { bindActionCreators } from 'redux';
import { actionCreators } from '../../../store';
// Typescript
import { Theme, ThemeSettingsForm } from '../../../interfaces';
// Components
import { ThemePreview } from './ThemePreview';
import { Button, InputGroup, SettingsHeadline } from '../../UI';
// Other
import classes from './Themer.module.css';
import { themes } from './themes.json';
import { State } from '../../../store/reducers';
import { inputHandler, themeSettingsTemplate } from '../../../utility';
export const Themer = (): JSX.Element => {
const {
auth: { isAuthenticated },
config: { loading, config },
} = useSelector((state: State) => state);
const dispatch = useDispatch();
const { setTheme, updateConfig } = bindActionCreators(
actionCreators,
dispatch
);
// Initial state
const [formData, setFormData] = useState<ThemeSettingsForm>(
themeSettingsTemplate
);
// 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<ThemeSettingsForm>({
e,
options,
setStateHandler: setFormData,
state: formData,
});
};
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>
{isAuthenticated && (
<form onSubmit={formSubmitHandler}>
<SettingsHeadline text="Other settings" />
<InputGroup>
<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}
</option>
))}
</select>
</InputGroup>
<Button>Save changes</Button>
</form>
)}
</Fragment>
);
};

View File

@@ -7,27 +7,22 @@ import { bindActionCreators } from 'redux';
import { actionCreators } from '../../../store'; import { actionCreators } from '../../../store';
// Typescript // Typescript
import { OtherSettingsForm } from '../../../interfaces'; import { UISettingsForm } from '../../../interfaces';
// UI // UI
import { InputGroup, Button, SettingsHeadline } from '../../UI'; import { InputGroup, Button, SettingsHeadline } from '../../UI';
// Utils // Utils
import { otherSettingsTemplate, inputHandler } from '../../../utility'; import { uiSettingsTemplate, inputHandler } from '../../../utility';
export const UISettings = (): JSX.Element => { export const UISettings = (): JSX.Element => {
const { loading, config } = useSelector((state: State) => state.config); const { loading, config } = useSelector((state: State) => state.config);
const dispatch = useDispatch(); const dispatch = useDispatch();
const { updateConfig, sortApps, sortCategories } = bindActionCreators( const { updateConfig } = bindActionCreators(actionCreators, dispatch);
actionCreators,
dispatch
);
// Initial state // Initial state
const [formData, setFormData] = useState<OtherSettingsForm>( const [formData, setFormData] = useState<UISettingsForm>(uiSettingsTemplate);
otherSettingsTemplate
);
// Get config // Get config
useEffect(() => { useEffect(() => {
@@ -45,10 +40,6 @@ export const UISettings = (): JSX.Element => {
// Update local page title // Update local page title
document.title = formData.customTitle; document.title = formData.customTitle;
// Sort apps and categories with new settings
sortApps();
sortCategories();
}; };
// Input handler // Input handler
@@ -56,7 +47,7 @@ export const UISettings = (): JSX.Element => {
e: ChangeEvent<HTMLInputElement | HTMLSelectElement>, e: ChangeEvent<HTMLInputElement | HTMLSelectElement>,
options?: { isNumber?: boolean; isBool?: boolean } options?: { isNumber?: boolean; isBool?: boolean }
) => { ) => {
inputHandler<OtherSettingsForm>({ inputHandler<UISettingsForm>({
e, e,
options, options,
setStateHandler: setFormData, setStateHandler: setFormData,
@@ -66,7 +57,7 @@ export const UISettings = (): JSX.Element => {
return ( return (
<form onSubmit={(e) => formSubmitHandler(e)}> <form onSubmit={(e) => formSubmitHandler(e)}>
{/* OTHER OPTIONS */} {/* === OTHER OPTIONS === */}
<SettingsHeadline text="Miscellaneous" /> <SettingsHeadline text="Miscellaneous" />
{/* PAGE TITLE */} {/* PAGE TITLE */}
<InputGroup> <InputGroup>
@@ -81,6 +72,82 @@ export const UISettings = (): JSX.Element => {
/> />
</InputGroup> </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 headline (greetings and weather)
</label>
<select
id="hideHeader"
name="hideHeader"
value={formData.hideHeader ? 1 : 0}
onChange={(e) => inputChangeHandler(e, { isBool: true })}
>
<option value={1}>True</option>
<option value={0}>False</option>
</select>
</InputGroup>
{/* HIDE DATE */}
<InputGroup>
<label htmlFor="hideDate">Hide date</label>
<select
id="hideDate"
name="hideDate"
value={formData.hideDate ? 1 : 0}
onChange={(e) => inputChangeHandler(e, { isBool: true })}
>
<option value={1}>True</option>
<option value={0}>False</option>
</select>
</InputGroup>
{/* HIDE TIME */}
<InputGroup>
<label htmlFor="showTime">Hide time</label>
<select
id="showTime"
name="showTime"
value={formData.showTime ? 1 : 0}
onChange={(e) => inputChangeHandler(e, { isBool: true })}
>
<option value={0}>True</option>
<option value={1}>False</option>
</select>
</InputGroup>
{/* DATE FORMAT */} {/* DATE FORMAT */}
<InputGroup> <InputGroup>
<label htmlFor="useAmericanDate">Date formatting</label> <label htmlFor="useAmericanDate">Date formatting</label>
@@ -95,99 +162,6 @@ export const UISettings = (): JSX.Element => {
</select> </select>
</InputGroup> </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>
{/* HEADER OPTIONS */}
<SettingsHeadline text="Header" />
{/* HIDE HEADER */}
<InputGroup>
<label htmlFor="hideHeader">Hide greeting and date</label>
<select
id="hideHeader"
name="hideHeader"
value={formData.hideHeader ? 1 : 0}
onChange={(e) => inputChangeHandler(e, { isBool: true })}
>
<option value={1}>True</option>
<option value={0}>False</option>
</select>
</InputGroup>
{/* CUSTOM GREETINGS */} {/* CUSTOM GREETINGS */}
<InputGroup> <InputGroup>
<label htmlFor="greetingsSchema">Custom greetings</label> <label htmlFor="greetingsSchema">Custom greetings</label>
@@ -200,8 +174,8 @@ export const UISettings = (): JSX.Element => {
onChange={(e) => inputChangeHandler(e)} onChange={(e) => inputChangeHandler(e)}
/> />
<span> <span>
Greetings must be separated with semicolon. Only 4 messages can be Greetings must be separated with semicolon. All 4 messages must be
used filled, even if they are the same
</span> </span>
</InputGroup> </InputGroup>
@@ -233,22 +207,8 @@ export const UISettings = (): JSX.Element => {
<span>Names must be separated with semicolon</span> <span>Names must be separated with semicolon</span>
</InputGroup> </InputGroup>
{/* SHOW TIME */} {/* === SECTIONS OPTIONS === */}
<InputGroup> <SettingsHeadline text="Sections" />
<label htmlFor="showTime">Show time</label>
<select
id="showTime"
name="showTime"
value={formData.showTime ? 1 : 0}
onChange={(e) => inputChangeHandler(e, { isBool: true })}
>
<option value={1}>True</option>
<option value={0}>False</option>
</select>
</InputGroup>
{/* MODULES OPTIONS */}
<SettingsHeadline text="Modules" />
{/* HIDE APPS */} {/* HIDE APPS */}
<InputGroup> <InputGroup>
<label htmlFor="hideApps">Hide applications</label> <label htmlFor="hideApps">Hide applications</label>

View File

@@ -11,7 +11,7 @@ import { State } from '../../../store/reducers';
import { ApiResponse, Weather, WeatherForm } from '../../../interfaces'; import { ApiResponse, Weather, WeatherForm } from '../../../interfaces';
// UI // UI
import { InputGroup, Button } from '../../UI'; import { InputGroup, Button, SettingsHeadline } from '../../UI';
// Utils // Utils
import { inputHandler, weatherSettingsTemplate } from '../../../utility'; import { inputHandler, weatherSettingsTemplate } from '../../../utility';
@@ -82,8 +82,23 @@ export const WeatherSettings = (): JSX.Element => {
}); });
}; };
// Get user location
const getLocation = () => {
window.navigator.geolocation.getCurrentPosition(
({ coords: { latitude, longitude } }) => {
setFormData({
...formData,
lat: latitude,
long: longitude,
});
}
);
};
return ( return (
<form onSubmit={(e) => formSubmitHandler(e)}> <form onSubmit={(e) => formSubmitHandler(e)}>
<SettingsHeadline text="API" />
{/* API KEY */}
<InputGroup> <InputGroup>
<label htmlFor="WEATHER_API_KEY">API key</label> <label htmlFor="WEATHER_API_KEY">API key</label>
<input <input
@@ -104,8 +119,10 @@ export const WeatherSettings = (): JSX.Element => {
</span> </span>
</InputGroup> </InputGroup>
<SettingsHeadline text="Location" />
{/* LAT */}
<InputGroup> <InputGroup>
<label htmlFor="lat">Location latitude</label> <label htmlFor="lat">Latitude</label>
<input <input
type="number" type="number"
id="lat" id="lat"
@@ -116,20 +133,14 @@ export const WeatherSettings = (): JSX.Element => {
step="any" step="any"
lang="en-150" lang="en-150"
/> />
<span> <span onClick={getLocation}>
You can use <a href="#">Click to get current location</a>
<a
href="https://www.latlong.net/convert-address-to-lat-long.html"
target="blank"
>
{' '}
latlong.net
</a>
</span> </span>
</InputGroup> </InputGroup>
{/* LONG */}
<InputGroup> <InputGroup>
<label htmlFor="long">Location longitude</label> <label htmlFor="long">Longitude</label>
<input <input
type="number" type="number"
id="long" id="long"
@@ -142,6 +153,8 @@ export const WeatherSettings = (): JSX.Element => {
/> />
</InputGroup> </InputGroup>
<SettingsHeadline text="Other" />
{/* TEMPERATURE */}
<InputGroup> <InputGroup>
<label htmlFor="isCelsius">Temperature unit</label> <label htmlFor="isCelsius">Temperature unit</label>
<select <select
@@ -155,6 +168,20 @@ export const WeatherSettings = (): JSX.Element => {
</select> </select>
</InputGroup> </InputGroup>
{/* WEATHER DATA */}
<InputGroup>
<label htmlFor="weatherData">Additional weather data</label>
<select
id="weatherData"
name="weatherData"
value={formData.weatherData}
onChange={(e) => inputChangeHandler(e)}
>
<option value="cloud">Cloud coverage</option>
<option value="humidity">Humidity</option>
</select>
</InputGroup>
<Button>Save changes</Button> <Button>Save changes</Button>
</form> </form>
); );

View File

@@ -6,13 +6,8 @@
"authRequired": false "authRequired": false
}, },
{ {
"name": "Weather", "name": "General",
"dest": "/settings/weather", "dest": "/settings/general",
"authRequired": true
},
{
"name": "Search",
"dest": "/settings/search",
"authRequired": true "authRequired": true
}, },
{ {
@@ -20,6 +15,11 @@
"dest": "/settings/interface", "dest": "/settings/interface",
"authRequired": true "authRequired": true
}, },
{
"name": "Weather",
"dest": "/settings/weather",
"authRequired": true
},
{ {
"name": "Docker", "name": "Docker",
"dest": "/settings/docker", "dest": "/settings/docker",

View File

@@ -1,29 +0,0 @@
import { Fragment } from 'react';
import { useDispatch } from 'react-redux';
import { bindActionCreators } from 'redux';
import { actionCreators } from '../../store';
import classes from './Themer.module.css';
import { themes } from './themes.json';
import { Theme } from '../../interfaces/Theme';
import { ThemePreview } from './ThemePreview';
export const Themer = (): JSX.Element => {
const dispatch = useDispatch();
const { setTheme } = bindActionCreators(actionCreators, dispatch);
return (
<Fragment>
<div>
<div className={classes.ThemerGrid}>
{themes.map(
(theme: Theme, idx: number): JSX.Element => (
<ThemePreview key={idx} theme={theme} applyTheme={setTheme} />
)
)}
</div>
</div>
</Fragment>
);
};

View File

@@ -23,7 +23,7 @@
.InputGroup span { .InputGroup span {
font-size: 12px; font-size: 12px;
color: var(--color-primary) color: var(--color-primary);
} }
.InputGroup span a { .InputGroup span a {
@@ -37,4 +37,4 @@
.InputGroup textarea { .InputGroup textarea {
resize: none; resize: none;
height: 50vh; height: 50vh;
} }

View File

@@ -1,17 +1,13 @@
.TableActions { .message {
display: flex; color: var(--color-primary);
align-items: center;
} }
.TableAction { .message a {
width: 22px; color: var(--color-accent);
font-weight: 600;
} }
.TableAction:hover { .messageCenter {
cursor: pointer;
}
.Message {
width: 100%; width: 100%;
display: flex; display: flex;
justify-content: center; justify-content: center;
@@ -20,10 +16,11 @@
margin-bottom: 20px; margin-bottom: 20px;
} }
.Message a { .messageCenter a,
.messageCenter span {
color: var(--color-accent); color: var(--color-accent);
} }
.Message a:hover { .messageCenter a:hover {
cursor: pointer; cursor: pointer;
} }

View 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>;
};

View File

@@ -12,3 +12,4 @@ export * from './Forms/InputGroup/InputGroup';
export * from './Forms/ModalForm/ModalForm'; export * from './Forms/ModalForm/ModalForm';
export * from './Buttons/ActionButton/ActionButton'; export * from './Buttons/ActionButton/ActionButton';
export * from './Buttons/Button/Button'; export * from './Buttons/Button/Button';
export * from './Text/Message/Message';

View File

@@ -13,22 +13,14 @@ import classes from './WeatherWidget.module.css';
// UI // UI
import { WeatherIcon } from '../../UI'; import { WeatherIcon } from '../../UI';
import { State } from '../../../store/reducers'; import { State } from '../../../store/reducers';
import { weatherTemplate } from '../../../utility/templateObjects/weatherTemplate';
export const WeatherWidget = (): JSX.Element => { export const WeatherWidget = (): JSX.Element => {
const { loading, config } = useSelector((state: State) => state.config); const { loading: configLoading, config } = useSelector(
(state: State) => state.config
);
const [weather, setWeather] = useState<Weather>({ const [weather, setWeather] = useState<Weather>(weatherTemplate);
externalLastUpdate: '',
tempC: 0,
tempF: 0,
isDay: 1,
cloud: 0,
conditionText: '',
conditionCode: 1000,
id: -1,
createdAt: new Date(),
updatedAt: new Date(),
});
const [isLoading, setIsLoading] = useState(true); const [isLoading, setIsLoading] = useState(true);
// Initial request to get data // Initial request to get data
@@ -65,8 +57,7 @@ export const WeatherWidget = (): JSX.Element => {
return ( return (
<div className={classes.WeatherWidget}> <div className={classes.WeatherWidget}>
{isLoading || {configLoading ||
loading ||
(config.WEATHER_API_KEY && weather.id > 0 && ( (config.WEATHER_API_KEY && weather.id > 0 && (
<Fragment> <Fragment>
<div className={classes.WeatherIcon}> <div className={classes.WeatherIcon}>
@@ -76,12 +67,15 @@ export const WeatherWidget = (): JSX.Element => {
/> />
</div> </div>
<div className={classes.WeatherDetails}> <div className={classes.WeatherDetails}>
{/* TEMPERATURE */}
{config.isCelsius ? ( {config.isCelsius ? (
<span>{weather.tempC}°C</span> <span>{weather.tempC}°C</span>
) : ( ) : (
<span>{weather.tempF}°F</span> <span>{Math.round(weather.tempF)}°F</span>
)} )}
<span>{weather.cloud}%</span>
{/* ADDITIONAL DATA */}
<span>{weather[config.weatherData]}%</span>
</div> </div>
</Fragment> </Fragment>
))} ))}

View File

@@ -5,6 +5,7 @@ export interface NewApp {
url: string; url: string;
icon: string; icon: string;
isPublic: boolean; isPublic: boolean;
description: string;
} }
export interface App extends Model, NewApp { export interface App extends Model, NewApp {

View File

@@ -8,4 +8,6 @@ export interface NewBookmark {
isPublic: boolean; isPublic: boolean;
} }
export interface Bookmark extends Model, NewBookmark {} export interface Bookmark extends Model, NewBookmark {
orderId: number;
}

View File

@@ -1,3 +1,5 @@
import { WeatherData } from '../types';
export interface Config { export interface Config {
WEATHER_API_KEY: string; WEATHER_API_KEY: string;
lat: number; lat: number;
@@ -25,4 +27,8 @@ export interface Config {
daySchema: string; daySchema: string;
monthSchema: string; monthSchema: string;
showTime: boolean; showTime: boolean;
defaultTheme: string;
isKilometer: boolean;
weatherData: WeatherData;
hideDate: boolean;
} }

View File

@@ -1,32 +1,36 @@
import { WeatherData } from '../types';
export interface WeatherForm { export interface WeatherForm {
WEATHER_API_KEY: string; WEATHER_API_KEY: string;
lat: number; lat: number;
long: number; long: number;
isCelsius: boolean; isCelsius: boolean;
weatherData: WeatherData;
} }
export interface SearchForm { export interface GeneralForm {
hideSearch: boolean;
defaultSearchProvider: string; defaultSearchProvider: string;
searchSameTab: boolean; searchSameTab: boolean;
disableAutofocus: boolean;
}
export interface OtherSettingsForm {
customTitle: string;
pinAppsByDefault: boolean; pinAppsByDefault: boolean;
pinCategoriesByDefault: boolean; pinCategoriesByDefault: boolean;
hideHeader: boolean;
hideApps: boolean;
hideCategories: boolean;
useOrdering: string; useOrdering: string;
appsSameTab: boolean; appsSameTab: boolean;
bookmarksSameTab: boolean; bookmarksSameTab: boolean;
}
export interface UISettingsForm {
customTitle: string;
hideHeader: boolean;
hideApps: boolean;
hideCategories: boolean;
useAmericanDate: boolean; useAmericanDate: boolean;
greetingsSchema: string; greetingsSchema: string;
daySchema: string; daySchema: string;
monthSchema: string; monthSchema: string;
showTime: boolean; showTime: boolean;
hideDate: boolean;
hideSearch: boolean;
disableAutofocus: boolean;
} }
export interface DockerSettingsForm { export interface DockerSettingsForm {
@@ -35,3 +39,7 @@ export interface DockerSettingsForm {
kubernetesApps: boolean; kubernetesApps: boolean;
unpinStoppedApps: boolean; unpinStoppedApps: boolean;
} }
export interface ThemeSettingsForm {
defaultTheme: string;
}

View File

@@ -8,4 +8,7 @@ export interface Weather extends Model {
cloud: number; cloud: number;
conditionText: string; conditionText: string;
conditionCode: number; conditionCode: number;
} humidity: number;
windK: number;
windM: number;
}

View File

@@ -7,6 +7,7 @@ import {
GetAppsAction, GetAppsAction,
PinAppAction, PinAppAction,
ReorderAppsAction, ReorderAppsAction,
SetEditAppAction,
SortAppsAction, SortAppsAction,
UpdateAppAction, UpdateAppAction,
} from '../actions/app'; } from '../actions/app';
@@ -196,3 +197,11 @@ export const sortApps = () => async (dispatch: Dispatch<SortAppsAction>) => {
console.log(err); console.log(err);
} }
}; };
export const setEditApp =
(app: App | null) => (dispatch: Dispatch<SetEditAppAction>) => {
dispatch({
type: ActionType.setEditApp,
payload: app,
});
};

View File

@@ -1,5 +1,8 @@
import axios from 'axios'; import axios from 'axios';
import { Dispatch } from 'redux'; import { Dispatch } from 'redux';
import { applyAuth } from '../../utility';
import { ActionType } from '../action-types';
import { import {
ApiResponse, ApiResponse,
Bookmark, Bookmark,
@@ -8,8 +11,7 @@ import {
NewBookmark, NewBookmark,
NewCategory, NewCategory,
} from '../../interfaces'; } from '../../interfaces';
import { applyAuth } from '../../utility';
import { ActionType } from '../action-types';
import { import {
AddBookmarkAction, AddBookmarkAction,
AddCategoryAction, AddCategoryAction,
@@ -17,7 +19,11 @@ import {
DeleteCategoryAction, DeleteCategoryAction,
GetCategoriesAction, GetCategoriesAction,
PinCategoryAction, PinCategoryAction,
ReorderBookmarksAction,
ReorderCategoriesAction, ReorderCategoriesAction,
SetEditBookmarkAction,
SetEditCategoryAction,
SortBookmarksAction,
SortCategoriesAction, SortCategoriesAction,
UpdateBookmarkAction, UpdateBookmarkAction,
UpdateCategoryAction, UpdateCategoryAction,
@@ -95,6 +101,8 @@ export const addBookmark =
type: ActionType.addBookmark, type: ActionType.addBookmark,
payload: res.data.data, payload: res.data.data,
}); });
dispatch<any>(sortBookmarks(res.data.data.categoryId));
} catch (err) { } catch (err) {
console.log(err); console.log(err);
} }
@@ -266,6 +274,8 @@ export const updateBookmark =
payload: res.data.data, payload: res.data.data,
}); });
} }
dispatch<any>(sortBookmarks(res.data.data.categoryId));
} catch (err) { } catch (err) {
console.log(err); console.log(err);
} }
@@ -319,3 +329,73 @@ export const reorderCategories =
console.log(err); 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);
}
};

View File

@@ -8,17 +8,10 @@ import {
UpdateQueryAction, UpdateQueryAction,
} from '../actions/config'; } from '../actions/config';
import axios from 'axios'; import axios from 'axios';
import { import { ApiResponse, Config, Query } from '../../interfaces';
ApiResponse,
Config,
DockerSettingsForm,
OtherSettingsForm,
Query,
SearchForm,
WeatherForm,
} from '../../interfaces';
import { ActionType } from '../action-types'; import { ActionType } from '../action-types';
import { storeUIConfig, applyAuth } from '../../utility'; import { storeUIConfig, applyAuth } from '../../utility';
import { ConfigFormData } from '../../types';
const keys: (keyof Config)[] = [ const keys: (keyof Config)[] = [
'useAmericanDate', 'useAmericanDate',
@@ -26,6 +19,7 @@ const keys: (keyof Config)[] = [
'daySchema', 'daySchema',
'monthSchema', 'monthSchema',
'showTime', 'showTime',
'hideDate',
]; ];
export const getConfig = () => async (dispatch: Dispatch<GetConfigAction>) => { export const getConfig = () => async (dispatch: Dispatch<GetConfigAction>) => {
@@ -50,9 +44,7 @@ export const getConfig = () => async (dispatch: Dispatch<GetConfigAction>) => {
}; };
export const updateConfig = export const updateConfig =
( (formData: ConfigFormData) =>
formData: WeatherForm | OtherSettingsForm | SearchForm | DockerSettingsForm
) =>
async (dispatch: Dispatch<UpdateConfigAction>) => { async (dispatch: Dispatch<UpdateConfigAction>) => {
try { try {
const res = await axios.put<ApiResponse<Config>>( const res = await axios.put<ApiResponse<Config>>(

View File

@@ -2,14 +2,18 @@ import { Dispatch } from 'redux';
import { SetThemeAction } from '../actions/theme'; import { SetThemeAction } from '../actions/theme';
import { ActionType } from '../action-types'; import { ActionType } from '../action-types';
import { Theme } from '../../interfaces/Theme'; import { Theme } from '../../interfaces/Theme';
import { themes } from '../../components/Themer/themes.json'; import { themes } from '../../components/Settings/Themer/themes.json';
export const setTheme = export const setTheme =
(name: string) => (dispatch: Dispatch<SetThemeAction>) => { (name: string, remeberTheme: boolean = true) =>
(dispatch: Dispatch<SetThemeAction>) => {
const theme = themes.find((theme) => theme.name === name); const theme = themes.find((theme) => theme.name === name);
if (theme) { if (theme) {
localStorage.setItem('theme', name); if (remeberTheme) {
localStorage.setItem('theme', name);
}
loadTheme(theme); loadTheme(theme);
dispatch({ dispatch({

View File

@@ -23,6 +23,7 @@ export enum ActionType {
updateApp = 'UPDATE_APP', updateApp = 'UPDATE_APP',
reorderApps = 'REORDER_APPS', reorderApps = 'REORDER_APPS',
sortApps = 'SORT_APPS', sortApps = 'SORT_APPS',
setEditApp = 'SET_EDIT_APP',
// CATEGORES // CATEGORES
getCategories = 'GET_CATEGORIES', getCategories = 'GET_CATEGORIES',
getCategoriesSuccess = 'GET_CATEGORIES_SUCCESS', getCategoriesSuccess = 'GET_CATEGORIES_SUCCESS',
@@ -33,10 +34,14 @@ export enum ActionType {
updateCategory = 'UPDATE_CATEGORY', updateCategory = 'UPDATE_CATEGORY',
sortCategories = 'SORT_CATEGORIES', sortCategories = 'SORT_CATEGORIES',
reorderCategories = 'REORDER_CATEGORIES', reorderCategories = 'REORDER_CATEGORIES',
setEditCategory = 'SET_EDIT_CATEGORY',
// BOOKMARKS // BOOKMARKS
addBookmark = 'ADD_BOOKMARK', addBookmark = 'ADD_BOOKMARK',
deleteBookmark = 'DELETE_BOOKMARK', deleteBookmark = 'DELETE_BOOKMARK',
updateBookmark = 'UPDATE_BOOKMARK', updateBookmark = 'UPDATE_BOOKMARK',
setEditBookmark = 'SET_EDIT_BOOKMARK',
reorderBookmarks = 'REORDER_BOOKMARKS',
sortBookmarks = 'SORT_BOOKMARKS',
// AUTH // AUTH
login = 'LOGIN', login = 'LOGIN',
logout = 'LOGOUT', logout = 'LOGOUT',

View File

@@ -36,3 +36,8 @@ export interface SortAppsAction {
type: ActionType.sortApps; type: ActionType.sortApps;
payload: string; payload: string;
} }
export interface SetEditAppAction {
type: ActionType.setEditApp;
payload: App | null;
}

View File

@@ -56,3 +56,29 @@ export interface ReorderCategoriesAction {
type: ActionType.reorderCategories; type: ActionType.reorderCategories;
payload: Category[]; 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;
};
}

View File

@@ -24,6 +24,7 @@ import {
UpdateAppAction, UpdateAppAction,
ReorderAppsAction, ReorderAppsAction,
SortAppsAction, SortAppsAction,
SetEditAppAction,
} from './app'; } from './app';
import { import {
@@ -37,6 +38,10 @@ import {
AddBookmarkAction, AddBookmarkAction,
DeleteBookmarkAction, DeleteBookmarkAction,
UpdateBookmarkAction, UpdateBookmarkAction,
SetEditCategoryAction,
SetEditBookmarkAction,
ReorderBookmarksAction,
SortBookmarksAction,
} from './bookmark'; } from './bookmark';
import { import {
@@ -67,6 +72,7 @@ export type Action =
| UpdateAppAction | UpdateAppAction
| ReorderAppsAction | ReorderAppsAction
| SortAppsAction | SortAppsAction
| SetEditAppAction
// Categories // Categories
| GetCategoriesAction<any> | GetCategoriesAction<any>
| AddCategoryAction | AddCategoryAction
@@ -75,10 +81,14 @@ export type Action =
| UpdateCategoryAction | UpdateCategoryAction
| SortCategoriesAction | SortCategoriesAction
| ReorderCategoriesAction | ReorderCategoriesAction
| SetEditCategoryAction
// Bookmarks // Bookmarks
| AddBookmarkAction | AddBookmarkAction
| DeleteBookmarkAction | DeleteBookmarkAction
| UpdateBookmarkAction | UpdateBookmarkAction
| SetEditBookmarkAction
| ReorderBookmarksAction
| SortBookmarksAction
// Auth // Auth
| LoginAction | LoginAction
| LogoutAction | LogoutAction

View File

@@ -7,12 +7,14 @@ interface AppsState {
loading: boolean; loading: boolean;
apps: App[]; apps: App[];
errors: string | undefined; errors: string | undefined;
appInUpdate: App | null;
} }
const initialState: AppsState = { const initialState: AppsState = {
loading: true, loading: true,
apps: [], apps: [],
errors: undefined, errors: undefined,
appInUpdate: null,
}; };
export const appsReducer = ( export const appsReducer = (
@@ -20,71 +22,86 @@ export const appsReducer = (
action: Action action: Action
): AppsState => { ): AppsState => {
switch (action.type) { switch (action.type) {
case ActionType.getApps: case ActionType.getApps: {
return { return {
...state, ...state,
loading: true, loading: true,
errors: undefined, errors: undefined,
}; };
}
case ActionType.getAppsSuccess: case ActionType.getAppsSuccess: {
return { return {
...state, ...state,
loading: false, loading: false,
apps: action.payload || [], apps: action.payload || [],
}; };
}
case ActionType.pinApp: case ActionType.pinApp: {
const pinnedAppIdx = state.apps.findIndex( const appIdx = state.apps.findIndex(
(app) => app.id === action.payload.id (app) => app.id === action.payload.id
); );
return { return {
...state, ...state,
apps: [ apps: [
...state.apps.slice(0, pinnedAppIdx), ...state.apps.slice(0, appIdx),
action.payload, action.payload,
...state.apps.slice(pinnedAppIdx + 1), ...state.apps.slice(appIdx + 1),
], ],
}; };
}
case ActionType.addAppSuccess: case ActionType.addAppSuccess: {
return { return {
...state, ...state,
apps: [...state.apps, action.payload], apps: [...state.apps, action.payload],
}; };
}
case ActionType.deleteApp: case ActionType.deleteApp: {
return { return {
...state, ...state,
apps: [...state.apps].filter((app) => app.id !== action.payload), apps: [...state.apps].filter((app) => app.id !== action.payload),
}; };
}
case ActionType.updateApp: case ActionType.updateApp: {
const updatedAppIdx = state.apps.findIndex( const appIdx = state.apps.findIndex(
(app) => app.id === action.payload.id (app) => app.id === action.payload.id
); );
return { return {
...state, ...state,
apps: [ apps: [
...state.apps.slice(0, updatedAppIdx), ...state.apps.slice(0, appIdx),
action.payload, action.payload,
...state.apps.slice(updatedAppIdx + 1), ...state.apps.slice(appIdx + 1),
], ],
}; };
}
case ActionType.reorderApps: case ActionType.reorderApps: {
return { return {
...state, ...state,
apps: action.payload, apps: action.payload,
}; };
}
case ActionType.sortApps: case ActionType.sortApps: {
return { return {
...state, ...state,
apps: sortData<App>(state.apps, action.payload), apps: sortData<App>(state.apps, action.payload),
}; };
}
case ActionType.setEditApp: {
return {
...state,
appInUpdate: action.payload,
};
}
default: default:
return state; return state;

View File

@@ -22,24 +22,28 @@ export const authReducer = (
token: action.payload, token: action.payload,
isAuthenticated: true, isAuthenticated: true,
}; };
case ActionType.logout: case ActionType.logout:
return { return {
...state, ...state,
token: null, token: null,
isAuthenticated: false, isAuthenticated: false,
}; };
case ActionType.autoLogin: case ActionType.autoLogin:
return { return {
...state, ...state,
token: action.payload, token: action.payload,
isAuthenticated: true, isAuthenticated: true,
}; };
case ActionType.authError: case ActionType.authError:
return { return {
...state, ...state,
token: null, token: null,
isAuthenticated: false, isAuthenticated: false,
}; };
default: default:
return state; return state;
} }

View File

@@ -1,4 +1,4 @@
import { Category } from '../../interfaces'; import { Bookmark, Category } from '../../interfaces';
import { sortData } from '../../utility'; import { sortData } from '../../utility';
import { ActionType } from '../action-types'; import { ActionType } from '../action-types';
import { Action } from '../actions'; import { Action } from '../actions';
@@ -7,12 +7,16 @@ interface BookmarksState {
loading: boolean; loading: boolean;
errors: string | undefined; errors: string | undefined;
categories: Category[]; categories: Category[];
categoryInEdit: Category | null;
bookmarkInEdit: Bookmark | null;
} }
const initialState: BookmarksState = { const initialState: BookmarksState = {
loading: true, loading: true,
errors: undefined, errors: undefined,
categories: [], categories: [],
categoryInEdit: null,
bookmarkInEdit: null,
}; };
export const bookmarksReducer = ( export const bookmarksReducer = (
@@ -20,27 +24,181 @@ export const bookmarksReducer = (
action: Action action: Action
): BookmarksState => { ): BookmarksState => {
switch (action.type) { switch (action.type) {
case ActionType.getCategories: case ActionType.getCategories: {
return { return {
...state, ...state,
loading: true, loading: true,
errors: undefined, errors: undefined,
}; };
}
case ActionType.getCategoriesSuccess: case ActionType.getCategoriesSuccess: {
return { return {
...state, ...state,
loading: false, loading: false,
categories: action.payload, categories: action.payload,
}; };
}
case ActionType.addCategory: case ActionType.addCategory: {
return { return {
...state, ...state,
categories: [...state.categories, { ...action.payload, bookmarks: [] }], 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( const categoryIdx = state.categories.findIndex(
(category) => category.id === action.payload.categoryId (category) => category.id === action.payload.categoryId
); );
@@ -51,121 +209,36 @@ export const bookmarksReducer = (
...state.categories.slice(0, categoryIdx), ...state.categories.slice(0, categoryIdx),
{ {
...state.categories[categoryIdx], ...state.categories[categoryIdx],
bookmarks: [ bookmarks: action.payload.bookmarks,
...state.categories[categoryIdx].bookmarks,
action.payload,
],
}, },
...state.categories.slice(categoryIdx + 1), ...state.categories.slice(categoryIdx + 1),
], ],
}; };
}
case ActionType.pinCategory: case ActionType.sortBookmarks: {
const pinnedCategoryIdx = state.categories.findIndex( const categoryIdx = 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(
(category) => category.id === action.payload.categoryId (category) => category.id === action.payload.categoryId
); );
return { const sortedBookmarks = sortData<Bookmark>(
...state, state.categories[categoryIdx].bookmarks,
categories: [ action.payload.orderType
...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 updatedBookmarkIdx = state.categories[
parentCategoryIdx
].bookmarks.findIndex((bookmark) => bookmark.id === action.payload.id);
return { return {
...state, ...state,
categories: [ categories: [
...state.categories.slice(0, parentCategoryIdx), ...state.categories.slice(0, categoryIdx),
{ {
...state.categories[parentCategoryIdx], ...state.categories[categoryIdx],
bookmarks: [ bookmarks: sortedBookmarks,
...state.categories[parentCategoryIdx].bookmarks.slice(
0,
updatedBookmarkIdx
),
action.payload,
...state.categories[parentCategoryIdx].bookmarks.slice(
updatedBookmarkIdx + 1
),
],
}, },
...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: default:
return state; return state;
} }

View File

@@ -26,26 +26,31 @@ export const configReducer = (
loading: false, loading: false,
config: action.payload, config: action.payload,
}; };
case ActionType.updateConfig: case ActionType.updateConfig:
return { return {
...state, ...state,
config: action.payload, config: action.payload,
}; };
case ActionType.fetchQueries: case ActionType.fetchQueries:
return { return {
...state, ...state,
customQueries: action.payload, customQueries: action.payload,
}; };
case ActionType.addQuery: case ActionType.addQuery:
return { return {
...state, ...state,
customQueries: [...state.customQueries, action.payload], customQueries: [...state.customQueries, action.payload],
}; };
case ActionType.deleteQuery: case ActionType.deleteQuery:
return { return {
...state, ...state,
customQueries: action.payload, customQueries: action.payload,
}; };
case ActionType.updateQuery: case ActionType.updateQuery:
return { return {
...state, ...state,

View File

@@ -29,6 +29,7 @@ export const notificationReducer = (
], ],
idCounter: state.idCounter + 1, idCounter: state.idCounter + 1,
}; };
case ActionType.clearNotification: case ActionType.clearNotification:
return { return {
...state, ...state,

View File

@@ -24,6 +24,7 @@ export const themeReducer = (
switch (action.type) { switch (action.type) {
case ActionType.setTheme: case ActionType.setTheme:
return { theme: action.payload }; return { theme: action.payload };
default: default:
return state; return state;
} }

View File

@@ -0,0 +1,14 @@
import {
DockerSettingsForm,
UISettingsForm,
GeneralForm,
ThemeSettingsForm,
WeatherForm,
} from '../interfaces';
export type ConfigFormData =
| WeatherForm
| GeneralForm
| DockerSettingsForm
| UISettingsForm
| ThemeSettingsForm;

View File

@@ -0,0 +1 @@
export type WeatherData = 'cloud' | 'humidity';

View File

@@ -0,0 +1,2 @@
export * from './ConfigFormData';
export * from './WeatherData';

View File

@@ -1,4 +1,4 @@
export const applyAuth = () => { export const applyAuth = () => {
const token = localStorage.getItem('token') || ''; const token = localStorage.getItem('token') || '';
return { Authorization: `Bearer ${token}` }; return { 'Authorization-Flame': `Bearer ${token}` };
}; };

View File

@@ -5,6 +5,7 @@ export const newAppTemplate: NewApp = {
url: '', url: '',
icon: '', icon: '',
isPublic: true, isPublic: true,
description: '',
}; };
export const appTemplate: App = { export const appTemplate: App = {

View File

@@ -13,4 +13,5 @@ export const bookmarkTemplate: Bookmark = {
id: -1, id: -1,
createdAt: new Date(), createdAt: new Date(),
updatedAt: new Date(), updatedAt: new Date(),
orderId: 0,
}; };

View File

@@ -28,4 +28,8 @@ export const configTemplate: Config = {
monthSchema: monthSchema:
'January;February;March;April;May;June;July;August;September;October;November;December', 'January;February;March;April;May;June;July;August;September;October;November;December',
showTime: false, showTime: false,
defaultTheme: 'tron',
isKilometer: true,
weatherData: 'cloud',
hideDate: false,
}; };

View File

@@ -1,26 +1,25 @@
import { import {
DockerSettingsForm, DockerSettingsForm,
OtherSettingsForm, UISettingsForm,
SearchForm, GeneralForm,
ThemeSettingsForm,
WeatherForm, WeatherForm,
} from '../../interfaces'; } from '../../interfaces';
export const otherSettingsTemplate: OtherSettingsForm = { export const uiSettingsTemplate: UISettingsForm = {
customTitle: document.title, customTitle: document.title,
pinAppsByDefault: true,
pinCategoriesByDefault: true,
hideHeader: false, hideHeader: false,
hideApps: false, hideApps: false,
hideCategories: false, hideCategories: false,
useOrdering: 'createdAt',
appsSameTab: false,
bookmarksSameTab: false,
useAmericanDate: false, useAmericanDate: false,
greetingsSchema: 'Good evening!;Good afternoon!;Good morning!;Good night!', greetingsSchema: 'Good evening!;Good afternoon!;Good morning!;Good night!',
daySchema: 'Sunday;Monday;Tuesday;Wednesday;Thursday;Friday;Saturday', daySchema: 'Sunday;Monday;Tuesday;Wednesday;Thursday;Friday;Saturday',
monthSchema: monthSchema:
'January;February;March;April;May;June;July;August;September;October;November;December', 'January;February;March;April;May;June;July;August;September;October;November;December',
showTime: false, showTime: false,
hideDate: false,
hideSearch: false,
disableAutofocus: false,
}; };
export const weatherSettingsTemplate: WeatherForm = { export const weatherSettingsTemplate: WeatherForm = {
@@ -28,13 +27,17 @@ export const weatherSettingsTemplate: WeatherForm = {
lat: 0, lat: 0,
long: 0, long: 0,
isCelsius: true, isCelsius: true,
weatherData: 'cloud',
}; };
export const searchSettingsTemplate: SearchForm = { export const generalSettingsTemplate: GeneralForm = {
hideSearch: false,
searchSameTab: false, searchSameTab: false,
defaultSearchProvider: 'l', defaultSearchProvider: 'l',
disableAutofocus: false, pinAppsByDefault: true,
pinCategoriesByDefault: true,
useOrdering: 'createdAt',
appsSameTab: false,
bookmarksSameTab: false,
}; };
export const dockerSettingsTemplate: DockerSettingsForm = { export const dockerSettingsTemplate: DockerSettingsForm = {
@@ -43,3 +46,7 @@ export const dockerSettingsTemplate: DockerSettingsForm = {
kubernetesApps: true, kubernetesApps: true,
unpinStoppedApps: true, unpinStoppedApps: true,
}; };
export const themeSettingsTemplate: ThemeSettingsForm = {
defaultTheme: 'tron',
};

View File

@@ -0,0 +1,17 @@
import { Weather } from '../../interfaces';
export const weatherTemplate: Weather = {
externalLastUpdate: '',
tempC: 0,
tempF: 0,
isDay: 1,
cloud: 0,
conditionText: '',
conditionCode: 1000,
id: -1,
createdAt: new Date(),
updatedAt: new Date(),
humidity: 0,
windK: 0,
windM: 0,
};

View File

@@ -13,7 +13,7 @@ export const isUrl = (data: string): boolean => {
}; };
export const isImage = (data: string): boolean => { export const isImage = (data: string): boolean => {
const regex = /.(jpeg|jpg|png)$/i; const regex = /.(jpeg|jpg|png|ico)$/i;
return regex.test(data); return regex.test(data);
}; };

View File

@@ -8,21 +8,20 @@ const loadConfig = require('../../utils/loadConfig');
const createApp = asyncWrapper(async (req, res, next) => { const createApp = asyncWrapper(async (req, res, next) => {
const { pinAppsByDefault } = await loadConfig(); const { pinAppsByDefault } = await loadConfig();
let app; let body = { ...req.body };
let _body = { ...req.body, icon: req.body.icon.trim() };
if (body.icon) {
body.icon = body.icon.trim();
}
if (req.file) { if (req.file) {
_body.icon = req.file.filename; body.icon = req.file.filename;
} }
if (pinAppsByDefault) { const app = await App.create({
app = await App.create({ ...body,
..._body, isPinned: pinAppsByDefault,
isPinned: true, });
});
} else {
app = await App.create(req.body);
}
res.status(201).json({ res.status(201).json({
success: true, success: true,

View File

@@ -28,17 +28,15 @@ const getAllApps = asyncWrapper(async (req, res, next) => {
// apps visibility // apps visibility
const where = req.isAuthenticated ? {} : { isPublic: true }; const where = req.isAuthenticated ? {} : { isPublic: true };
if (orderType == 'name') { const order =
apps = await App.findAll({ orderType == 'name'
order: [[Sequelize.fn('lower', Sequelize.col('name')), 'ASC']], ? [[Sequelize.fn('lower', Sequelize.col('name')), 'ASC']]
where, : [[orderType, 'ASC']];
});
} else { apps = await App.findAll({
apps = await App.findAll({ order,
order: [[orderType, 'ASC']], where,
where, });
});
}
if (process.env.NODE_ENV === 'production') { if (process.env.NODE_ENV === 'production') {
// Set header to fetch containers info every time // Set header to fetch containers info every time

View File

@@ -18,17 +18,17 @@ const updateApp = asyncWrapper(async (req, res, next) => {
); );
} }
let _body = { ...req.body }; let body = { ...req.body };
if (_body.icon) { if (body.icon) {
_body.icon = _body.icon.trim(); body.icon = body.icon.trim();
} }
if (req.file) { if (req.file) {
_body.icon = req.file.filename; body.icon = req.file.filename;
} }
app = await app.update(_body); app = await app.update(body);
res.status(200).json({ res.status(200).json({
success: true, success: true,

View File

@@ -7,20 +7,20 @@ const Bookmark = require('../../models/Bookmark');
const createBookmark = asyncWrapper(async (req, res, next) => { const createBookmark = asyncWrapper(async (req, res, next) => {
let bookmark; let bookmark;
let _body = { let body = {
...req.body, ...req.body,
categoryId: parseInt(req.body.categoryId), categoryId: parseInt(req.body.categoryId),
}; };
if (_body.icon) { if (body.icon) {
_body.icon = _body.icon.trim(); body.icon = body.icon.trim();
} }
if (req.file) { if (req.file) {
_body.icon = req.file.filename; body.icon = req.file.filename;
} }
bookmark = await Bookmark.create(_body); bookmark = await Bookmark.create(body);
res.status(201).json({ res.status(201).json({
success: true, success: true,

View File

@@ -1,16 +1,24 @@
const asyncWrapper = require('../../middleware/asyncWrapper'); const asyncWrapper = require('../../middleware/asyncWrapper');
const Bookmark = require('../../models/Bookmark'); const Bookmark = require('../../models/Bookmark');
const { Sequelize } = require('sequelize'); const { Sequelize } = require('sequelize');
const loadConfig = require('../../utils/loadConfig');
// @desc Get all bookmarks // @desc Get all bookmarks
// @route GET /api/bookmarks // @route GET /api/bookmarks
// @access Public // @access Public
const getAllBookmarks = asyncWrapper(async (req, res, next) => { const getAllBookmarks = asyncWrapper(async (req, res, next) => {
const { useOrdering: orderType } = await loadConfig();
// bookmarks visibility // bookmarks visibility
const where = req.isAuthenticated ? {} : { isPublic: true }; const where = req.isAuthenticated ? {} : { isPublic: true };
const order =
orderType == 'name'
? [[Sequelize.fn('lower', Sequelize.col('name')), 'ASC']]
: [[orderType, 'ASC']];
const bookmarks = await Bookmark.findAll({ const bookmarks = await Bookmark.findAll({
order: [[Sequelize.fn('lower', Sequelize.col('name')), 'ASC']], order,
where, where,
}); });

View File

@@ -4,4 +4,5 @@ module.exports = {
getSingleBookmark: require('./getSingleBookmark'), getSingleBookmark: require('./getSingleBookmark'),
updateBookmark: require('./updateBookmark'), updateBookmark: require('./updateBookmark'),
deleteBookmark: require('./deleteBookmark'), deleteBookmark: require('./deleteBookmark'),
reorderBookmarks: require('./reorderBookmarks'),
}; };

View File

@@ -0,0 +1,23 @@
const asyncWrapper = require('../../middleware/asyncWrapper');
const Bookmark = require('../../models/Bookmark');
// @desc Reorder bookmarks
// @route PUT /api/bookmarks/0/reorder
// @access Public
const reorderBookmarks = asyncWrapper(async (req, res, next) => {
req.body.bookmarks.forEach(async ({ id, orderId }) => {
await Bookmark.update(
{ orderId },
{
where: { id },
}
);
});
res.status(200).json({
success: true,
data: {},
});
});
module.exports = reorderBookmarks;

View File

@@ -19,20 +19,20 @@ const updateBookmark = asyncWrapper(async (req, res, next) => {
); );
} }
let _body = { let body = {
...req.body, ...req.body,
categoryId: parseInt(req.body.categoryId), categoryId: parseInt(req.body.categoryId),
}; };
if (_body.icon) { if (body.icon) {
_body.icon = _body.icon.trim(); body.icon = body.icon.trim();
} }
if (req.file) { if (req.file) {
_body.icon = req.file.filename; body.icon = req.file.filename;
} }
bookmark = await bookmark.update(_body); bookmark = await bookmark.update(body);
res.status(200).json({ res.status(200).json({
success: true, success: true,

Some files were not shown because too many files have changed in this diff Show More