From 9a1ec76ffd0a8b15fba53cae2d9f9d69ca5dc207 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 15 Jun 2021 12:36:23 +0200 Subject: [PATCH] Case-insensitive sorting. App version checking --- ._env | 0 .env | 2 ++ .gitignore | 3 +-- client/.env | 1 + client/src/App.tsx | 8 ++++++ .../Settings/AppDetails/AppDetails.module.css | 8 ++++++ .../Settings/AppDetails/AppDetails.tsx | 25 +++++++++++++++++ client/src/components/Settings/Settings.tsx | 14 ++++++++-- .../UI/Buttons/Button/Button.module.css | 3 +-- .../components/UI/Buttons/Button/Button.tsx | 12 ++++++++- client/src/utility/checkVersion.ts | 27 +++++++++++++++++++ client/src/utility/index.ts | 3 ++- controllers/apps.js | 3 ++- controllers/bookmark.js | 3 ++- controllers/category.js | 3 ++- 15 files changed, 104 insertions(+), 11 deletions(-) delete mode 100644 ._env create mode 100644 .env create mode 100644 client/.env create mode 100644 client/src/components/Settings/AppDetails/AppDetails.module.css create mode 100644 client/src/components/Settings/AppDetails/AppDetails.tsx create mode 100644 client/src/utility/checkVersion.ts diff --git a/._env b/._env deleted file mode 100644 index e69de29..0000000 diff --git a/.env b/.env new file mode 100644 index 0000000..f1644a5 --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +PORT=5005 +NODE_ENV=development \ No newline at end of file diff --git a/.gitignore b/.gitignore index 477ae0c..ff227fe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ node_modules/ -data/ -.env \ No newline at end of file +data/ \ No newline at end of file diff --git a/client/.env b/client/.env new file mode 100644 index 0000000..a96328e --- /dev/null +++ b/client/.env @@ -0,0 +1 @@ +REACT_APP_VERSION=1.3.2 \ No newline at end of file diff --git a/client/src/App.tsx b/client/src/App.tsx index 7210f3d..157206e 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -5,6 +5,10 @@ import { getConfig, setTheme } from './store/actions'; import { store } from './store/store'; import { Provider } from 'react-redux'; +// Utils +import { checkVersion } from './utility'; + +// Routes import Home from './components/Home/Home'; import Apps from './components/Apps/Apps'; import Settings from './components/Settings/Settings'; @@ -14,10 +18,14 @@ import NotificationCenter from './components/NotificationCenter/NotificationCent // Get config pairs from database store.dispatch(getConfig()); +// Set theme if (localStorage.theme) { store.dispatch(setTheme(localStorage.theme)); } +// Check for updates +checkVersion(); + const App = (): JSX.Element => { return ( diff --git a/client/src/components/Settings/AppDetails/AppDetails.module.css b/client/src/components/Settings/AppDetails/AppDetails.module.css new file mode 100644 index 0000000..8f5fae3 --- /dev/null +++ b/client/src/components/Settings/AppDetails/AppDetails.module.css @@ -0,0 +1,8 @@ +.AppVersion { + color: var(--color-primary); + margin-bottom: 15px; +} + +.AppVersion a { + color: var(--color-accent); +} \ No newline at end of file diff --git a/client/src/components/Settings/AppDetails/AppDetails.tsx b/client/src/components/Settings/AppDetails/AppDetails.tsx new file mode 100644 index 0000000..90fe2fb --- /dev/null +++ b/client/src/components/Settings/AppDetails/AppDetails.tsx @@ -0,0 +1,25 @@ +import { Fragment } from 'react'; + +import classes from './AppDetails.module.css'; +import Button from '../../UI/Buttons/Button/Button'; +import { checkVersion } from '../../../utility'; + +const AppDetails = (): JSX.Element => { + return ( + +

+ + Flame + + {' '} + version {process.env.REACT_APP_VERSION} +

