Skip to content

Commit 0e67e8d

Browse files
committed
Refactor code to use optional chaining for accessing nested properties
1 parent 19cfaf9 commit 0e67e8d

File tree

7 files changed

+93
-9
lines changed

7 files changed

+93
-9
lines changed

nuxt.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ export default defineNuxtConfig({
3838
global: true,
3939
dirs: [{ path: '~/components', prefix: 'sesame' }],
4040
},
41+
appConfig: {
42+
baseUrl: SESAME_APP_API_URL,
43+
},
4144
modules: [
4245
'@nuxt-alt/auth',
4346
'@nuxt-alt/http',

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"pinia": "^2.1.7",
2929
"quasar": "^2.15.4",
3030
"radash": "^12.1.0",
31+
"reconnecting-eventsource": "^1.6.2",
3132
"sass": "^1.70.0",
3233
"vue-eslint-parser": "^9.4.2",
3334
"yaml": "^2.4.2"

src/components/appbar/RightButtons.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ const buttons = [
5656
},
5757
]
5858
59+
const emits = defineEmits(['syncing'])
60+
5961
async function syncAll() {
62+
emits('syncing', { count: badgesValues.value.TO_SYNC })
6063
await useHttp('/core/backends/syncall', {
6164
method: 'POST',
6265
params: {

src/components/appbar/index.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ q-header
1111
//q-separator(vertical dark inset).q-mx-md
1212
//sesame-AppbarMenu
1313
q-space
14-
sesame-AppbarRightButtons
14+
sesame-AppbarRightButtons(@syncing="emits('syncing', $event)")
1515
</template>
1616

1717
<script lang="ts" setup>
@@ -25,7 +25,7 @@ defineOptions({
2525
const $q = useQuasar()
2626
const router = useRouter()
2727
28-
const emits = defineEmits(['closeDrawer'])
28+
const emits = defineEmits(['closeDrawer', 'syncing'])
2929
3030
function backToIndex() {
3131
router.push({ name: 'index' })

src/layouts/default.vue

Lines changed: 78 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template lang="pug">
22
q-layout
3-
sesame-appbar(@closeDrawer="drawer = !drawer")
3+
sesame-appbar(@closeDrawer="drawer = !drawer" @syncing="syncing")
44
q-drawer.flex(v-model="drawer" side="left" :mini="true" bordered)
55
template(#mini)
66
q-scroll-area.fit.mini-slot.cursor-pointer
@@ -20,6 +20,19 @@ q-layout
2020
q-separator
2121
q-page-container
2222
nuxt-page
23+
q-dialog(seamless v-model="eventSeamless" position="bottom")
24+
q-card(style="width: 350px")
25+
q-linear-progress(:value="eventSeamlessProgress" color="amber-9")
26+
q-card-section.row.items-center.no-wrap
27+
q-circular-progress.q-mr-md(indeterminate size="42px" color="amber-9")
28+
//- pre(v-html="JSON.stringify(eventSeamlessCurrentJobs, null, 2)")
29+
div
30+
.text-weight-bold.q-px-md.text-center
31+
| Synchronisation en cours&nbsp;&nbsp;
32+
q-badge(color="amber-10") {{ eventSeamlessCurrent }}/{{ eventSeamlessTotal }}
33+
//- .text-grey Fitz & The Tantrums
34+
q-space
35+
q-btn(flat round icon="mdi-close" v-close-popup)
2336
</template>
2437

2538
<script lang="ts" setup>
@@ -28,11 +41,74 @@ import { IdentityState } from '~/composables'
2841
import { useIdentityStateStore } from '~/stores/identityState'
2942
import { useIdentityAffectationStore } from '~/stores/identityAffectation'
3043
import { useMenu } from '~/composables'
44+
import ReconnectingEventSource from "reconnecting-eventsource";
45+
46+
const identityStateStore = useIdentityStateStore()
47+
48+
const auth = useAuth()
49+
const config = useAppConfig()
50+
const esUrl = new URL(config.baseUrl + "/core/backends/sse")
51+
esUrl.searchParams.append("key", '' + auth.user?.sseToken)
52+
var es = new ReconnectingEventSource(esUrl)
53+
54+
console.log('identityStateStore.getProcessingCount', identityStateStore.getProcessingCount)
55+
56+
const eventSeamless = ref(false)
57+
const eventSeamlessTotal = ref(identityStateStore.getProcessingCount)
58+
const eventSeamlessCurrent = ref(0)
59+
const eventSeamlessCurrentJobs = ref({})
60+
61+
const eventSeamlessProgress = computed(() => {
62+
return eventSeamlessTotal.value === 0 ? 0 : eventSeamlessCurrent.value / eventSeamlessTotal.value
63+
})
64+
65+
async function onmessage(event) {
66+
try {
67+
const data = JSON.parse(event.data)
68+
69+
if (/^job:/.test(data.channel)) {
70+
eventSeamless.value = true
71+
if (eventSeamlessTotal.value === 0) {
72+
await identityStateStore.fetchProcessingCount()
73+
eventSeamlessTotal.value = identityStateStore.getProcessingCount
74+
}
75+
}
76+
77+
switch (data.channel) {
78+
case 'job:added':
79+
eventSeamlessCurrentJobs.value[data.payload.jobId] = data.payload
80+
break
81+
82+
case 'job:completed':
83+
delete eventSeamlessCurrentJobs.value[data.payload.jobId]
84+
eventSeamlessCurrent.value++
85+
86+
if (eventSeamlessCurrent.value >= eventSeamlessTotal.value) {
87+
eventSeamlessCurrent.value = 0
88+
eventSeamlessCurrentJobs.value = {}
89+
setTimeout(() => {
90+
eventSeamless.value = false
91+
}, 2000)
92+
}
93+
break
94+
}
95+
96+
} catch (e) {
97+
console.error(e)
98+
}
99+
}
100+
101+
es.onmessage = onmessage
102+
103+
function syncing(payload: { count: number }) {
104+
eventSeamlessTotal.value = payload.count
105+
eventSeamlessCurrent.value = 0
106+
eventSeamless.value = true
107+
}
31108
32109
const drawer = ref(true)
33110
34111
const router = useRouter()
35-
const identityStateStore = useIdentityStateStore()
36112
const identityAffectationStore = useIdentityAffectationStore()
37113
const { fetchAllStateCount } = identityStateStore
38114
const { fetchAllAffectationCount } = identityAffectationStore
@@ -51,10 +127,6 @@ function push(path: string) {
51127
function logout() {
52128
router.push({ name: 'login' })
53129
}
54-
55-
function test() {
56-
console.log('test')
57-
}
58130
</script>
59131

60132
<style>

src/stores/identityState.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { defineStore } from 'pinia';
2-
import {IdentityState} from '@/composables/useIdentityStates';
2+
import { IdentityState } from '@/composables/useIdentityStates';
33

44
export const useIdentityStateStore = defineStore('identityStates', {
55
state: () => ({

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5985,6 +5985,11 @@ readdirp@~3.6.0:
59855985
dependencies:
59865986
picomatch "^2.2.1"
59875987

5988+
reconnecting-eventsource@^1.6.2:
5989+
version "1.6.2"
5990+
resolved "https://registry.yarnpkg.com/reconnecting-eventsource/-/reconnecting-eventsource-1.6.2.tgz#b7f5b03b1c76291f6fbcb0203004892a57ae253b"
5991+
integrity sha512-vHhoxVLbA2YcfljWMKEbgR1KVTgwIrnyh/bzVJc+gfQbGcUIToLL6jNhkUL4E+9FbnAcfUVNLIw2YCiliTg/4g==
5992+
59885993
redis-errors@^1.0.0, redis-errors@^1.2.0:
59895994
version "1.2.0"
59905995
resolved "https://registry.yarnpkg.com/redis-errors/-/redis-errors-1.2.0.tgz#eb62d2adb15e4eaf4610c04afe1529384250abad"

0 commit comments

Comments
 (0)