Skip to content

Commit 0e01fbf

Browse files
committed
refactor(Notification, ProcessingStatus, SetLanguage): move SSE connection logic to onMounted lifecycle hook and update language handling in SetLanguage component
1 parent 48cdfce commit 0e01fbf

File tree

21 files changed

+3148
-2522
lines changed

21 files changed

+3148
-2522
lines changed

app/src/components/Notification/Notification.vue

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,23 @@ const data = ref([]) as Ref<Notification[]>
2626
2727
const { connect } = useSSE()
2828
29-
connect({
30-
url: '/api/notifications/live',
31-
onMessage: (data: Notification) => {
32-
const typeTrans = {
33-
0: 'error',
34-
1: 'warning',
35-
2: 'info',
36-
3: 'success',
37-
}
38-
39-
notification[typeTrans[data.type]]({
40-
message: $gettext(data.title),
41-
description: detailRender({ text: data.details, record: data }),
42-
})
43-
},
29+
onMounted(() => {
30+
connect({
31+
url: '/api/notifications/live',
32+
onMessage: (data: Notification) => {
33+
const typeTrans = {
34+
0: 'error',
35+
1: 'warning',
36+
2: 'info',
37+
3: 'success',
38+
}
39+
40+
notification[typeTrans[data.type]]({
41+
message: $gettext(data.title),
42+
description: detailRender({ text: data.details, record: data }),
43+
})
44+
},
45+
})
4446
})
4547
4648
function init() {

app/src/components/ProcessingStatus/ProcessingStatus.vue

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ const { connect } = useSSE()
88
const globalStore = useGlobalStore()
99
const { processingStatus } = storeToRefs(globalStore)
1010
11-
connect({
12-
url: '/api/system/processing',
13-
onMessage: data => {
14-
processingStatus.value = data
15-
},
11+
onMounted(() => {
12+
connect({
13+
url: '/api/system/processing',
14+
onMessage: data => {
15+
processingStatus.value = data
16+
},
17+
})
1618
})
1719
1820
const isProcessing = computed(() => {

app/src/components/SetLanguage/SetLanguage.vue

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import gettext from '@/gettext'
55
import { useSettingsStore, useUserStore } from '@/pinia'
66
77
const settings = useSettingsStore()
8-
const userStore = useUserStore()
9-
const { info } = storeToRefs(userStore)
8+
const user = useUserStore()
109
1110
const route = useRoute()
1211
@@ -30,8 +29,9 @@ function updateTitle() {
3029
watch(current, v => {
3130
loadTranslations(route)
3231
settings.set_language(v)
33-
gettext.current = v
34-
userStore.updateCurrentUserLanguage(v)
32+
if (user.isLogin) {
33+
user.updateCurrentUserLanguage(v)
34+
}
3535
3636
updateTitle()
3737
})
@@ -109,11 +109,7 @@ async function init() {
109109
}
110110
111111
// Reactive initialization and watch
112-
onMounted(async () => {
113-
current.value = info.value.language || 'en'
114-
await nextTick()
115-
await init()
116-
})
112+
onMounted(init)
117113
watch(current, init)
118114
</script>
119115

app/src/language/ar/app.po

Lines changed: 175 additions & 160 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)