1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-08-03 20:45:23 +02:00

Added | System Dark mode. Streamlined themes

This commit is contained in:
zackbcom 2021-01-05 23:26:59 -06:00
parent de17085e04
commit b099da573c
3 changed files with 190 additions and 93 deletions

View file

@ -1,69 +1,114 @@
<template>
<v-card>
<v-card-title class="secondary white--text"> Theme Settings </v-card-title>
<v-card-text>
<h2 class="mt-4 mb-1">Dark Mode</h2>
<p>
Choose how Mealie looks to you. Set your theme preference to follow your
system settings, or choose to use the light or dark theme.
</p>
<v-row dense align="center">
<v-col cols="12">
<v-btn-toggle
v-model="darkMode"
color="primary "
mandatory
@change="setDarkMode"
>
<v-btn value="system">
Default to system
</v-btn>
<v-btn value="light">
Light
</v-btn>
<v-btn value="dark">
Dark
</v-btn>
</v-btn-toggle>
</v-col>
</v-row></v-card-text
>
<v-divider class=""></v-divider>
<v-card-text>
<h2 class="mt-1 mb-1">Theme</h2>
<p>
Select a theme from the dropdown or create a new theme. Note that the
default theme will be served to all users who have not set a theme
preference.
</p>
<v-row dense align="center">
<v-col cols="12" md="2" sm="5">
<v-switch
v-model="darkMode"
inset
label="Dark Mode"
class="my-n3"
@change="toggleDarkMode"
></v-switch>
</v-col>
<v-col cols="12" md="4" sm="3">
<v-form ref="form" lazy-validation>
<v-form ref="form" lazy-validation>
<v-row dense align="center">
<v-col cols="12" md="4" sm="3">
<v-select
label="Saved Color Schemes"
label="Saved Color Theme"
:items="availableThemes"
item-text="name"
item-value="colors"
return-object
v-model="selectedScheme"
v-model="activeTheme"
@change="themeSelected"
:rules="[(v) => !!v || 'Theme is required']"
:rules="[v => !!v || 'Theme is required']"
required
>
</v-select>
</v-form>
</v-col>
<v-col cols="12" sm="1">
<NewTheme @new-theme="appendTheme" />
</v-col>
<v-col cols="12" sm="1">
<v-btn text color="error" @click="deleteSelected"> Delete </v-btn>
</v-col>
</v-row>
<v-row dense align-content="center" v-if="activeTheme">
</v-col>
<v-col cols="12" sm="1">
<NewTheme @new-theme="appendTheme" />
</v-col>
<v-col cols="12" sm="1">
<v-btn text color="error" @click="deleteSelectedThemeValidation">
Delete
</v-btn>
<Confirmation
title="Delete Theme"
message="Are you sure you want to delete this theme?"
color="error"
icon="mdi-alert-circle"
ref="deleteThemeConfirm"
v-on:confirm="deleteSelectedTheme()"
/>
</v-col>
</v-row>
</v-form>
<v-row dense align-content="center" v-if="activeTheme.colors">
<v-col>
<ColorPicker button-text="Primary" v-model="activeTheme.primary" />
<ColorPicker
button-text="Primary"
v-model="activeTheme.colors.primary"
/>
</v-col>
<v-col>
<ColorPicker
button-text="Secondary"
v-model="activeTheme.secondary"
v-model="activeTheme.colors.secondary"
/>
</v-col>
<v-col>
<ColorPicker button-text="Accent" v-model="activeTheme.accent" />
<ColorPicker
button-text="Accent"
v-model="activeTheme.colors.accent"
/>
</v-col>
<v-col>
<ColorPicker button-text="Success" v-model="activeTheme.success" />
<ColorPicker
button-text="Success"
v-model="activeTheme.colors.success"
/>
</v-col>
<v-col>
<ColorPicker button-text="Info" v-model="activeTheme.info" />
<ColorPicker button-text="Info" v-model="activeTheme.colors.info" />
</v-col>
<v-col>
<ColorPicker button-text="Warning" v-model="activeTheme.warning" />
<ColorPicker
button-text="Warning"
v-model="activeTheme.colors.warning"
/>
</v-col>
<v-col>
<ColorPicker button-text="Error" v-model="activeTheme.error" />
<ColorPicker button-text="Error" v-model="activeTheme.colors.error" />
</v-col>
</v-row>
</v-card-text>
@ -84,73 +129,74 @@
import api from "../../api";
import ColorPicker from "./ThemeUI/ColorPicker";
import NewTheme from "./ThemeUI/NewTheme";
import Confirmation from "../UI/Confirmation";
export default {
components: {
ColorPicker,
NewTheme,
Confirmation,
NewTheme
},
data() {
return {
themes: null,
activeTheme: {},
darkMode: false,
availableThemes: [],
selectedScheme: "",
selectedLight: "",
darkMode: "system",
availableThemes: []
};
},
async mounted() {
this.availableThemes = await api.themes.requestAll();
this.activeTheme = this.$store.getters.getActiveTheme;
this.darkMode = this.$store.getters.getDarkMode;
this.themes = this.$store.getters.getThemes;
this.setThemeEditor();
},
methods: {
async deleteSelected() {
deleteSelectedThemeValidation() {
if (this.$refs.form.validate()) {
if (this.selectedScheme === "default") {
if (this.activeTheme.name === "default") {
// Notify User Can't Delete Default
} else if (this.selectedScheme !== "") {
api.themes.delete(this.selectedScheme.name);
} else if (this.activeTheme !== {}) {
this.$refs.deleteThemeConfirm.open();
}
this.availableThemes = await api.themes.requestAll();
}
},
async deleteSelectedTheme() {
api.themes.delete(this.activeTheme.name);
this.availableThemes = await api.themes.requestAll();
//Change to default if deleting current theme.
if (
!this.availableThemes.some(
theme => theme.name === this.activeTheme.name
)
) {
this.$store.commit("setActiveTheme", null);
this.activeTheme = this.$store.getters.getActiveTheme;
}
},
async appendTheme(newTheme) {
api.themes.create(newTheme);
this.availableThemes.push(newTheme);
this.activeTheme = newTheme;
},
themeSelected() {
this.activeTheme = this.selectedScheme.colors;
console.log("this.activeTheme", this.activeTheme);
},
setThemeEditor() {
if (this.darkMode) {
this.activeTheme = this.themes.dark;
} else {
this.activeTheme = this.themes.light;
}
},
toggleDarkMode() {
this.$store.commit("setDarkMode", this.darkMode);
this.selectedScheme = "";
this.setThemeEditor();
setDarkMode() {
this.$store.commit("setDarkMode", this.darkMode);
},
saveThemes() {
/**
* This will save the current colors and make the selected theme live.
*/
async saveThemes() {
if (this.$refs.form.validate()) {
if (this.darkMode) {
this.themes.dark = this.activeTheme;
} else {
this.themes.light = this.activeTheme;
}
this.$store.commit("setThemes", this.themes);
this.$store.commit("setActiveTheme", this.activeTheme);
this.$store.dispatch("initCookies");
api.themes.update(this.selectedScheme.name, this.activeTheme);
api.themes.update(this.activeTheme.name, this.activeTheme);
} else;
},
},
}
}
};
</script>