Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: |UI| add configAutoRefreshInterval && autoRefresh useStorage #549

Merged
merged 3 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions frontend/src/components/MailBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@ const props = defineProps({
})

const {
isDark, mailboxSplitSize, indexTab, loading, useUTCDate,
isDark, mailboxSplitSize, indexTab, loading, useUTCDate, autoRefresh, configAutoRefreshInterval,
useIframeShowMail, sendMailModel, preferShowTextMail
} = useGlobalState()
const autoRefresh = ref(false)
const autoRefreshInterval = ref(30)
const autoRefreshInterval = ref(configAutoRefreshInterval.value)
const data = ref([])
const timer = ref(null)

Expand Down Expand Up @@ -119,14 +118,16 @@ const { t } = useI18n({
});

const setupAutoRefresh = async (autoRefresh) => {
// auto refresh every 30 seconds
autoRefreshInterval.value = 30;
// auto refresh every configAutoRefreshInterval seconds
autoRefreshInterval.value = configAutoRefreshInterval.value;
if (autoRefresh) {
clearInterval(timer.value);
timer.value = setInterval(async () => {
if (loading.value) return;
autoRefreshInterval.value--;
if (autoRefreshInterval.value <= 0) {
autoRefreshInterval.value = 30;
await refresh();
autoRefreshInterval.value = configAutoRefreshInterval.value;
await backFirstPageAndRefresh();
}
}, 1000)
} else {
Expand All @@ -137,7 +138,7 @@ const setupAutoRefresh = async (autoRefresh) => {

watch(autoRefresh, async (autoRefresh, old) => {
setupAutoRefresh(autoRefresh)
})
}, { immediate: true })

watch([page, pageSize], async ([page, pageSize], [oldPage, oldPageSize]) => {
if (page !== oldPage || pageSize !== oldPageSize) {
Expand Down Expand Up @@ -170,6 +171,11 @@ const refresh = async () => {
}
};

const backFirstPageAndRefresh = async () =>{
page.value = 1;
await refresh();
}

const clickRow = async (row) => {
if (multiActionMode.value) {
row.checked = !row.checked;
Expand Down Expand Up @@ -366,7 +372,7 @@ onBeforeUnmount(() => {
{{ t('autoRefresh') }}
</template>
</n-switch>
<n-button @click="refresh" type="primary" tertiary>
<n-button @click="backFirstPageAndRefresh" type="primary" tertiary>
{{ t('refresh') }}
</n-button>
</n-space>
Expand Down Expand Up @@ -476,7 +482,7 @@ onBeforeUnmount(() => {
{{ t('autoRefresh') }}
</template>
</n-switch>
<n-button @click="refresh" tertiary size="small" type="primary">
<n-button @click="backFirstPageAndRefresh" tertiary size="small" type="primary">
{{ t('refresh') }}
</n-button>
</n-space>
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ export const useGlobalState = createGlobalState(
const globalTabplacement = useStorage('globalTabplacement', 'top');
const useSideMargin = useStorage('useSideMargin', true);
const useUTCDate = useStorage('useUTCDate', false);
const autoRefresh = useStorage('autoRefresh', false);
const configAutoRefreshInterval = useStorage("configAutoRefreshInterval", 60);
const userOpenSettings = ref({
fetched: false,
enable: false,
Expand Down Expand Up @@ -130,6 +132,8 @@ export const useGlobalState = createGlobalState(
globalTabplacement,
useSideMargin,
useUTCDate,
autoRefresh,
configAutoRefreshInterval,
telegramApp,
isTelegram,
showAdminPage,
Expand Down
9 changes: 8 additions & 1 deletion frontend/src/views/common/Appearance.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useIsMobile } from '../../utils/composables'
import { useGlobalState } from '../../store'

const {
mailboxSplitSize, useIframeShowMail, preferShowTextMail,
mailboxSplitSize, useIframeShowMail, preferShowTextMail, configAutoRefreshInterval,
globalTabplacement, useSideMargin, useUTCDate
} = useGlobalState()
const isMobile = useIsMobile()
Expand All @@ -23,6 +23,7 @@ const { t } = useI18n({
right: 'right',
bottom: 'bottom',
useUTCDate: 'Use UTC Date',
autoRefreshInterval: 'Auto Refresh Interval(Sec)',
},
zh: {
mailboxSplitSize: '邮箱界面分栏大小',
Expand All @@ -35,6 +36,7 @@ const { t } = useI18n({
right: '右侧',
bottom: '底部',
useUTCDate: '使用 UTC 时间',
autoRefreshInterval: '自动刷新间隔(秒)',
}
}
});
Expand All @@ -50,6 +52,11 @@ const { t } = useI18n({
0.75: '0.75'
}" />
</n-form-item-row>
<n-form-item-row :label="t('autoRefreshInterval')">
<n-slider v-model:value="configAutoRefreshInterval" :min="30" :max="300" :step="1" :marks="{
60: '60', 120: '120', 180: '180', 240: '240'
}" />
</n-form-item-row>
<n-form-item-row :label="t('preferShowTextMail')">
<n-switch v-model:value="preferShowTextMail" :round="false" />
</n-form-item-row>
Expand Down