diff --git a/dev/dev-notes.md b/dev/dev-notes.md index 2c5d87f3a64e..121368e1194c 100644 --- a/dev/dev-notes.md +++ b/dev/dev-notes.md @@ -46,3 +46,5 @@ General - Improved documentation - Fixed hot-reloading development environment - [grssmnn](https://github.com/grssmnn) - Added Confirmation component to deleting recipes - [zackbcom](https://github.com/zackbcom) +- Added Persistent storage to vuex - [zackbcom](https://github.com/zackbcom) +- Updated Theme backend - [zackbcom](https://github.com/zackbcom) diff --git a/docs/docs/getting-started/site-settings.md b/docs/docs/getting-started/site-settings.md index c53f5ef2cd20..7dc6266cd7ca 100644 --- a/docs/docs/getting-started/site-settings.md +++ b/docs/docs/getting-started/site-settings.md @@ -4,12 +4,12 @@ ## Theme Settings -Color themes can be created and set from the UI in the settings page. You can select an existing color theme or create a new one. On creation of a new color theme random colors will first be generated, then you can select and save as you'd like. By default the "default" theme will be loaded for all new users visiting the site. All created color themes are available to all users of the site. Separate color themes can be set for both Light and Dark modes. +Color themes can be created and set from the UI in the settings page. You can select an existing color theme or create a new one. On creation of a new color theme, the default colors will be used, then you can select and save as you'd like. By default the "default" theme will be loaded for all new users visiting the site. All created color themes are available to all users of the site. Theme Colors will be set for both light and dark modes. ![](../gifs/theme-demo.gif) !!! note - Theme data is stored in cookies in the browser. Calling "Save Theme" will refresh the cookie with the selected theme as well save the theme to the database. + Theme data is stored in localstorage in the browser. Calling "Save colors and apply theme will refresh the localstorage with the selected theme as well save the theme to the database. diff --git a/frontend/package.json b/frontend/package.json index 17dfefb37958..ada4b56dc84a 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -13,11 +13,11 @@ "qs": "^6.9.4", "v-jsoneditor": "^1.4.2", "vue": "^2.6.11", - "vue-cookies": "^1.7.4", "vue-html-to-paper": "^1.3.1", "vue-router": "^3.4.9", "vuetify": "^2.4.1", - "vuex": "^3.6.0" + "vuex": "^3.6.0", + "vuex-persistedstate": "^4.0.0-beta.2" }, "devDependencies": { "@vue/cli-plugin-babel": "~4.5.0", diff --git a/frontend/src/App.vue b/frontend/src/App.vue index a5c69bd11082..533c394c7c67 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -2,7 +2,7 @@ - + mdi-silverware-variant @@ -37,6 +37,7 @@ import Menu from "./components/UI/Menu"; import SearchHeader from "./components/UI/SearchHeader"; import AddRecipe from "./components/AddRecipe"; import SnackBar from "./components/UI/SnackBar"; +import Vuetify from "./plugins/vuetify"; export default { name: "App", @@ -44,32 +45,53 @@ export default { Menu, AddRecipe, SearchHeader, - SnackBar, + SnackBar }, watch: { $route() { this.search = false; - }, + } }, mounted() { - this.$store.dispatch("initCookies"); + this.$store.dispatch("initTheme"); this.$store.dispatch("requestRecentRecipes"); + this.darkModeSystemCheck(); + this.darkModeAddEventListener(); }, data: () => ({ - search: false, + search: false }), methods: { + /** + * Checks if 'system' is set for dark mode and then sets the corrisponding value for vuetify + */ + darkModeSystemCheck() { + if (this.$store.getters.getDarkMode === "system") + Vuetify.framework.theme.dark = window.matchMedia( + "(prefers-color-scheme: dark)" + ).matches; + }, + /** + * This will monitor the OS level darkmode and call to update dark mode. + */ + darkModeAddEventListener() { + const darkMediaQuery = window.matchMedia("(prefers-color-scheme: dark)"); + darkMediaQuery.addEventListener("change", () => { + this.darkModeSystemCheck(); + }); + }, + toggleSearch() { if (this.search === true) { this.search = false; } else { this.search = true; } - }, - }, + } + } }; diff --git a/frontend/src/api/themes.js b/frontend/src/api/themes.js index 866848325643..04ae7eb75915 100644 --- a/frontend/src/api/themes.js +++ b/frontend/src/api/themes.js @@ -19,7 +19,6 @@ export default { async requestByName(name) { let response = await apiReq.get(settingsURLs.specificTheme(name)); - console.log(response); return response.data; }, diff --git a/frontend/src/components/Admin/Theme.vue b/frontend/src/components/Admin/Theme.vue index 392f58a9a31f..3699c5ed4c8e 100644 --- a/frontend/src/components/Admin/Theme.vue +++ b/frontend/src/components/Admin/Theme.vue @@ -1,69 +1,117 @@