mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2026-04-15 01:41:56 +00:00
use useStorage and same prefix
This commit is contained in:
@@ -163,7 +163,7 @@ const hasLogs = computed(
|
||||
// we do not have logs for skipped steps
|
||||
repo?.value && pipeline.value && step.value && step.value.state !== 'skipped',
|
||||
);
|
||||
const autoScroll = useStorage('log-auto-scroll', false);
|
||||
const autoScroll = useStorage('woodpecker:log-auto-scroll', false);
|
||||
const showActions = ref(false);
|
||||
const downloadInProgress = ref(false);
|
||||
const ansiUp = ref(new AnsiUp());
|
||||
|
||||
@@ -55,7 +55,7 @@ import type { Repo } from '~/lib/api/types';
|
||||
const apiClient = useApiClient();
|
||||
const repo = inject<Ref<Repo>>('repo');
|
||||
|
||||
const badgeType = useStorage('last-badge-type', 'markdown');
|
||||
const badgeType = useStorage('woodpecker:last-badge-type', 'markdown');
|
||||
|
||||
if (!repo) {
|
||||
throw new Error('Unexpected: "repo" should be provided at this place');
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { useLocalStorage } from '@vueuse/core';
|
||||
import { useStorage } from '@vueuse/core';
|
||||
import { SUPPORTED_LOCALES } from 'virtual:vue-i18n-supported-locales';
|
||||
import { computed } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
@@ -39,7 +39,7 @@ const localeOptions = computed(() =>
|
||||
})),
|
||||
);
|
||||
|
||||
const storedLocale = useLocalStorage('woodpecker:locale', locale.value);
|
||||
const storedLocale = useStorage('woodpecker:locale', locale.value);
|
||||
const selectedLocale = computed<string>({
|
||||
async set(_selectedLocale) {
|
||||
await setI18nLanguage(_selectedLocale);
|
||||
|
||||
28
web/src/compositions/useDarkMode.ts
Normal file
28
web/src/compositions/useDarkMode.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { useStorage } from '@vueuse/core';
|
||||
import { watch } from 'vue';
|
||||
|
||||
const isDarkModeActive = useStorage('woodpecker:dark-mode', window.matchMedia('(prefers-color-scheme: dark)').matches);
|
||||
|
||||
watch(
|
||||
isDarkModeActive,
|
||||
(isActive) => {
|
||||
if (isActive) {
|
||||
document.documentElement.classList.remove('light');
|
||||
document.documentElement.classList.add('dark');
|
||||
document.documentElement.setAttribute('data-theme', 'dark');
|
||||
document.querySelector('meta[name=theme-color]')?.setAttribute('content', '#2A2E3A'); // internal-wp-secondary-600 (see windi.config.ts)
|
||||
} else {
|
||||
document.documentElement.classList.remove('dark');
|
||||
document.documentElement.classList.add('light');
|
||||
document.documentElement.setAttribute('data-theme', 'light');
|
||||
document.querySelector('meta[name=theme-color]')?.setAttribute('content', '#369943'); // internal-wp-primary-400
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
export function useDarkMode() {
|
||||
return {
|
||||
darkMode: isDarkModeActive,
|
||||
};
|
||||
}
|
||||
@@ -1,32 +1,19 @@
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
const USER_CONFIG_KEY = 'woodpecker-user-config';
|
||||
import { useStorage } from '@vueuse/core';
|
||||
import { computed } from 'vue';
|
||||
|
||||
interface UserConfig {
|
||||
isPipelineFeedOpen: boolean;
|
||||
redirectUrl: string;
|
||||
}
|
||||
|
||||
const defaultUserConfig: UserConfig = {
|
||||
const config = useStorage<UserConfig>('woodpecker:user-config', {
|
||||
isPipelineFeedOpen: false,
|
||||
redirectUrl: '',
|
||||
};
|
||||
|
||||
function loadUserConfig(): UserConfig {
|
||||
const lsData = localStorage.getItem(USER_CONFIG_KEY);
|
||||
if (lsData === null) {
|
||||
return defaultUserConfig;
|
||||
}
|
||||
|
||||
return JSON.parse(lsData) as UserConfig;
|
||||
}
|
||||
|
||||
const config = ref<UserConfig>(loadUserConfig());
|
||||
});
|
||||
|
||||
export default () => ({
|
||||
setUserConfig<T extends keyof UserConfig>(key: T, value: UserConfig[T]): void {
|
||||
config.value = { ...config.value, [key]: value };
|
||||
localStorage.setItem(USER_CONFIG_KEY, JSON.stringify(config.value));
|
||||
},
|
||||
userConfig: computed(() => config.value),
|
||||
});
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { useLocalStorage } from '@vueuse/core';
|
||||
import { useStorage } from '@vueuse/core';
|
||||
|
||||
export function getUserLanguage(): string {
|
||||
const browserLocale = navigator.language.split('-')[0];
|
||||
const selectedLocale = useLocalStorage('woodpecker:locale', browserLocale).value;
|
||||
const selectedLocale = useStorage('woodpecker:locale', browserLocale).value;
|
||||
|
||||
return selectedLocale;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user