+ +
+ ) +} + +export default AppDetails; \ No newline at end of file diff --git a/client/src/components/Settings/Settings.tsx b/client/src/components/Settings/Settings.tsx index 0abea20..49b08bd 100644 --- a/client/src/components/Settings/Settings.tsx +++ b/client/src/components/Settings/Settings.tsx @@ -1,12 +1,14 @@ -import { NavLink, Link, Switch, Route, withRouter } from 'react-router-dom'; +import { NavLink, Link, Switch, Route } from 'react-router-dom'; import classes from './Settings.module.css'; import { Container } from '../UI/Layout/Layout'; import Headline from '../UI/Headlines/Headline/Headline'; + import Themer from '../Themer/Themer'; import WeatherSettings from './WeatherSettings/WeatherSettings'; import OtherSettings from './OtherSettings/OtherSettings'; +import AppDetails from './AppDetails/AppDetails'; const Settings = (): JSX.Element => { return ( @@ -38,12 +40,20 @@ const Settings = (): JSX.Element => { to='/settings/other'> Other + + App +
+
@@ -51,4 +61,4 @@ const Settings = (): JSX.Element => { ) } -export default withRouter(Settings); \ No newline at end of file +export default Settings; \ No newline at end of file diff --git a/client/src/components/UI/Buttons/Button/Button.module.css b/client/src/components/UI/Buttons/Button/Button.module.css index b9874e1..238850b 100644 --- a/client/src/components/UI/Buttons/Button/Button.module.css +++ b/client/src/components/UI/Buttons/Button/Button.module.css @@ -6,8 +6,7 @@ border-radius: 4px; } -.Button:hover, -.Button:focus { +.Button:hover { cursor: pointer; background-color: var(--color-accent); color: var(--color-background); diff --git a/client/src/components/UI/Buttons/Button/Button.tsx b/client/src/components/UI/Buttons/Button/Button.tsx index 321e993..5f113d8 100644 --- a/client/src/components/UI/Buttons/Button/Button.tsx +++ b/client/src/components/UI/Buttons/Button/Button.tsx @@ -2,10 +2,20 @@ import classes from './Button.module.css'; interface ComponentProps { children: string; + click?: any; } const Button = (props: ComponentProps): JSX.Element => { - return + const { + children, + click + } = props; + + return ( + + ) } export default Button; \ No newline at end of file diff --git a/client/src/utility/checkVersion.ts b/client/src/utility/checkVersion.ts new file mode 100644 index 0000000..e1a0508 --- /dev/null +++ b/client/src/utility/checkVersion.ts @@ -0,0 +1,27 @@ +import axios from 'axios'; +import { store } from '../store/store'; +import { createNotification } from '../store/actions'; + +export const checkVersion = async (isForced: boolean = false) => { + try { + const res = await axios.get('https://raw.githubusercontent.com/pawelmalak/flame/master/client/.env'); + + const githubVersion = res.data + .split('\n') + .map(pair => pair.split('='))[0][1]; + + if (githubVersion !== process.env.REACT_APP_VERSION) { + store.dispatch(createNotification({ + title: 'Info', + message: 'New version is available!' + })) + } else if (isForced) { + store.dispatch(createNotification({ + title: 'Info', + message: 'You are using the latest version!' + })) + } + } catch (err) { + console.log(err); + } +} \ No newline at end of file diff --git a/client/src/utility/index.ts b/client/src/utility/index.ts index 6caa71e..1422624 100644 --- a/client/src/utility/index.ts +++ b/client/src/utility/index.ts @@ -1,3 +1,4 @@ export * from './iconParser'; export * from './urlParser'; -export * from './searchConfig'; \ No newline at end of file +export * from './searchConfig'; +export * from './checkVersion'; \ No newline at end of file diff --git a/controllers/apps.js b/controllers/apps.js index 4f21394..6ca83d2 100644 --- a/controllers/apps.js +++ b/controllers/apps.js @@ -2,6 +2,7 @@ const asyncWrapper = require('../middleware/asyncWrapper'); const ErrorResponse = require('../utils/ErrorResponse'); const App = require('../models/App'); const Config = require('../models/Config'); +const { Sequelize } = require('sequelize'); // @desc Create new app // @route POST /api/apps @@ -36,7 +37,7 @@ exports.createApp = asyncWrapper(async (req, res, next) => { // @access Public exports.getApps = asyncWrapper(async (req, res, next) => { const apps = await App.findAll({ - order: [['name', 'ASC']] + order: [[ Sequelize.fn('lower', Sequelize.col('name')), 'ASC' ]] }); res.status(200).json({ diff --git a/controllers/bookmark.js b/controllers/bookmark.js index 7baa664..08b2fca 100644 --- a/controllers/bookmark.js +++ b/controllers/bookmark.js @@ -1,6 +1,7 @@ const asyncWrapper = require('../middleware/asyncWrapper'); const ErrorResponse = require('../utils/ErrorResponse'); const Bookmark = require('../models/Bookmark'); +const { Sequelize } = require('sequelize'); // @desc Create new bookmark // @route POST /api/bookmarks @@ -19,7 +20,7 @@ exports.createBookmark = asyncWrapper(async (req, res, next) => { // @access Public exports.getBookmarks = asyncWrapper(async (req, res, next) => { const bookmarks = await Bookmark.findAll({ - order: [['name', 'ASC']] + order: [[ Sequelize.fn('lower', Sequelize.col('name')), 'ASC' ]] }); res.status(200).json({ diff --git a/controllers/category.js b/controllers/category.js index a390405..29d03b4 100644 --- a/controllers/category.js +++ b/controllers/category.js @@ -3,6 +3,7 @@ const ErrorResponse = require('../utils/ErrorResponse'); const Category = require('../models/Category'); const Bookmark = require('../models/Bookmark'); const Config = require('../models/Config'); +const { Sequelize } = require('sequelize') // @desc Create new category // @route POST /api/categories @@ -41,7 +42,7 @@ exports.getCategories = asyncWrapper(async (req, res, next) => { model: Bookmark, as: 'bookmarks' }], - order: [['name', 'ASC']] + order: [[ Sequelize.fn('lower', Sequelize.col('Category.name')), 'ASC' ]] }); res.status(200).json({