Compare commits

...

69 commits

Author SHA1 Message Date
pawelmalak
3c347c854c
Merge pull request #432 from pawelmalak/v2.3.1
Version 2.3.1
2023-07-23 14:51:23 +02:00
Paweł Malak
89fa2980e6 Pushed version 2.3.1 2023-07-23 14:47:08 +02:00
Paweł Malak
7479ffb134 Updated MDI link. Opening link in the same tab will now allow to go back to the previous page 2023-07-23 10:59:37 +02:00
Paweł Malak
97884a5293 Fixed bug where color inputs in theme creator/editor were too small (fixing #429) 2023-07-23 10:45:26 +02:00
Paweł Malak
002a87a6df Changed input labels in settings (fixing #430) 2023-07-23 10:24:13 +02:00
Paweł Malak
17f0b7a553 Fixed bug where styles for SettingsHeadline weren\'t applied with current version of react-scripts 2023-07-23 00:40:57 +02:00
Paweł Malak
69ddc44796 Merge branch 'v2.3.1' of https://github.com/pawelmalak/flame into v2.3.1 2023-07-20 19:33:16 +02:00
pawelmalak
9e6d6fce73
Merge pull request #395 from davidchalifoux/codespace-2cc7
Enforce no border-radius on search bar
2023-07-20 19:33:01 +02:00
Paweł Malak
018ec0dd94 Fixed bug#270 where setting was not respected when local was set as primary search 2023-07-20 19:28:00 +02:00
pawelmalak
c2d580ee0d
Merge pull request #284 from pmjklemm/fix_sameTab
bugfix: sameTab does not work if prefix is localSearch
2023-07-20 19:24:49 +02:00
Paweł Malak
188c5bc04b Fixed react errors while importing named exports from JSON files 2023-07-20 19:04:31 +02:00
Paweł Malak
35ae5f9ee7 Bumped react-scripts to version 5 2023-07-20 18:58:19 +02:00
David Chalifoux
ebd98d29c1 Enforce no border-radius on search bar 2022-10-16 19:14:12 +00:00
pawelmalak
446b4095f6
Merge pull request #334 from pawelmalak/feature
Version 2.3.0
2022-03-25 15:16:19 +01:00
Paweł Malak
2b5b3494f2 Pushed version 2.3.0 2022-03-25 14:56:48 +01:00
Paweł Malak
6fb5737118 Small bug fixes and UI improvements 2022-03-25 14:51:56 +01:00
Paweł Malak
16121ff547 Added option to set secondary search provider 2022-03-25 14:28:40 +01:00
Paweł Malak
2c0491a5b0 Fixed visual bug with custom theme editor modal. Added Mint theme 2022-03-25 14:07:53 +01:00
Paweł Malak
0f6d79683e Fixed bug where pressing Enter with empty search bar would redirect to search results 2022-03-25 13:37:53 +01:00
Paweł Malak
0b3eb2e87f Fixed bug where user could create empty app or bookmark which was causing page to go blank 2022-03-25 13:16:57 +01:00
Paweł Malak
668edb03d3 Functionality to delete and edit custom themes 2022-03-25 12:13:19 +01:00
Paweł Malak
ad92de141b API routes to edit and delete custom themes. Added ThemeEditor table 2022-03-25 11:33:42 +01:00
Paweł Malak
bd96f6ca50 Added CompactTable and ActionIcons UI components 2022-03-25 11:04:16 +01:00
Paweł Malak
9ab6c65d85 Added custom theme creator 2022-03-24 16:07:14 +01:00
Paweł Malak
378dd8e36d Fixed color of weather icon when changing theme 2022-03-24 14:56:36 +01:00
Paweł Malak
b8af178cbf API routes to get and add themes 2022-03-24 14:48:10 +01:00
Paweł Malak
48e28b9abd Added user themes section to Theme settings 2022-03-23 16:13:34 +01:00
Paweł Malak
89bd921875 Changed how theme is set and stored on client 2022-03-23 14:49:35 +01:00
Paweł Malak
e427fbf54c Added theme string normalization to initial process. Added getThemes controller 2022-03-23 14:13:14 +01:00
Paweł Malak
ee0b435493 Separated theme components 2022-03-23 13:02:32 +01:00
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
pmjklemm
eaab31aacc fix sameTab for prefix==l 2022-01-04 21:11:13 +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
Abbie Wade
7a8808df4f added integration for docker secrets 2021-11-20 10:54:34 +11:00
106 changed files with 29937 additions and 11329 deletions

1
.dev/build_dev.sh Normal file
View file

@ -0,0 +1 @@
docker build -t flame:dev -f .docker/Dockerfile .

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 . \
&& 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 .

View file

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

View file

@ -1,10 +1,10 @@
FROM node:14-alpine3.11 as builder
FROM node:16-alpine3.11 as builder
WORKDIR /app
COPY package*.json ./
RUN apk --no-cache --virtual build-dependencies add python make g++ \
RUN apk --no-cache --virtual build-dependencies add python python3 make g++ \
&& npm install --production
COPY . .
@ -17,7 +17,7 @@ RUN mkdir -p ./public ./data \
&& mv ./client/build/* ./public \
&& rm -rf ./client
FROM node:14-alpine3.11
FROM node:16-alpine3.11
COPY --from=builder /app /app
@ -28,4 +28,4 @@ EXPOSE 5005
ENV NODE_ENV=production
ENV PASSWORD=flame_password
CMD ["node", "server.js"]
CMD ["sh", "-c", "chown -R node /app/data && node server.js"]

View file

@ -1,12 +1,22 @@
version: '3'
version: '3.6'
services:
flame:
image: pawelmalak/flame
container_name: flame
volumes:
- /path/to/data:/app/data
- /path/to/host/data:/app/data
# - /var/run/docker.sock:/var/run/docker.sock # optional but required for Docker integration
ports:
- 5005:5005
# secrets:
# - password # optional but required for (1)
environment:
- PASSWORD=flame_password
# - PASSWORD_FILE=/run/secrets/password # optional but required for (1)
restart: unless-stopped
# optional but required for Docker secrets (1)
# secrets:
# password:
# file: /path/to/secrets/password

View file

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

2
.env
View file

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

3
.gitignore vendored
View file

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

View file

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

View file

@ -1,3 +1,37 @@
### v2.3.1 (2023-07-23)
- Fixed bug where "Open search results in the same tab" setting was not respected if "Local search" was set as primary search provider ([#270](https://github.com/pawelmalak/flame/issues/270))
- Fixed bug where search bar had rounded input field on iOS ([#394](https://github.com/pawelmalak/flame/issues/394))
- Updated link to Material Design Icons reference page ([#414](https://github.com/pawelmalak/flame/issues/414))
- Fixed bug where color inputs in theme creator/editor were too small ([#429](https://github.com/pawelmalak/flame/issues/429))
- Changed input labels in settings for more consistent naming ([#430](https://github.com/pawelmalak/flame/issues/430))
### v2.3.0 (2022-03-25)
- Added custom theme editor ([#246](https://github.com/pawelmalak/flame/issues/246))
- Added option to set secondary search provider ([#295](https://github.com/pawelmalak/flame/issues/295))
- Fixed bug where pressing Enter with empty search bar would redirect to search results ([#325](https://github.com/pawelmalak/flame/issues/325))
- Fixed bug where user could create empty app or bookmark which was causing page to go blank ([#332](https://github.com/pawelmalak/flame/issues/332))
- Added new theme: Mint
### v2.2.2 (2022-03-21)
- Added option to get user location directly from the app ([#287](https://github.com/pawelmalak/flame/issues/287))
- Fixed bug with local search not working when using prefix ([#289](https://github.com/pawelmalak/flame/issues/289))
- Fixed bug with app description not updating when using custom icon ([#310](https://github.com/pawelmalak/flame/issues/310))
- Changed permissions to some files and directories created by Flame
- Changed some of the settings tabs
### v2.2.1 (2022-01-08)
- Local search will now include app descriptions ([#266](https://github.com/pawelmalak/flame/issues/266))
- Fixed bug with unsupported characters in local search [#279](https://github.com/pawelmalak/flame/issues/279))
- Background tasks optimization ([#283](https://github.com/pawelmalak/flame/issues/283))
### v2.2.0 (2021-12-17)
- Added option to set custom description for apps ([#201](https://github.com/pawelmalak/flame/issues/201))
- Fixed fatal error while deploying Flame to cluster ([#242](https://github.com/pawelmalak/flame/issues/242))
### v2.1.1 (2021-12-02)
- Added support for Docker secrets ([#189](https://github.com/pawelmalak/flame/issues/189))
- Changed some messages and buttons to make it easier to open bookmarks editor ([#239](https://github.com/pawelmalak/flame/issues/239))
### v2.1.0 (2021-11-26)
- Added option to set custom order for bookmarks ([#43](https://github.com/pawelmalak/flame/issues/43)) and ([#187](https://github.com/pawelmalak/flame/issues/187))
- Added support for .ico files for custom icons ([#209](https://github.com/pawelmalak/flame/issues/209))

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
- 🔍 Integrated search bar with local filtering, 11 web search providers and ability to add your own
- 🔑 Authentication system to protect your settings, apps and bookmarks
- 🔨 Dozens of options to customize Flame interface to your needs, including support for custom CSS and 15 built-in color themes
- 🔨 Dozens of options to customize Flame interface to your needs, including support for custom CSS, 15 built-in color themes and custom theme builder
- ☀️ Weather widget with current temperature, cloud coverage and animated weather status
- 🐳 Docker integration to automatically pick and add apps based on their labels
@ -35,7 +35,7 @@ docker pull pawelmalak/flame:2.0.0
```sh
# run container
docker run -p 5005:5005 -v /path/to/data:/app/data -e PASSWORD=flame_password flame
docker run -p 5005:5005 -v /path/to/data:/app/data -e PASSWORD=flame_password pawelmalak/flame
```
#### Building images
@ -55,19 +55,42 @@ docker buildx build \
#### Docker-Compose
```yaml
version: '2.1'
version: '3.6'
services:
flame:
image: pawelmalak/flame:latest
image: pawelmalak/flame
container_name: flame
volumes:
- <host_dir>:/app/data
- /var/run/docker.sock:/var/run/docker.sock # optional but required for Docker integration feature
- /path/to/host/data:/app/data
- /var/run/docker.sock:/var/run/docker.sock # optional but required for Docker integration
ports:
- 5005:5005
secrets:
- password # optional but required for (1)
environment:
- PASSWORD=flame_password
- PASSWORD_FILE=/run/secrets/password # optional but required for (1)
restart: unless-stopped
# optional but required for Docker secrets (1)
secrets:
password:
file: /path/to/secrets/password
```
##### Docker Secrets
All environment variables can be overwritten by appending `_FILE` to the variable value. For example, you can use `PASSWORD_FILE` to pass through a docker secret instead of `PASSWORD`. If both `PASSWORD` and `PASSWORD_FILE` are set, the docker secret will take precedent.
```bash
# ./secrets/flame_password
my_custom_secret_password_123
# ./docker-compose.yml
secrets:
password:
file: ./secrets/flame_password
```
#### Skaffold
@ -212,7 +235,7 @@ metadata:
- Backup your `db.sqlite` before running script!
- Known Issues:
- generated icons are sometimes incorrect
```bash
pip3 install Pillow, beautifulsoup4

1
api.js
View file

@ -22,6 +22,7 @@ api.use('/api/categories', require('./routes/category'));
api.use('/api/bookmarks', require('./routes/bookmark'));
api.use('/api/queries', require('./routes/queries'));
api.use('/api/auth', require('./routes/auth'));
api.use('/api/themes', require('./routes/themes'));
// Custom error handler
api.use(errorHandler);

View file

@ -1 +1 @@
REACT_APP_VERSION=2.1.0
REACT_APP_VERSION=2.3.1

33592
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/node": "^16.11.6",
"@types/react": "^17.0.34",
"@types/react-autosuggest": "^10.1.5",
"@types/react-beautiful-dnd": "^13.1.2",
"@types/react-dom": "^17.0.11",
"@types/react-redux": "^7.1.20",
@ -21,12 +20,11 @@
"http-proxy-middleware": "^2.0.1",
"jwt-decode": "^3.1.2",
"react": "^17.0.2",
"react-autosuggest": "^10.1.0",
"react-beautiful-dnd": "^13.1.0",
"react-dom": "^17.0.2",
"react-redux": "^7.2.6",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.3",
"react-scripts": "^5.0.1",
"redux": "^4.1.2",
"redux-devtools-extension": "^2.13.9",
"redux-thunk": "^2.4.0",

View file

@ -10,7 +10,7 @@ import { actionCreators, store } from './store';
import { State } from './store/reducers';
// Utils
import { checkVersion, decodeToken } from './utility';
import { checkVersion, decodeToken, parsePABToTheme } from './utility';
// Routes
import { Home } from './components/Home/Home';
@ -31,7 +31,7 @@ export const App = (): JSX.Element => {
const { config, loading } = useSelector((state: State) => state.config);
const dispath = useDispatch();
const { fetchQueries, setTheme, logout, createNotification } =
const { fetchQueries, setTheme, logout, createNotification, fetchThemes } =
bindActionCreators(actionCreators, dispath);
useEffect(() => {
@ -51,9 +51,12 @@ export const App = (): JSX.Element => {
}
}, 1000);
// load themes
fetchThemes();
// set user theme if present
if (localStorage.theme) {
setTheme(localStorage.theme);
setTheme(parsePABToTheme(localStorage.theme));
}
// check for updated
@ -68,7 +71,7 @@ export const App = (): JSX.Element => {
// If there is no user theme, set the default one
useEffect(() => {
if (!loading && !localStorage.theme) {
setTheme(config.defaultTheme, false);
setTheme(parsePABToTheme(config.defaultTheme), false);
}
}, [loading]);

View file

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

View file

@ -18,10 +18,8 @@ export const AppForm = ({ modalHandler }: Props): JSX.Element => {
const { appInUpdate } = useSelector((state: State) => state.apps);
const dispatch = useDispatch();
const { addApp, updateApp, setEditApp } = bindActionCreators(
actionCreators,
dispatch
);
const { addApp, updateApp, setEditApp, createNotification } =
bindActionCreators(actionCreators, dispatch);
const [useCustomIcon, toggleUseCustomIcon] = useState<boolean>(false);
const [customIcon, setCustomIcon] = useState<File | null>(null);
@ -58,13 +56,26 @@ export const AppForm = ({ modalHandler }: Props): JSX.Element => {
const formSubmitHandler = (e: SyntheticEvent<HTMLFormElement>): void => {
e.preventDefault();
for (let field of ['name', 'url', 'icon'] as const) {
if (/^ +$/.test(formData[field])) {
createNotification({
title: 'Error',
message: `Field cannot be empty: ${field}`,
});
return;
}
}
const createFormData = (): FormData => {
const data = new FormData();
if (customIcon) {
data.append('icon', customIcon);
}
data.append('name', formData.name);
data.append('description', formData.description);
data.append('url', formData.url);
data.append('isPublic', `${formData.isPublic ? 1 : 0}`);
@ -96,7 +107,7 @@ export const AppForm = ({ modalHandler }: Props): JSX.Element => {
<ModalForm modalHandler={modalHandler} formHandler={formSubmitHandler}>
{/* NAME */}
<InputGroup>
<label htmlFor="name">App Name</label>
<label htmlFor="name">App name</label>
<input
type="text"
name="name"
@ -122,11 +133,27 @@ export const AppForm = ({ modalHandler }: Props): JSX.Element => {
/>
</InputGroup>
{/* DESCRIPTION */}
<InputGroup>
<label htmlFor="description">App description</label>
<input
type="text"
name="description"
id="description"
placeholder="My self-hosted app"
value={formData.description}
onChange={(e) => inputChangeHandler(e)}
/>
<span>
Optional - If description is not set, app URL will be displayed
</span>
</InputGroup>
{/* ICON */}
{!useCustomIcon ? (
// use mdi icon
<InputGroup>
<label htmlFor="icon">App Icon</label>
<label htmlFor="icon">App icon</label>
<input
type="text"
name="icon"
@ -138,7 +165,7 @@ export const AppForm = ({ modalHandler }: Props): JSX.Element => {
/>
<span>
Use icon name from MDI or pass a valid URL.
<a href="https://materialdesignicons.com/" target="blank">
<a href="https://pictogrammers.com/library/mdi/" target="blank">
{' '}
Click here for reference
</a>

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

@ -17,8 +17,7 @@ import { actionCreators } from '../../../store';
import { App } from '../../../interfaces';
// Other
import classes from './AppTable.module.css';
import { Table } from '../../UI';
import { Message, Table } from '../../UI';
import { TableActions } from '../../Actions/TableActions';
interface Props {
@ -89,16 +88,16 @@ export const AppTable = (props: Props): JSX.Element => {
return (
<Fragment>
<div className={classes.Message}>
<Message isPrimary={false}>
{config.useOrdering === 'orderId' ? (
<p>You can drag and drop single rows to reorder application</p>
) : (
<p>
Custom order is disabled. You can change it in the{' '}
<Link to="/settings/interface">settings</Link>
<Link to="/settings/general">settings</Link>
</p>
)}
</div>
</Message>
<DragDropContext onDragEnd={dragEndHanlder}>
<Droppable droppableId="apps">

View file

@ -22,7 +22,10 @@ interface Props {
export const BookmarkCard = (props: Props): JSX.Element => {
const { category, fromHomepage = false } = props;
const { config } = useSelector((state: State) => state.config);
const {
config: { config },
auth: { isAuthenticated },
} = useSelector((state: State) => state);
const dispatch = useDispatch();
const { setEditCategory } = bindActionCreators(actionCreators, dispatch);
@ -30,9 +33,11 @@ export const BookmarkCard = (props: Props): JSX.Element => {
return (
<div className={classes.BookmarkCard}>
<h3
className={fromHomepage ? '' : classes.BookmarkHeader}
className={
fromHomepage || !isAuthenticated ? '' : classes.BookmarkHeader
}
onClick={() => {
if (!fromHomepage) {
if (!fromHomepage && isAuthenticated) {
setEditCategory(category);
}
}}

View file

@ -14,7 +14,14 @@ import { Category, Bookmark } from '../../interfaces';
import classes from './Bookmarks.module.css';
// UI
import { Container, Headline, ActionButton, Spinner, Modal } from '../UI';
import {
Container,
Headline,
ActionButton,
Spinner,
Modal,
Message,
} from '../UI';
// Components
import { BookmarkGrid } from './BookmarkGrid/BookmarkGrid';
@ -121,6 +128,11 @@ export const Bookmarks = (props: Props): JSX.Element => {
}
};
const finishEditing = () => {
setShowTable(false);
setEditCategory(null);
};
return (
<Container>
<Modal isOpen={modalIsOpen} setIsOpen={toggleModal}>
@ -150,14 +162,24 @@ export const Bookmarks = (props: Props): JSX.Element => {
icon="mdiPencil"
handler={() => showTableForEditing(ContentType.category)}
/>
<ActionButton
name="Edit Bookmarks"
icon="mdiPencil"
handler={() => showTableForEditing(ContentType.bookmark)}
/>
{showTable && tableContentType === ContentType.bookmark && (
<ActionButton
name="Finish Editing"
icon="mdiPencil"
handler={finishEditing}
/>
)}
</div>
)}
{categories.length && isAuthenticated && !showTable ? (
<Message isPrimary={false}>
Click on category name to edit its bookmarks
</Message>
) : (
<></>
)}
{loading ? (
<Spinner />
) : !showTable ? (

View file

@ -69,6 +69,17 @@ export const BookmarksForm = ({
const formSubmitHandler = (e: FormEvent): void => {
e.preventDefault();
for (let field of ['name', 'url', 'icon'] as const) {
if (/^ +$/.test(formData[field])) {
createNotification({
title: 'Error',
message: `Field cannot be empty: ${field}`,
});
return;
}
}
const createFormData = (): FormData => {
const data = new FormData();
if (customIcon) {

View file

@ -15,11 +15,8 @@ import { actionCreators } from '../../../store';
// Typescript
import { Bookmark, Category } from '../../../interfaces';
// CSS
import classes from './Table.module.css';
// UI
import { Table } from '../../UI';
import { Message, Table } from '../../UI';
import { TableActions } from '../../Actions/TableActions';
import { bookmarkTemplate } from '../../../utility';
@ -108,18 +105,14 @@ export const BookmarksTable = ({ openFormForUpdating }: Props): JSX.Element => {
return (
<Fragment>
{!categoryInEdit ? (
<div className={classes.Message}>
<p>
Switch to grid view and click on the name of category you want to
edit
</p>
</div>
<Message isPrimary={false}>
Switch to grid view and click on the name of category you want to edit
</Message>
) : (
<div className={classes.Message}>
<p>
Editing bookmarks from <span>{categoryInEdit.name}</span> category
</p>
</div>
<Message isPrimary={false}>
Editing bookmarks from&nbsp;<span>{categoryInEdit.name}</span>
&nbsp;category
</Message>
)}
{categoryInEdit && (

View file

@ -16,11 +16,8 @@ import { actionCreators } from '../../../store';
// Typescript
import { Bookmark, Category } from '../../../interfaces';
// CSS
import classes from './Table.module.css';
// UI
import { Table } from '../../UI';
import { Message, Table } from '../../UI';
import { TableActions } from '../../Actions/TableActions';
interface Props {
@ -99,16 +96,16 @@ export const CategoryTable = ({ openFormForUpdating }: Props): JSX.Element => {
return (
<Fragment>
<div className={classes.Message}>
<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/interface">settings</Link>
<Link to="/settings/general">settings</Link>
</p>
)}
</div>
</Message>
<DragDropContext onDragEnd={dragEndHanlder}>
<Droppable droppableId="categories">

View file

@ -1,17 +0,0 @@
.Message {
width: 100%;
display: flex;
justify-content: center;
align-items: baseline;
color: var(--color-primary);
margin-bottom: 20px;
}
.Message a,
.Message span {
color: var(--color-accent);
}
.Message a:hover {
cursor: pointer;
}

View file

@ -64,8 +64,10 @@ export const Home = (): JSX.Element => {
if (localSearch) {
// Search through apps
setAppSearchResult([
...apps.filter(({ name }) =>
new RegExp(escapeRegex(localSearch), 'i').test(name)
...apps.filter(({ name, description }) =>
new RegExp(escapeRegex(localSearch), 'i').test(
`${name} ${description}`
)
),
]);

View file

@ -9,6 +9,7 @@
border-bottom: 2px solid var(--color-accent);
opacity: 0.5;
transition: all 0.2s;
border-radius: 0px;
}
.SearchBar:focus {

View file

@ -64,16 +64,22 @@ export const SearchBar = (props: Props): JSX.Element => {
};
const searchHandler = (e: KeyboardEvent<HTMLInputElement>) => {
const { isLocal, search, query, isURL, sameTab } = searchParser(
inputRef.current.value
);
const {
isLocal,
encodedURL,
primarySearch,
secondarySearch,
isURL,
sameTab,
rawQuery,
} = searchParser(inputRef.current.value);
if (isLocal) {
setLocalSearch(search);
setLocalSearch(encodedURL);
}
if (e.code === 'Enter' || e.code === 'NumpadEnter') {
if (!query.prefix) {
if (!primarySearch.prefix) {
// Prefix not found -> emit notification
createNotification({
title: 'Error',
@ -90,19 +96,21 @@ export const SearchBar = (props: Props): JSX.Element => {
} else if (bookmarkSearchResult?.[0]?.bookmarks?.length) {
redirectUrl(bookmarkSearchResult[0].bookmarks[0].url, sameTab);
} else {
// no local results -> search the internet with the default search provider
let template = query.template;
// no local results -> search the internet with the default search provider if query is not empty
if (!/^ *$/.test(rawQuery)) {
let template = primarySearch.template;
if (query.prefix === 'l') {
template = 'https://duckduckgo.com/?q=';
if (primarySearch.prefix === 'l') {
template = secondarySearch.template;
}
const url = `${template}${encodedURL}`;
redirectUrl(url, sameTab);
}
const url = `${template}${search}`;
redirectUrl(url, sameTab);
}
} else {
// Valid query -> redirect to search results
const url = `${query.template}${search}`;
const url = `${primarySearch.template}${encodedURL}`;
redirectUrl(url, sameTab);
}
} else if (e.code === 'Escape') {

View file

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

View file

@ -9,11 +9,8 @@ import { actionCreators } from '../../../../store';
// Typescript
import { Query } from '../../../../interfaces';
// CSS
import classes from './CustomQueries.module.css';
// UI
import { Modal, Icon, Button } from '../../../UI';
import { Modal, Icon, Button, CompactTable, ActionIcons } from '../../../UI';
// Components
import { QueriesForm } from './QueriesForm';
@ -67,33 +64,27 @@ export const CustomQueries = (): JSX.Element => {
)}
</Modal>
<div>
<div className={classes.QueriesGrid}>
{customQueries.length > 0 && (
<Fragment>
<span>Name</span>
<span>Prefix</span>
<span>Actions</span>
<div className={classes.Separator}></div>
</Fragment>
)}
{customQueries.map((q: Query, idx) => (
<Fragment key={idx}>
<span>{q.name}</span>
<span>{q.prefix}</span>
<span className={classes.ActionIcons}>
<span onClick={() => updateHandler(q)}>
<Icon icon="mdiPencil" />
</span>
<span onClick={() => deleteHandler(q)}>
<Icon icon="mdiDelete" />
</span>
</span>
</Fragment>
))}
</div>
<section>
{customQueries.length ? (
<CompactTable headers={['Name', 'Prefix', 'Actions']}>
{customQueries.map((q: Query, idx) => (
<Fragment key={idx}>
<span>{q.name}</span>
<span>{q.prefix}</span>
<ActionIcons>
<span onClick={() => updateHandler(q)}>
<Icon icon="mdiPencil" />
</span>
<span onClick={() => deleteHandler(q)}>
<Icon icon="mdiDelete" />
</span>
</ActionIcons>
</Fragment>
))}
</CompactTable>
) : (
<></>
)}
<Button
click={() => {
@ -103,7 +94,7 @@ export const CustomQueries = (): JSX.Element => {
>
Add new search provider
</Button>
</div>
</section>
</Fragment>
);
};

View file

@ -0,0 +1,242 @@
// React
import { useState, useEffect, FormEvent, ChangeEvent, Fragment } from 'react';
import { useDispatch, useSelector } from 'react-redux';
// Typescript
import { Query, GeneralForm } from '../../../interfaces';
// Components
import { CustomQueries } from './CustomQueries/CustomQueries';
// UI
import { Button, SettingsHeadline, InputGroup } from '../../UI';
// Utils
import { inputHandler, generalSettingsTemplate } from '../../../utility';
// Data
import searchQueries from '../../../utility/searchQueries.json';
// Redux
import { State } from '../../../store/reducers';
import { bindActionCreators } from 'redux';
import { actionCreators } from '../../../store';
export const GeneralSettings = (): JSX.Element => {
const {
config: { loading, customQueries, config },
bookmarks: { categories },
} = useSelector((state: State) => state);
const dispatch = useDispatch();
const { updateConfig, sortApps, sortCategories, sortBookmarks } =
bindActionCreators(actionCreators, dispatch);
const queries = searchQueries.queries;
// Initial state
const [formData, setFormData] = useState<GeneralForm>(
generalSettingsTemplate
);
// Get config
useEffect(() => {
setFormData({
...config,
});
}, [loading]);
// Form handler
const formSubmitHandler = async (e: FormEvent) => {
e.preventDefault();
// Save settings
await updateConfig(formData);
// Sort entities with new settings
if (formData.useOrdering !== config.useOrdering) {
sortApps();
sortCategories();
for (let { id } of categories) {
sortBookmarks(id);
}
}
};
// Input handler
const inputChangeHandler = (
e: ChangeEvent<HTMLInputElement | HTMLSelectElement>,
options?: { isNumber?: boolean; isBool?: boolean }
) => {
inputHandler<GeneralForm>({
e,
options,
setStateHandler: setFormData,
state: formData,
});
};
return (
<Fragment>
<form
onSubmit={(e) => formSubmitHandler(e)}
style={{ marginBottom: '30px' }}
>
{/* === GENERAL OPTIONS === */}
<SettingsHeadline text="General" />
{/* SORT TYPE */}
<InputGroup>
<label htmlFor="useOrdering">Sorting type</label>
<select
id="useOrdering"
name="useOrdering"
value={formData.useOrdering}
onChange={(e) => inputChangeHandler(e)}
>
<option value="createdAt">By creation date</option>
<option value="name">Alphabetical order</option>
<option value="orderId">Custom order</option>
</select>
</InputGroup>
{/* === APPS OPTIONS === */}
<SettingsHeadline text="Apps" />
{/* PIN APPS */}
<InputGroup>
<label htmlFor="pinAppsByDefault">
Pin new applications by default
</label>
<select
id="pinAppsByDefault"
name="pinAppsByDefault"
value={formData.pinAppsByDefault ? 1 : 0}
onChange={(e) => inputChangeHandler(e, { isBool: true })}
>
<option value={1}>True</option>
<option value={0}>False</option>
</select>
</InputGroup>
{/* APPS OPPENING */}
<InputGroup>
<label htmlFor="appsSameTab">Open applications in the same tab</label>
<select
id="appsSameTab"
name="appsSameTab"
value={formData.appsSameTab ? 1 : 0}
onChange={(e) => inputChangeHandler(e, { isBool: true })}
>
<option value={1}>True</option>
<option value={0}>False</option>
</select>
</InputGroup>
{/* === BOOKMARKS OPTIONS === */}
<SettingsHeadline text="Bookmarks" />
{/* PIN CATEGORIES */}
<InputGroup>
<label htmlFor="pinCategoriesByDefault">
Pin new categories by default
</label>
<select
id="pinCategoriesByDefault"
name="pinCategoriesByDefault"
value={formData.pinCategoriesByDefault ? 1 : 0}
onChange={(e) => inputChangeHandler(e, { isBool: true })}
>
<option value={1}>True</option>
<option value={0}>False</option>
</select>
</InputGroup>
{/* BOOKMARKS OPPENING */}
<InputGroup>
<label htmlFor="bookmarksSameTab">
Open bookmarks in the same tab
</label>
<select
id="bookmarksSameTab"
name="bookmarksSameTab"
value={formData.bookmarksSameTab ? 1 : 0}
onChange={(e) => inputChangeHandler(e, { isBool: true })}
>
<option value={1}>True</option>
<option value={0}>False</option>
</select>
</InputGroup>
{/* === SEARCH OPTIONS === */}
<SettingsHeadline text="Search" />
<InputGroup>
<label htmlFor="defaultSearchProvider">Primary search provider</label>
<select
id="defaultSearchProvider"
name="defaultSearchProvider"
value={formData.defaultSearchProvider}
onChange={(e) => inputChangeHandler(e)}
>
{[...queries, ...customQueries].map((query: Query, idx) => {
const isCustom = idx >= queries.length;
return (
<option key={idx} value={query.prefix}>
{isCustom && '+'} {query.name}
</option>
);
})}
</select>
</InputGroup>
{formData.defaultSearchProvider === 'l' && (
<InputGroup>
<label htmlFor="secondarySearchProvider">
Secondary search provider
</label>
<select
id="secondarySearchProvider"
name="secondarySearchProvider"
value={formData.secondarySearchProvider}
onChange={(e) => inputChangeHandler(e)}
>
{[...queries, ...customQueries].map((query: Query, idx) => {
const isCustom = idx >= queries.length;
return (
<option key={idx} value={query.prefix}>
{isCustom && '+'} {query.name}
</option>
);
})}
</select>
<span>
Will be used when "Local search" is primary search provider and
there are not any local results
</span>
</InputGroup>
)}
<InputGroup>
<label htmlFor="searchSameTab">
Open search results in the same tab
</label>
<select
id="searchSameTab"
name="searchSameTab"
value={formData.searchSameTab ? 1 : 0}
onChange={(e) => inputChangeHandler(e, { isBool: true })}
>
<option value={1}>True</option>
<option value={0}>False</option>
</select>
</InputGroup>
<Button>Save changes</Button>
</form>
{/* CUSTOM QUERIES */}
<SettingsHeadline text="Custom search providers" />
<CustomQueries />
</Fragment>
);
};

View file

@ -1,30 +0,0 @@
.QueriesGrid {
display: grid;
grid-template-columns: repeat(3, 1fr);
}
.QueriesGrid span {
color: var(--color-primary);
}
.QueriesGrid span:last-child {
margin-bottom: 10px;
}
.ActionIcons {
display: flex;
}
.ActionIcons svg {
width: 20px;
}
.ActionIcons svg:hover {
cursor: pointer;
}
.Separator {
grid-column: 1 / 4;
border-bottom: 1px solid var(--color-primary);
margin: 10px 0;
}

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

@ -16,7 +16,7 @@ import { WeatherSettings } from './WeatherSettings/WeatherSettings';
import { UISettings } from './UISettings/UISettings';
import { AppDetails } from './AppDetails/AppDetails';
import { StyleSettings } from './StyleSettings/StyleSettings';
import { SearchSettings } from './SearchSettings/SearchSettings';
import { GeneralSettings } from './GeneralSettings/GeneralSettings';
import { DockerSettings } from './DockerSettings/DockerSettings';
import { ProtectedRoute } from '../Routing/ProtectedRoute';
@ -24,9 +24,11 @@ import { ProtectedRoute } from '../Routing/ProtectedRoute';
import { Container, Headline } from '../UI';
// Data
import { routes } from './settings.json';
import clientRoutes from './settings.json';
export const Settings = (): JSX.Element => {
const routes = clientRoutes.routes;
const { isAuthenticated } = useSelector((state: State) => state.auth);
const tabs = isAuthenticated ? routes : routes.filter((r) => !r.authRequired);
@ -59,8 +61,8 @@ export const Settings = (): JSX.Element => {
component={WeatherSettings}
/>
<ProtectedRoute
path="/settings/search"
component={SearchSettings}
path="/settings/general"
component={GeneralSettings}
/>
<ProtectedRoute path="/settings/interface" component={UISettings} />
<ProtectedRoute

View file

@ -0,0 +1,7 @@
.ThemeBuilder {
margin-bottom: 30px;
}
.Buttons button:not(:last-child) {
margin-right: 10px;
}

View file

@ -0,0 +1,95 @@
import { useState, useEffect } from 'react';
// Redux
import { useSelector, useDispatch } from 'react-redux';
import { bindActionCreators } from 'redux';
import { actionCreators } from '../../../../store';
import { State } from '../../../../store/reducers';
// Other
import { Theme } from '../../../../interfaces';
// UI
import { Button, Modal } from '../../../UI';
import { ThemeGrid } from '../ThemeGrid/ThemeGrid';
import classes from './ThemeBuilder.module.css';
import { ThemeCreator } from './ThemeCreator';
import { ThemeEditor } from './ThemeEditor';
interface Props {
themes: Theme[];
}
export const ThemeBuilder = ({ themes }: Props): JSX.Element => {
const {
auth: { isAuthenticated },
theme: { themeInEdit, userThemes },
} = useSelector((state: State) => state);
const { editTheme } = bindActionCreators(actionCreators, useDispatch());
const [showModal, toggleShowModal] = useState(false);
const [isInEdit, toggleIsInEdit] = useState(false);
useEffect(() => {
if (themeInEdit) {
toggleIsInEdit(false);
toggleShowModal(true);
}
}, [themeInEdit]);
useEffect(() => {
if (isInEdit && !userThemes.length) {
toggleIsInEdit(false);
toggleShowModal(false);
}
}, [userThemes]);
return (
<div className={classes.ThemeBuilder}>
{/* MODALS */}
<Modal
isOpen={showModal}
setIsOpen={() => toggleShowModal(!showModal)}
cb={() => editTheme(null)}
>
{isInEdit ? (
<ThemeEditor modalHandler={() => toggleShowModal(!showModal)} />
) : (
<ThemeCreator modalHandler={() => toggleShowModal(!showModal)} />
)}
</Modal>
{/* USER THEMES */}
<ThemeGrid themes={themes} />
{/* BUTTONS */}
{isAuthenticated && (
<div className={classes.Buttons}>
<Button
click={() => {
editTheme(null);
toggleIsInEdit(false);
toggleShowModal(!showModal);
}}
>
Create new theme
</Button>
{themes.length ? (
<Button
click={() => {
toggleIsInEdit(true);
toggleShowModal(!showModal);
}}
>
Edit user themes
</Button>
) : (
<></>
)}
</div>
)}
</div>
);
};

View file

@ -0,0 +1,5 @@
.ColorsContainer {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-gap: 10px;
}

View file

@ -0,0 +1,152 @@
import { ChangeEvent, FormEvent, useState, useEffect } from 'react';
// Redux
import { useDispatch, useSelector } from 'react-redux';
import { bindActionCreators } from 'redux';
import { actionCreators } from '../../../../store';
import { State } from '../../../../store/reducers';
// UI
import { Button, InputGroup, ModalForm } from '../../../UI';
import classes from './ThemeCreator.module.css';
// Other
import { Theme } from '../../../../interfaces';
interface Props {
modalHandler: () => void;
}
export const ThemeCreator = ({ modalHandler }: Props): JSX.Element => {
const {
theme: { activeTheme, themeInEdit },
} = useSelector((state: State) => state);
const { addTheme, updateTheme, editTheme } = bindActionCreators(
actionCreators,
useDispatch()
);
const [formData, setFormData] = useState<Theme>({
name: '',
isCustom: true,
colors: {
primary: '#ffffff',
accent: '#ffffff',
background: '#ffffff',
},
});
useEffect(() => {
setFormData({ ...formData, colors: activeTheme.colors });
}, [activeTheme]);
useEffect(() => {
if (themeInEdit) {
setFormData(themeInEdit);
}
}, [themeInEdit]);
const inputChangeHandler = (e: ChangeEvent<HTMLInputElement>) => {
const { name, value } = e.target;
setFormData({
...formData,
[name]: value,
});
};
const setColor = ({
target: { value, name },
}: ChangeEvent<HTMLInputElement>) => {
setFormData({
...formData,
colors: {
...formData.colors,
[name]: value,
},
});
};
const closeModal = () => {
editTheme(null);
modalHandler();
};
const formHandler = (e: FormEvent) => {
e.preventDefault();
if (!themeInEdit) {
addTheme(formData);
} else {
updateTheme(formData, themeInEdit.name);
}
// close modal
closeModal();
// clear theme name
setFormData({ ...formData, name: '' });
};
return (
<ModalForm formHandler={formHandler} modalHandler={closeModal}>
<InputGroup>
<label htmlFor="name">Theme name</label>
<input
type="text"
name="name"
id="name"
placeholder="my_theme"
required
value={formData.name}
onChange={(e) => inputChangeHandler(e)}
/>
</InputGroup>
<div className={classes.ColorsContainer}>
<InputGroup>
<label htmlFor="primary">Primary color</label>
<input
type="color"
name="primary"
id="primary"
required
value={formData.colors.primary}
onChange={(e) => setColor(e)}
/>
</InputGroup>
<InputGroup>
<label htmlFor="accent">Accent color</label>
<input
type="color"
name="accent"
id="accent"
required
value={formData.colors.accent}
onChange={(e) => setColor(e)}
/>
</InputGroup>
<InputGroup>
<label htmlFor="background">Background color</label>
<input
type="color"
name="background"
id="background"
required
value={formData.colors.background}
onChange={(e) => setColor(e)}
/>
</InputGroup>
</div>
{!themeInEdit ? (
<Button>Add theme</Button>
) : (
<Button>Update theme</Button>
)}
</ModalForm>
);
};

View file

@ -0,0 +1,57 @@
import { Fragment } from 'react';
// Redux
import { useSelector, useDispatch } from 'react-redux';
import { bindActionCreators } from 'redux';
import { Theme } from '../../../../interfaces';
import { actionCreators } from '../../../../store';
import { State } from '../../../../store/reducers';
// Other
import { ActionIcons, CompactTable, Icon, ModalForm } from '../../../UI';
interface Props {
modalHandler: () => void;
}
export const ThemeEditor = (props: Props): JSX.Element => {
const {
theme: { userThemes },
} = useSelector((state: State) => state);
const { deleteTheme, editTheme } = bindActionCreators(
actionCreators,
useDispatch()
);
const updateHandler = (theme: Theme) => {
props.modalHandler();
editTheme(theme);
};
const deleteHandler = (theme: Theme) => {
if (window.confirm(`Are you sure you want to delete this theme?`)) {
deleteTheme(theme.name);
}
};
return (
<ModalForm formHandler={() => {}} modalHandler={props.modalHandler}>
<CompactTable headers={['Name', 'Actions']}>
{userThemes.map((t, idx) => (
<Fragment key={idx}>
<span>{t.name}</span>
<ActionIcons>
<span onClick={() => updateHandler(t)}>
<Icon icon="mdiPencil" />
</span>
<span onClick={() => deleteHandler(t)}>
<Icon icon="mdiDelete" />
</span>
</ActionIcons>
</Fragment>
))}
</CompactTable>
</ModalForm>
);
};

View file

@ -15,4 +15,4 @@
.ThemerGrid {
grid-template-columns: 1fr 1fr 1fr;
}
}
}

View file

@ -0,0 +1,22 @@
// Components
import { ThemePreview } from '../ThemePreview/ThemePreview';
// Other
import { Theme } from '../../../../interfaces';
import classes from './ThemeGrid.module.css';
interface Props {
themes: Theme[];
}
export const ThemeGrid = ({ themes }: Props): JSX.Element => {
return (
<div className={classes.ThemerGrid}>
{themes.map(
(theme: Theme, idx: number): JSX.Element => (
<ThemePreview key={idx} theme={theme} />
)
)}
</div>
);
};

View file

@ -1,32 +0,0 @@
import { Theme } from '../../../interfaces/Theme';
import classes from './ThemePreview.module.css';
interface Props {
theme: Theme;
applyTheme: Function;
}
export const ThemePreview = (props: Props): JSX.Element => {
return (
<div
className={classes.ThemePreview}
onClick={() => props.applyTheme(props.theme.name)}
>
<div className={classes.ColorsPreview}>
<div
className={classes.ColorPreview}
style={{ backgroundColor: props.theme.colors.background }}
></div>
<div
className={classes.ColorPreview}
style={{ backgroundColor: props.theme.colors.primary }}
></div>
<div
className={classes.ColorPreview}
style={{ backgroundColor: props.theme.colors.accent }}
></div>
</div>
<p>{props.theme.name}</p>
</div>
);
};

View file

@ -0,0 +1,38 @@
// Redux
import { useDispatch } from 'react-redux';
import { bindActionCreators } from 'redux';
import { actionCreators } from '../../../../store';
// Other
import { Theme } from '../../../../interfaces/Theme';
import classes from './ThemePreview.module.css';
interface Props {
theme: Theme;
}
export const ThemePreview = ({
theme: { colors, name },
}: Props): JSX.Element => {
const { setTheme } = bindActionCreators(actionCreators, useDispatch());
return (
<div className={classes.ThemePreview} onClick={() => setTheme(colors)}>
<div className={classes.ColorsPreview}>
<div
className={classes.ColorPreview}
style={{ backgroundColor: colors.background }}
></div>
<div
className={classes.ColorPreview}
style={{ backgroundColor: colors.primary }}
></div>
<div
className={classes.ColorPreview}
style={{ backgroundColor: colors.accent }}
></div>
</div>
<p>{name}</p>
</div>
);
};

View file

@ -4,31 +4,32 @@ import { ChangeEvent, FormEvent, Fragment, useEffect, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { bindActionCreators } from 'redux';
import { actionCreators } from '../../../store';
import { State } from '../../../store/reducers';
// Typescript
import { Theme, ThemeSettingsForm } from '../../../interfaces';
// Components
import { ThemePreview } from './ThemePreview';
import { Button, InputGroup, SettingsHeadline } from '../../UI';
import { Button, InputGroup, SettingsHeadline, Spinner } from '../../UI';
import { ThemeBuilder } from './ThemeBuilder/ThemeBuilder';
import { ThemeGrid } from './ThemeGrid/ThemeGrid';
// Other
import classes from './Themer.module.css';
import { themes } from './themes.json';
import { State } from '../../../store/reducers';
import { inputHandler, themeSettingsTemplate } from '../../../utility';
import {
inputHandler,
parseThemeToPAB,
themeSettingsTemplate,
} from '../../../utility';
export const Themer = (): JSX.Element => {
const {
auth: { isAuthenticated },
config: { loading, config },
theme: { themes, userThemes },
} = useSelector((state: State) => state);
const dispatch = useDispatch();
const { setTheme, updateConfig } = bindActionCreators(
actionCreators,
dispatch
);
const { updateConfig } = bindActionCreators(actionCreators, dispatch);
// Initial state
const [formData, setFormData] = useState<ThemeSettingsForm>(
@ -47,7 +48,7 @@ export const Themer = (): JSX.Element => {
e.preventDefault();
// Save settings
await updateConfig(formData);
await updateConfig({ ...formData });
};
// Input handler
@ -63,31 +64,34 @@ export const Themer = (): JSX.Element => {
});
};
const customThemesEl = (
<Fragment>
<SettingsHeadline text="User themes" />
<ThemeBuilder themes={userThemes} />
</Fragment>
);
return (
<Fragment>
<SettingsHeadline text="Set theme" />
<div className={classes.ThemerGrid}>
{themes.map(
(theme: Theme, idx: number): JSX.Element => (
<ThemePreview key={idx} theme={theme} applyTheme={setTheme} />
)
)}
</div>
<SettingsHeadline text="App themes" />
{!themes.length ? <Spinner /> : <ThemeGrid themes={themes} />}
{!userThemes.length ? isAuthenticated && customThemesEl : customThemesEl}
{isAuthenticated && (
<form onSubmit={formSubmitHandler}>
<SettingsHeadline text="Other settings" />
<InputGroup>
<label htmlFor="defaultTheme">Default theme (for new users)</label>
<label htmlFor="defaultTheme">Default theme for new users</label>
<select
id="defaultTheme"
name="defaultTheme"
value={formData.defaultTheme}
onChange={(e) => inputChangeHandler(e)}
>
{themes.map((theme: Theme, idx) => (
<option key={idx} value={theme.name}>
{theme.name}
{[...themes, ...userThemes].map((theme: Theme, idx) => (
<option key={idx} value={parseThemeToPAB(theme.colors)}>
{theme.isCustom && '+'} {theme.name}
</option>
))}
</select>

View file

@ -7,28 +7,22 @@ import { bindActionCreators } from 'redux';
import { actionCreators } from '../../../store';
// Typescript
import { OtherSettingsForm } from '../../../interfaces';
import { UISettingsForm } from '../../../interfaces';
// UI
import { InputGroup, Button, SettingsHeadline } from '../../UI';
// Utils
import { otherSettingsTemplate, inputHandler } from '../../../utility';
import { uiSettingsTemplate, inputHandler } from '../../../utility';
export const UISettings = (): JSX.Element => {
const {
config: { loading, config },
bookmarks: { categories },
} = useSelector((state: State) => state);
const { loading, config } = useSelector((state: State) => state.config);
const dispatch = useDispatch();
const { updateConfig, sortApps, sortCategories, sortBookmarks } =
bindActionCreators(actionCreators, dispatch);
const { updateConfig } = bindActionCreators(actionCreators, dispatch);
// Initial state
const [formData, setFormData] = useState<OtherSettingsForm>(
otherSettingsTemplate
);
const [formData, setFormData] = useState<UISettingsForm>(uiSettingsTemplate);
// Get config
useEffect(() => {
@ -46,16 +40,6 @@ export const UISettings = (): JSX.Element => {
// Update local page title
document.title = formData.customTitle;
// Sort entities with new settings
if (formData.useOrdering !== config.useOrdering) {
sortApps();
sortCategories();
for (let { id } of categories) {
sortBookmarks(id);
}
}
};
// Input handler
@ -63,7 +47,7 @@ export const UISettings = (): JSX.Element => {
e: ChangeEvent<HTMLInputElement | HTMLSelectElement>,
options?: { isNumber?: boolean; isBool?: boolean }
) => {
inputHandler<OtherSettingsForm>({
inputHandler<UISettingsForm>({
e,
options,
setStateHandler: setFormData,
@ -88,6 +72,36 @@ export const UISettings = (): JSX.Element => {
/>
</InputGroup>
{/* === SEARCH OPTIONS === */}
<SettingsHeadline text="Search" />
{/* HIDE SEARCHBAR */}
<InputGroup>
<label htmlFor="hideSearch">Hide search bar</label>
<select
id="hideSearch"
name="hideSearch"
value={formData.hideSearch ? 1 : 0}
onChange={(e) => inputChangeHandler(e, { isBool: true })}
>
<option value={1}>True</option>
<option value={0}>False</option>
</select>
</InputGroup>
{/* AUTOFOCUS SEARCHBAR */}
<InputGroup>
<label htmlFor="disableAutofocus">Disable search bar autofocus</label>
<select
id="disableAutofocus"
name="disableAutofocus"
value={formData.disableAutofocus ? 1 : 0}
onChange={(e) => inputChangeHandler(e, { isBool: true })}
>
<option value={1}>True</option>
<option value={0}>False</option>
</select>
</InputGroup>
{/* === HEADER OPTIONS === */}
<SettingsHeadline text="Header" />
{/* HIDE HEADER */}
@ -160,8 +174,8 @@ export const UISettings = (): JSX.Element => {
onChange={(e) => inputChangeHandler(e)}
/>
<span>
Greetings must be separated with semicolon. Only 4 messages can be
used
Greetings must be separated with semicolon. All 4 messages must be
filled, even if they are the same
</span>
</InputGroup>
@ -193,85 +207,8 @@ export const UISettings = (): JSX.Element => {
<span>Names must be separated with semicolon</span>
</InputGroup>
{/* === BEAHVIOR OPTIONS === */}
<SettingsHeadline text="App Behavior" />
{/* PIN APPS */}
<InputGroup>
<label htmlFor="pinAppsByDefault">
Pin new applications by default
</label>
<select
id="pinAppsByDefault"
name="pinAppsByDefault"
value={formData.pinAppsByDefault ? 1 : 0}
onChange={(e) => inputChangeHandler(e, { isBool: true })}
>
<option value={1}>True</option>
<option value={0}>False</option>
</select>
</InputGroup>
{/* PIN CATEGORIES */}
<InputGroup>
<label htmlFor="pinCategoriesByDefault">
Pin new categories by default
</label>
<select
id="pinCategoriesByDefault"
name="pinCategoriesByDefault"
value={formData.pinCategoriesByDefault ? 1 : 0}
onChange={(e) => inputChangeHandler(e, { isBool: true })}
>
<option value={1}>True</option>
<option value={0}>False</option>
</select>
</InputGroup>
{/* SORT TYPE */}
<InputGroup>
<label htmlFor="useOrdering">Sorting type</label>
<select
id="useOrdering"
name="useOrdering"
value={formData.useOrdering}
onChange={(e) => inputChangeHandler(e)}
>
<option value="createdAt">By creation date</option>
<option value="name">Alphabetical order</option>
<option value="orderId">Custom order</option>
</select>
</InputGroup>
{/* APPS OPPENING */}
<InputGroup>
<label htmlFor="appsSameTab">Open applications in the same tab</label>
<select
id="appsSameTab"
name="appsSameTab"
value={formData.appsSameTab ? 1 : 0}
onChange={(e) => inputChangeHandler(e, { isBool: true })}
>
<option value={1}>True</option>
<option value={0}>False</option>
</select>
</InputGroup>
{/* BOOKMARKS OPPENING */}
<InputGroup>
<label htmlFor="bookmarksSameTab">Open bookmarks in the same tab</label>
<select
id="bookmarksSameTab"
name="bookmarksSameTab"
value={formData.bookmarksSameTab ? 1 : 0}
onChange={(e) => inputChangeHandler(e, { isBool: true })}
>
<option value={1}>True</option>
<option value={0}>False</option>
</select>
</InputGroup>
{/* === MODULES OPTIONS === */}
<SettingsHeadline text="Modules" />
{/* === SECTIONS OPTIONS === */}
<SettingsHeadline text="Sections" />
{/* HIDE APPS */}
<InputGroup>
<label htmlFor="hideApps">Hide applications</label>
@ -286,9 +223,9 @@ export const UISettings = (): JSX.Element => {
</select>
</InputGroup>
{/* HIDE CATEGORIES */}
{/* HIDE BOOKMARK CATEGORIES */}
<InputGroup>
<label htmlFor="hideCategories">Hide categories</label>
<label htmlFor="hideCategories">Hide bookmarks</label>
<select
id="hideCategories"
name="hideCategories"

View file

@ -82,6 +82,19 @@ export const WeatherSettings = (): JSX.Element => {
});
};
// Get user location
const getLocation = () => {
window.navigator.geolocation.getCurrentPosition(
({ coords: { latitude, longitude } }) => {
setFormData({
...formData,
lat: latitude,
long: longitude,
});
}
);
};
return (
<form onSubmit={(e) => formSubmitHandler(e)}>
<SettingsHeadline text="API" />
@ -120,15 +133,8 @@ export const WeatherSettings = (): JSX.Element => {
step="any"
lang="en-150"
/>
<span>
You can use
<a
href="https://www.latlong.net/convert-address-to-lat-long.html"
target="blank"
>
{' '}
latlong.net
</a>
<span onClick={getLocation}>
<a href="#">Click to get current location</a>
</span>
</InputGroup>

View file

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

View file

@ -23,7 +23,7 @@
.InputGroup span {
font-size: 12px;
color: var(--color-primary)
color: var(--color-primary);
}
.InputGroup span a {
@ -37,4 +37,14 @@
.InputGroup textarea {
resize: none;
height: 50vh;
}
}
.InputGroup input[type='color'] {
margin: 0;
padding: 0;
background-color: transparent;
}
.InputGroup input[type='color']:hover {
cursor: pointer;
}

View file

@ -1,4 +1,4 @@
const classes = require('./SettingsHeadline.module.css');
import classes from './SettingsHeadline.module.css';
interface Props {
text: string;

View file

@ -0,0 +1,11 @@
.ActionIcons {
display: flex;
}
.ActionIcons svg {
width: 20px;
}
.ActionIcons svg:hover {
cursor: pointer;
}

View file

@ -0,0 +1,10 @@
import { ReactNode } from 'react';
import styles from './ActionIcons.module.css';
interface Props {
children: ReactNode;
}
export const ActionIcons = ({ children }: Props): JSX.Element => {
return <span className={styles.ActionIcons}>{children}</span>;
};

View file

@ -10,7 +10,7 @@ interface Props {
}
export const WeatherIcon = (props: Props): JSX.Element => {
const { theme } = useSelector((state: State) => state.theme);
const { activeTheme } = useSelector((state: State) => state.theme);
const icon = props.isDay
? new IconMapping().mapIcon(props.weatherStatusCode, TimeOfDay.day)
@ -18,7 +18,7 @@ export const WeatherIcon = (props: Props): JSX.Element => {
useEffect(() => {
const delay = setTimeout(() => {
const skycons = new Skycons({ color: theme.colors.accent });
const skycons = new Skycons({ color: activeTheme.colors.accent });
skycons.add(`weather-icon`, icon);
skycons.play();
}, 1);
@ -26,7 +26,7 @@ export const WeatherIcon = (props: Props): JSX.Element => {
return () => {
clearTimeout(delay);
};
}, [props.weatherStatusCode, icon, theme.colors.accent]);
}, [props.weatherStatusCode, icon, activeTheme.colors.accent]);
return <canvas id={`weather-icon`} width="50" height="50"></canvas>;
};

View file

@ -6,24 +6,32 @@ interface Props {
isOpen: boolean;
setIsOpen: Function;
children: ReactNode;
cb?: Function;
}
export const Modal = (props: Props): JSX.Element => {
export const Modal = ({
isOpen,
setIsOpen,
children,
cb,
}: Props): JSX.Element => {
const modalRef = useRef(null);
const modalClasses = [
classes.Modal,
props.isOpen ? classes.ModalOpen : classes.ModalClose,
isOpen ? classes.ModalOpen : classes.ModalClose,
].join(' ');
const clickHandler = (e: MouseEvent) => {
if (e.target === modalRef.current) {
props.setIsOpen(false);
setIsOpen(false);
if (cb) cb();
}
};
return (
<div className={modalClasses} onClick={clickHandler} ref={modalRef}>
{props.children}
{children}
</div>
);
};

View file

@ -0,0 +1,16 @@
.CompactTable {
display: grid;
}
.CompactTable span {
color: var(--color-primary);
}
.CompactTable span:last-child {
margin-bottom: 10px;
}
.Separator {
border-bottom: 1px solid var(--color-primary);
margin: 10px 0;
}

View file

@ -0,0 +1,27 @@
import { ReactNode } from 'react';
import classes from './CompactTable.module.css';
interface Props {
headers: string[];
children?: ReactNode;
}
export const CompactTable = ({ headers, children }: Props): JSX.Element => {
return (
<div
className={classes.CompactTable}
style={{ gridTemplateColumns: `repeat(${headers.length}, 1fr)` }}
>
{headers.map((h, idx) => (
<span key={idx}>{h}</span>
))}
<div
className={classes.Separator}
style={{ gridColumn: `1 / ${headers.length + 1}` }}
></div>
{children}
</div>
);
};

View file

@ -6,3 +6,21 @@
color: var(--color-accent);
font-weight: 600;
}
.messageCenter {
width: 100%;
display: flex;
justify-content: center;
align-items: baseline;
color: var(--color-primary);
margin-bottom: 20px;
}
.messageCenter a,
.messageCenter span {
color: var(--color-accent);
}
.messageCenter a:hover {
cursor: pointer;
}

View file

@ -4,8 +4,11 @@ import classes from './Message.module.css';
interface Props {
children: ReactNode;
isPrimary?: boolean;
}
export const Message = ({ children }: Props): JSX.Element => {
return <p className={classes.message}>{children}</p>;
export const Message = ({ children, isPrimary = true }: Props): JSX.Element => {
const style = isPrimary ? classes.message : classes.messageCenter;
return <p className={style}>{children}</p>;
};

View file

@ -1,10 +1,12 @@
export * from './Table/Table';
export * from './Tables/Table/Table';
export * from './Tables/CompactTable/CompactTable';
export * from './Spinner/Spinner';
export * from './Notification/Notification';
export * from './Modal/Modal';
export * from './Layout/Layout';
export * from './Icons/Icon/Icon';
export * from './Icons/WeatherIcon/WeatherIcon';
export * from './Icons/ActionIcons/ActionIcons';
export * from './Headlines/Headline/Headline';
export * from './Headlines/SectionHeadline/SectionHeadline';
export * from './Headlines/SettingsHeadline/SettingsHeadline';

View file

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

View file

@ -17,6 +17,7 @@ export interface Config {
hideCategories: boolean;
hideSearch: boolean;
defaultSearchProvider: string;
secondarySearchProvider: string;
dockerApps: boolean;
dockerHost: string;
kubernetesApps: boolean;

View file

@ -8,29 +8,30 @@ export interface WeatherForm {
weatherData: WeatherData;
}
export interface SearchForm {
hideSearch: boolean;
export interface GeneralForm {
defaultSearchProvider: string;
secondarySearchProvider: string;
searchSameTab: boolean;
disableAutofocus: boolean;
}
export interface OtherSettingsForm {
customTitle: string;
pinAppsByDefault: boolean;
pinCategoriesByDefault: boolean;
hideHeader: boolean;
hideApps: boolean;
hideCategories: boolean;
useOrdering: string;
appsSameTab: boolean;
bookmarksSameTab: boolean;
}
export interface UISettingsForm {
customTitle: string;
hideHeader: boolean;
hideApps: boolean;
hideCategories: boolean;
useAmericanDate: boolean;
greetingsSchema: string;
daySchema: string;
monthSchema: string;
showTime: boolean;
hideDate: boolean;
hideSearch: boolean;
disableAutofocus: boolean;
}
export interface DockerSettingsForm {

View file

@ -4,6 +4,8 @@ export interface SearchResult {
isLocal: boolean;
isURL: boolean;
sameTab: boolean;
search: string;
query: Query;
encodedURL: string;
primarySearch: Query;
secondarySearch: Query;
rawQuery: string;
}

View file

@ -1,8 +1,11 @@
export interface ThemeColors {
background: string;
primary: string;
accent: string;
}
export interface Theme {
name: string;
colors: {
background: string;
primary: string;
accent: string;
}
}
colors: ThemeColors;
isCustom: boolean;
}

View file

@ -7,7 +7,7 @@ import {
UpdateConfigAction,
UpdateQueryAction,
} from '../actions/config';
import axios from 'axios';
import axios, { AxiosError } from 'axios';
import { ApiResponse, Config, Query } from '../../interfaces';
import { ActionType } from '../action-types';
import { storeUIConfig, applyAuth } from '../../utility';
@ -103,7 +103,15 @@ export const addQuery =
payload: res.data.data,
});
} catch (err) {
console.log(err);
const error = err as AxiosError<{ error: string }>;
dispatch<any>({
type: ActionType.createNotification,
payload: {
title: 'Error',
message: error.response?.data.error,
},
});
}
};

View file

@ -1,30 +1,128 @@
import { Dispatch } from 'redux';
import { SetThemeAction } from '../actions/theme';
import {
AddThemeAction,
DeleteThemeAction,
EditThemeAction,
FetchThemesAction,
SetThemeAction,
UpdateThemeAction,
} from '../actions/theme';
import { ActionType } from '../action-types';
import { Theme } from '../../interfaces/Theme';
import { themes } from '../../components/Settings/Themer/themes.json';
import { Theme, ApiResponse, ThemeColors } from '../../interfaces';
import { applyAuth, parseThemeToPAB } from '../../utility';
import axios, { AxiosError } from 'axios';
export const setTheme =
(name: string, remeberTheme: boolean = true) =>
(colors: ThemeColors, remeberTheme: boolean = true) =>
(dispatch: Dispatch<SetThemeAction>) => {
const theme = themes.find((theme) => theme.name === name);
if (remeberTheme) {
localStorage.setItem('theme', parseThemeToPAB(colors));
}
if (theme) {
if (remeberTheme) {
localStorage.setItem('theme', name);
}
for (const [key, value] of Object.entries(colors)) {
document.body.style.setProperty(`--color-${key}`, value);
}
loadTheme(theme);
dispatch({
type: ActionType.setTheme,
payload: colors,
});
};
export const fetchThemes =
() => async (dispatch: Dispatch<FetchThemesAction>) => {
try {
const res = await axios.get<ApiResponse<Theme[]>>('/api/themes');
dispatch({
type: ActionType.setTheme,
payload: theme,
type: ActionType.fetchThemes,
payload: res.data.data,
});
} catch (err) {
console.log(err);
}
};
export const addTheme =
(theme: Theme) => async (dispatch: Dispatch<AddThemeAction>) => {
try {
const res = await axios.post<ApiResponse<Theme>>('/api/themes', theme, {
headers: applyAuth(),
});
dispatch({
type: ActionType.addTheme,
payload: res.data.data,
});
dispatch<any>({
type: ActionType.createNotification,
payload: {
title: 'Success',
message: 'Theme added',
},
});
} catch (err) {
const error = err as AxiosError<{ error: string }>;
dispatch<any>({
type: ActionType.createNotification,
payload: {
title: 'Error',
message: error.response?.data.error,
},
});
}
};
export const loadTheme = (theme: Theme): void => {
for (const [key, value] of Object.entries(theme.colors)) {
document.body.style.setProperty(`--color-${key}`, value);
}
};
export const deleteTheme =
(name: string) => async (dispatch: Dispatch<DeleteThemeAction>) => {
try {
const res = await axios.delete<ApiResponse<Theme[]>>(
`/api/themes/${name}`,
{ headers: applyAuth() }
);
dispatch({
type: ActionType.deleteTheme,
payload: res.data.data,
});
dispatch<any>({
type: ActionType.createNotification,
payload: {
title: 'Success',
message: 'Theme deleted',
},
});
} catch (err) {
console.log(err);
}
};
export const editTheme =
(theme: Theme | null) => (dispatch: Dispatch<EditThemeAction>) => {
dispatch({
type: ActionType.editTheme,
payload: theme,
});
};
export const updateTheme =
(theme: Theme, originalName: string) =>
async (dispatch: Dispatch<UpdateThemeAction>) => {
try {
const res = await axios.put<ApiResponse<Theme[]>>(
`/api/themes/${originalName}`,
theme,
{ headers: applyAuth() }
);
dispatch({
type: ActionType.updateTheme,
payload: res.data.data,
});
} catch (err) {
console.log(err);
}
};

View file

@ -1,6 +1,11 @@
export enum ActionType {
// THEME
setTheme = 'SET_THEME',
fetchThemes = 'FETCH_THEMES',
addTheme = 'ADD_THEME',
deleteTheme = 'DELETE_THEME',
updateTheme = 'UPDATE_THEME',
editTheme = 'EDIT_THEME',
// CONFIG
getConfig = 'GET_CONFIG',
updateConfig = 'UPDATE_CONFIG',

View file

@ -1,6 +1,13 @@
import { App } from '../../interfaces';
import { SetThemeAction } from './theme';
import {
AddThemeAction,
DeleteThemeAction,
EditThemeAction,
FetchThemesAction,
SetThemeAction,
UpdateThemeAction,
} from './theme';
import {
AddQueryAction,
@ -54,6 +61,11 @@ import {
export type Action =
// Theme
| SetThemeAction
| FetchThemesAction
| AddThemeAction
| DeleteThemeAction
| UpdateThemeAction
| EditThemeAction
// Config
| GetConfigAction
| UpdateConfigAction

View file

@ -1,7 +1,32 @@
import { ActionType } from '../action-types';
import { Theme } from '../../interfaces';
import { Theme, ThemeColors } from '../../interfaces';
export interface SetThemeAction {
type: ActionType.setTheme;
payload: ThemeColors;
}
export interface FetchThemesAction {
type: ActionType.fetchThemes;
payload: Theme[];
}
export interface AddThemeAction {
type: ActionType.addTheme;
payload: Theme;
}
export interface DeleteThemeAction {
type: ActionType.deleteTheme;
payload: Theme[];
}
export interface UpdateThemeAction {
type: ActionType.updateTheme;
payload: Theme[];
}
export interface EditThemeAction {
type: ActionType.editTheme;
payload: Theme | null;
}

View file

@ -1,20 +1,30 @@
import { Action } from '../actions';
import { ActionType } from '../action-types';
import { Theme } from '../../interfaces/Theme';
import { arrayPartition, parsePABToTheme } from '../../utility';
interface ThemeState {
theme: Theme;
activeTheme: Theme;
themes: Theme[];
userThemes: Theme[];
themeInEdit: Theme | null;
}
const savedTheme = localStorage.theme
? parsePABToTheme(localStorage.theme)
: parsePABToTheme('#effbff;#6ee2ff;#242b33');
const initialState: ThemeState = {
theme: {
name: 'tron',
activeTheme: {
name: 'main',
isCustom: false,
colors: {
background: '#242B33',
primary: '#EFFBFF',
accent: '#6EE2FF',
...savedTheme,
},
},
themes: [],
userThemes: [],
themeInEdit: null,
};
export const themeReducer = (
@ -22,8 +32,56 @@ export const themeReducer = (
action: Action
): ThemeState => {
switch (action.type) {
case ActionType.setTheme:
return { theme: action.payload };
case ActionType.setTheme: {
return {
...state,
activeTheme: {
...state.activeTheme,
colors: action.payload,
},
};
}
case ActionType.fetchThemes: {
const [themes, userThemes] = arrayPartition<Theme>(
action.payload,
(e) => !e.isCustom
);
return {
...state,
themes,
userThemes,
};
}
case ActionType.addTheme: {
return {
...state,
userThemes: [...state.userThemes, action.payload],
};
}
case ActionType.deleteTheme: {
return {
...state,
userThemes: action.payload,
};
}
case ActionType.editTheme: {
return {
...state,
themeInEdit: action.payload,
};
}
case ActionType.updateTheme: {
return {
...state,
userThemes: action.payload,
};
}
default:
return state;

View file

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

View file

@ -0,0 +1,11 @@
export const arrayPartition = <T>(
arr: T[],
isValid: (e: T) => boolean
): T[][] => {
let pass: T[] = [];
let fail: T[] = [];
arr.forEach((e) => (isValid(e) ? pass : fail).push(e));
return [pass, fail];
};

View file

@ -12,3 +12,5 @@ export * from './parseTime';
export * from './decodeToken';
export * from './applyAuth';
export * from './escapeRegex';
export * from './parseTheme';
export * from './arrayPartition';

View file

@ -0,0 +1,20 @@
import { ThemeColors } from '../interfaces';
// parse theme in PAB (primary;accent;background) format to theme colors object
export const parsePABToTheme = (themeStr: string): ThemeColors => {
const [primary, accent, background] = themeStr.split(';');
return {
primary,
accent,
background,
};
};
export const parseThemeToPAB = ({
primary: p,
accent: a,
background: b,
}: ThemeColors): string => {
return `${p};${a};${b}`;
};

View file

@ -4,7 +4,7 @@ export const redirectUrl = (url: string, sameTab: boolean) => {
const parsedUrl = urlParser(url)[1];
if (sameTab) {
document.location.replace(parsedUrl);
document.location.assign(parsedUrl);
} else {
window.open(parsedUrl);
}

View file

@ -1,19 +1,27 @@
import { queries } from './searchQueries.json';
import { Query, SearchResult } from '../interfaces';
import searchQueries from './searchQueries.json';
import { SearchResult } from '../interfaces';
import { store } from '../store/store';
import { isUrlOrIp } from '.';
export const searchParser = (searchQuery: string): SearchResult => {
const queries = searchQueries.queries;
const result: SearchResult = {
isLocal: false,
isURL: false,
sameTab: false,
search: '',
query: {
encodedURL: '',
primarySearch: {
name: '',
prefix: '',
template: '',
},
secondarySearch: {
name: '',
prefix: '',
template: '',
},
rawQuery: searchQuery,
};
const { customQueries, config } = store.getState().config;
@ -24,25 +32,35 @@ export const searchParser = (searchQuery: string): SearchResult => {
// Match prefix and query
const splitQuery = searchQuery.match(/^\/([a-z]+)[ ](.+)$/i);
// Extract prefix
const prefix = splitQuery ? splitQuery[1] : config.defaultSearchProvider;
const search = splitQuery
// Encode url
const encodedURL = splitQuery
? encodeURIComponent(splitQuery[2])
: encodeURIComponent(searchQuery);
const query = [...queries, ...customQueries].find(
(q: Query) => q.prefix === prefix
);
// Find primary search engine template
const findProvider = (prefix: string) => {
return [...queries, ...customQueries].find((q) => q.prefix === prefix);
};
// If search provider was found
if (query) {
result.query = query;
result.search = search;
const primarySearch = findProvider(prefix);
const secondarySearch = findProvider(config.secondarySearchProvider);
// If search providers were found
if (primarySearch) {
result.primarySearch = primarySearch;
result.encodedURL = encodedURL;
if (prefix === 'l') {
result.isLocal = true;
} else {
result.sameTab = config.searchSameTab;
}
result.sameTab = config.searchSameTab;
if (secondarySearch) {
result.secondarySearch = secondarySearch;
}
return result;

View file

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

View file

@ -17,6 +17,7 @@ export const configTemplate: Config = {
hideCategories: false,
hideSearch: false,
defaultSearchProvider: 'l',
secondarySearchProvider: 'd',
dockerApps: false,
dockerHost: 'localhost',
kubernetesApps: false,

View file

@ -1,21 +1,16 @@
import {
DockerSettingsForm,
OtherSettingsForm,
SearchForm,
UISettingsForm,
GeneralForm,
ThemeSettingsForm,
WeatherForm,
} from '../../interfaces';
export const otherSettingsTemplate: OtherSettingsForm = {
export const uiSettingsTemplate: UISettingsForm = {
customTitle: document.title,
pinAppsByDefault: true,
pinCategoriesByDefault: true,
hideHeader: false,
hideApps: false,
hideCategories: false,
useOrdering: 'createdAt',
appsSameTab: false,
bookmarksSameTab: false,
useAmericanDate: false,
greetingsSchema: 'Good evening!;Good afternoon!;Good morning!;Good night!',
daySchema: 'Sunday;Monday;Tuesday;Wednesday;Thursday;Friday;Saturday',
@ -23,6 +18,8 @@ export const otherSettingsTemplate: OtherSettingsForm = {
'January;February;March;April;May;June;July;August;September;October;November;December',
showTime: false,
hideDate: false,
hideSearch: false,
disableAutofocus: false,
};
export const weatherSettingsTemplate: WeatherForm = {
@ -33,11 +30,15 @@ export const weatherSettingsTemplate: WeatherForm = {
weatherData: 'cloud',
};
export const searchSettingsTemplate: SearchForm = {
hideSearch: false,
export const generalSettingsTemplate: GeneralForm = {
searchSameTab: false,
defaultSearchProvider: 'l',
disableAutofocus: false,
secondarySearchProvider: 'd',
pinAppsByDefault: true,
pinCategoriesByDefault: true,
useOrdering: 'createdAt',
appsSameTab: false,
bookmarksSameTab: false,
};
export const dockerSettingsTemplate: DockerSettingsForm = {

View file

@ -1,4 +1,5 @@
const asyncWrapper = require('../../middleware/asyncWrapper');
const ErrorResponse = require('../../utils/ErrorResponse');
const File = require('../../utils/File');
// @desc Add custom search query
@ -8,6 +9,12 @@ const addQuery = asyncWrapper(async (req, res, next) => {
const file = new File('data/customQueries.json');
let content = JSON.parse(file.read());
const prefixes = content.queries.map((q) => q.prefix);
if (prefixes.includes(req.body.prefix)) {
return next(new ErrorResponse('Prefix must be unique', 400));
}
// Add new query
content.queries.push(req.body);
file.write(content, true);

View file

@ -0,0 +1,28 @@
const asyncWrapper = require('../../middleware/asyncWrapper');
const ErrorResponse = require('../../utils/ErrorResponse');
const File = require('../../utils/File');
// @desc Create new theme
// @route POST /api/themes
// @access Private
const addTheme = asyncWrapper(async (req, res, next) => {
const file = new File('data/themes.json');
let content = JSON.parse(file.read());
const themeNames = content.themes.map((t) => t.name);
if (themeNames.includes(req.body.name)) {
return next(new ErrorResponse('Name must be unique', 400));
}
// Add new theme
content.themes.push(req.body);
file.write(content, true);
res.status(201).json({
success: true,
data: req.body,
});
});
module.exports = addTheme;

View file

@ -0,0 +1,22 @@
const asyncWrapper = require('../../middleware/asyncWrapper');
const File = require('../../utils/File');
// @desc Delete theme
// @route DELETE /api/themes/:name
// @access Public
const deleteTheme = asyncWrapper(async (req, res, next) => {
const file = new File('data/themes.json');
let content = JSON.parse(file.read());
content.themes = content.themes.filter((t) => t.name != req.params.name);
file.write(content, true);
const userThemes = content.themes.filter((t) => t.isCustom);
res.status(200).json({
success: true,
data: userThemes,
});
});
module.exports = deleteTheme;

View file

@ -0,0 +1,17 @@
const asyncWrapper = require('../../middleware/asyncWrapper');
const File = require('../../utils/File');
// @desc Get themes file
// @route GET /api/themes
// @access Public
const getThemes = asyncWrapper(async (req, res, next) => {
const file = new File('data/themes.json');
const content = JSON.parse(file.read());
res.status(200).json({
success: true,
data: content.themes,
});
});
module.exports = getThemes;

View file

@ -0,0 +1,6 @@
module.exports = {
getThemes: require('./getThemes'),
addTheme: require('./addTheme'),
deleteTheme: require('./deleteTheme'),
updateTheme: require('./updateTheme'),
};

View file

@ -0,0 +1,32 @@
const asyncWrapper = require('../../middleware/asyncWrapper');
const File = require('../../utils/File');
// @desc Update theme
// @route PUT /api/themes/:name
// @access Public
const updateTheme = asyncWrapper(async (req, res, next) => {
const file = new File('data/themes.json');
let content = JSON.parse(file.read());
let themeIdx = content.themes.findIndex((t) => t.name == req.params.name);
// theme found
if (themeIdx > -1) {
content.themes = [
...content.themes.slice(0, themeIdx),
req.body,
...content.themes.slice(themeIdx + 1),
];
}
file.write(content, true);
const userThemes = content.themes.filter((t) => t.isCustom);
res.status(200).json({
success: true,
data: userThemes,
});
});
module.exports = updateTheme;

View file

@ -0,0 +1,19 @@
const { DataTypes } = require('sequelize');
const { STRING } = DataTypes;
const up = async (query) => {
await query.addColumn('apps', 'description', {
type: STRING,
allowNull: false,
defaultValue: '',
});
};
const down = async (query) => {
await query.removeColumn('apps', 'description');
};
module.exports = {
up,
down,
};

View file

@ -1,5 +1,4 @@
const ErrorResponse = require('../utils/ErrorResponse');
const colors = require('colors');
const Logger = require('../utils/Logger');
const logger = new Logger();

View file

@ -31,6 +31,11 @@ const App = sequelize.define(
allowNull: true,
defaultValue: 1,
},
description: {
type: DataTypes.STRING,
allowNull: false,
defaultValue: '',
},
},
{
tableName: 'apps',

5047
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -20,8 +20,8 @@
"@kubernetes/client-node": "^0.15.1",
"@types/express": "^4.17.13",
"axios": "^0.24.0",
"colors": "^1.4.0",
"concurrently": "^6.3.0",
"docker-secret": "^1.2.4",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"jsonwebtoken": "^8.5.1",

View file

@ -2,7 +2,7 @@ const express = require('express');
const router = express.Router();
// middleware
const { auth, requireAuth } = require('../middleware');
const { auth, requireAuth, requireBody } = require('../middleware');
const {
getQueries,
@ -11,7 +11,16 @@ const {
updateQuery,
} = require('../controllers/queries/');
router.route('/').post(auth, requireAuth, addQuery).get(getQueries);
router
.route('/')
.post(
auth,
requireAuth,
requireBody(['name', 'prefix', 'template']),
addQuery
)
.get(getQueries);
router
.route('/:prefix')
.delete(auth, requireAuth, deleteQuery)

29
routes/themes.js Normal file
View file

@ -0,0 +1,29 @@
const express = require('express');
const router = express.Router();
// middleware
const { auth, requireAuth, requireBody } = require('../middleware');
const {
getThemes,
addTheme,
deleteTheme,
updateTheme,
} = require('../controllers/themes/');
router
.route('/')
.get(getThemes)
.post(
auth,
requireAuth,
requireBody(['name', 'colors', 'isCustom']),
addTheme
);
router
.route('/:name')
.delete(auth, requireAuth, deleteTheme)
.put(auth, requireAuth, updateTheme);
module.exports = router;

View file

@ -23,6 +23,7 @@ const logger = new Logger();
await initApp();
await connectDB();
await associateModels();
await jobs();
// Create server for Express API and WebSockets
const server = http.createServer();

View file

@ -1,6 +1,6 @@
class Logger {
log(message, level = 'INFO') {
console.log(`[${this.generateTimestamp()}] [${level}] ${message}`)
console.log(`[${this.generateTimestamp()}] [${level}] ${message}`);
}
generateTimestamp() {
@ -20,7 +20,9 @@ class Logger {
// Timezone
const tz = -d.getTimezoneOffset() / 60;
return `${year}-${month}-${day} ${hour}:${minutes}:${seconds}.${miliseconds} UTC${tz >= 0 ? '+' + tz : tz}`;
return `${year}-${month}-${day} ${hour}:${minutes}:${seconds}.${miliseconds} UTC${
tz >= 0 ? '+' + tz : tz
}`;
}
parseDate(date, ms = false) {
@ -36,4 +38,4 @@ class Logger {
}
}
module.exports = Logger;
module.exports = Logger;

View file

@ -1,9 +1,13 @@
const initConfig = require('./initConfig');
const initFiles = require('./initFiles');
const initDockerSecrets = require('./initDockerSecrets');
const normalizeTheme = require('./normalizeTheme');
const initApp = async () => {
initDockerSecrets();
await initFiles();
await initConfig();
await normalizeTheme();
};
module.exports = initApp;

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