Skip to content

Commit

Permalink
Add dark mode switch (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
Germey authored Apr 6, 2024
1 parent 97d36d2 commit de242c8
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "add dark mode switch",
"packageName": "@acedatacloud/hub",
"email": "[email protected]",
"dependentChangeType": "patch"
}
47 changes: 29 additions & 18 deletions src/components/common/DarkSelector.vue
Original file line number Diff line number Diff line change
@@ -1,41 +1,52 @@
<template>
<dark-switch class="switch" dark-background="#333" light-background="#fff" />
<el-button :class="{ active: !!dark }" @click="setDark(!dark)">
<font-awesome-icon v-if="dark" icon="fa-solid fa-moon" />
<font-awesome-icon v-else icon="fa-solid fa-moon" />
</el-button>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import { Switch as DarkSwitch, toggleDark, isDark } from 'vue-dark-switch';
import { toggleDark } from 'vue-dark-switch';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import { ElButton } from 'element-plus';
export default defineComponent({
components: {
DarkSwitch
FontAwesomeIcon,
ElButton
},
emits: ['update:dark'],
computed: {
dark() {
return this.$store.getters.dark;
},
switchValue() {
return isDark.value;
}
// switchValue() {
// return isDark.value;
// }
},
watch: {
switchValue(val) {
console.log('switchValue', val);
this.$store.dispatch('setDark', val);
},
dark(val) {
document.documentElement.classList.toggle('dark', val);
this.$store.dispatch('setDark', this.dark);
this.setDark(val);
}
// switchValue(val) {
// console.log('switchValue', val);
// // this.$store.dispatch('setDark', val);
// }
},
mounted() {
if (this.dark) {
toggleDark(true);
document.documentElement.classList.add('dark');
} else {
toggleDark(false);
document.documentElement.classList.remove('dark');
console.log('mounted', this.dark);
this.setDark(this.dark);
},
methods: {
setDark(flag: boolean) {
toggleDark(flag);
this.$store.dispatch('setDark', flag);
if (flag === true) {
document.documentElement.classList.add('dark');
} else if (flag === false) {
document.documentElement.classList.remove('dark');
}
}
}
});
Expand Down
10 changes: 7 additions & 3 deletions src/components/common/Navigator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<div class="top">
<div v-if="!collapsed">
<logo @click="onHome" />
<dark-selector v-show="false" />
</div>
<el-menu v-if="!collapsed" :default-active="activeIndex">
<el-menu-item
Expand Down Expand Up @@ -47,6 +46,11 @@
</el-menu>
</div>
<div v-else class="bottom">
<div v-if="$config.navigation?.darkMode" class="link">
<el-tooltip effect="dark" :content="$t('common.nav.darkMode')" placement="right">
<dark-selector class="button" />
</el-tooltip>
</div>
<div v-if="$config.navigation?.locale" class="link">
<el-tooltip effect="dark" :content="$t('common.nav.locale')" placement="right">
<el-button class="button">
Expand Down Expand Up @@ -84,6 +88,7 @@ import { defineComponent } from 'vue';
import { ElButton, ElTooltip, ElMenu, ElMenuItem } from 'element-plus';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import LocaleSelector from './LocaleSelector.vue';
import DarkSelector from './DarkSelector.vue';
import {
ROUTE_CHATDOC_INDEX,
ROUTE_CHATDOC_CONVERSATION,
Expand All @@ -98,7 +103,6 @@ import {
ROUTE_MIDJOURNEY_INDEX
} from '@/router/constants';
import Chevron from './Chevron.vue';
import DarkSelector from './DarkSelector.vue';
import Logo from './Logo.vue';
export default defineComponent({
Expand Down Expand Up @@ -262,7 +266,7 @@ export default defineComponent({
border-radius: 10px;
border: none;
color: var(--el-text-color-primary);
background-color: var(--el-bg-color-overlay);
background-color: var(--el-bg-color-page);
&.active,
&:hover,
&:focus {
Expand Down
9 changes: 4 additions & 5 deletions src/components/midjourney/tasks/TaskPreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
<div class="extra">
<p v-if="modelValue?.created_at" class="datetime">
<font-awesome-icon icon="fa-regular fa-clock" class="mr-1" />
{{ $dayjs.format(new Date(parseFloat(modelValue?.created_at) * 1000)) }}
{{ $dayjs.format('' + new Date(parseFloat(modelValue?.created_at) * 1000)) }}
</p>
</div>
</div>
Expand Down Expand Up @@ -337,8 +337,7 @@ export default defineComponent({
width: 100%;
height: 100%;
background: var(--el-fill-color-light);
color: var(--el-text-color-secondary);
// font-size: 30px;
color: var(--el-text-color-regular);
}
}
.progress {
Expand All @@ -362,7 +361,7 @@ export default defineComponent({
flex-wrap: wrap;
overflow: hidden;
text-align: center;
color: #666;
color: var(--el-text-color-regular);
font-size: 14px;
overflow-y: scroll;
Expand All @@ -380,7 +379,7 @@ export default defineComponent({
.datetime,
.prompt {
font-size: 12px;
color: #666;
color: var(--el-text-color-regular);
margin-bottom: 5px;
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ export default {
*/
locale: true,

/**
* Show dark entry in left navigation.
*/
darkMode: true,

/**
* Show console entry in left navigation.
*/
Expand Down
10 changes: 7 additions & 3 deletions src/i18n/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,15 @@
},
"nav.chat": {
"message": "Chat",
"description": "The text in nav bar of the website, which is used to show the chat page"
"description": "The text in nav bar of the website, which is used to show the chat page, please do not translate 'Chat', keep it as 'Chat'"
},
"nav.midjourney": {
"message": "Midjourney",
"description": "The text in nav bar of the website, which is used to show the midjourney page, please do not translate 'Midjourney', keep it as 'Midjourney'"
},
"nav.chatdoc": {
"message": "Chatdoc",
"description": "The text in nav bar of the website, which is used to show the chatdoc page"
"description": "The text in nav bar of the website, which is used to show the chatdoc page, please do not translate 'Chatdoc', keep it as 'Chatdoc'"
},
"nav.distribution": {
"message": "Referral Earnings",
Expand All @@ -263,6 +263,10 @@
"message": "Language",
"description": "The text in nav bar of the website, which is used to change the language"
},
"nav.darkMode": {
"message": "Dark Mode",
"description": "The text in nav bar of the website, which is used to change the theme to dark mode"
},
"title.alert": {
"message": "Alert",
"description": "The title of the alert message"
Expand Down Expand Up @@ -311,4 +315,4 @@
"message": "Credentials",
"description": "The title of the page to show all credentials, the credentials are used to access the API"
}
}
}
6 changes: 3 additions & 3 deletions src/pages/distribution/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ export default defineComponent({
font-size: 20px;
font-weight: bold;
margin-bottom: 20px;
color: #333;
color: var(--el-text-color-primary);
}
.icon {
margin-right: 5px;
Expand All @@ -385,7 +385,7 @@ export default defineComponent({
padding: 15px 0;
p {
text-align: center;
color: #999;
color: var(--el-text-color-regular);
font-size: 12px;
}
}
Expand All @@ -402,7 +402,7 @@ export default defineComponent({
}
.description {
color: #999;
color: var(--el-text-color-regular);
font-size: 14px;
margin-bottom: 10px;
.more {
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/font-awesome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from '@fortawesome/free-regular-svg-icons';
import {
faChevronRight as faSolidChevronRight,
faMoon as faSolidMoon,
faChevronLeft as faSolidChevronLeft,
faFire as faSolidFire,
faBook as faSolidBook,
Expand Down Expand Up @@ -71,6 +72,7 @@ library.add(faSolidCheck);
library.add(faSolidLocationArrow);
library.add(faRegularUser);
library.add(faRegularSun);
library.add(faSolidMoon);
library.add(faSolidBolt);
library.add(faSolidBook);
library.add(faSolidGear);
Expand Down
2 changes: 1 addition & 1 deletion src/store/common/persist.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default ['user', 'token', 'setting', 'locale'];
export default ['user', 'token', 'setting', 'locale', 'dark'];

0 comments on commit de242c8

Please sign in to comment.