Skip to content

Commit

Permalink
Merge pull request #12110 from AlexVelezLl/fix-update-last-sync
Browse files Browse the repository at this point in the history
Update now value in SyncStatusDisplay
  • Loading branch information
AlexVelezLl authored May 7, 2024
2 parents 535f108 + 6c7896b commit cb98c94
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
21 changes: 21 additions & 0 deletions kolibri/core/assets/src/composables/useNow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { now as getNow } from 'kolibri.utils.serverClock';

import { ref, onMounted, onUnmounted } from 'kolibri.lib.vueCompositionApi';

export default function useNow(interval = 10000) {
const now = ref(getNow());

let timer;

onMounted(() => {
timer = setInterval(() => {
now.value = getNow();
}, interval);
});

onUnmounted(() => {
clearInterval(timer);
});

return { now };
}
2 changes: 2 additions & 0 deletions kolibri/core/assets/src/core-app/apiSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ import NotificationsRoot from '../views/NotificationsRoot';
import useMinimumKolibriVersion from '../composables/useMinimumKolibriVersion';
import useUserSyncStatus from '../composables/useUserSyncStatus';
import useUser from '../composables/useUser';
import useNow from '../composables/useNow';

// webpack optimization
import CoreInfoIcon from '../views/CoreInfoIcon';
Expand Down Expand Up @@ -230,6 +231,7 @@ export default {
useKResponsiveWindow,
useKShow,
useMinimumKolibriVersion,
useNow,
useUser,
useUserSyncStatus,
},
Expand Down
11 changes: 5 additions & 6 deletions kolibri/core/assets/src/views/SyncStatusDisplay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@

<script>
import { now } from 'kolibri.utils.serverClock';
import useNow from 'kolibri.coreVue.composables.useNow';
import { SyncStatus } from 'kolibri.coreVue.vuex.constants';
export default {
name: 'SyncStatusDisplay',
setup() {
const { now } = useNow();
return { now };
},
props: {
syncStatus: {
type: String,
Expand All @@ -43,11 +47,6 @@
},
},
},
data() {
return {
now: now(),
};
},
computed: {
syncTextDisplayMap() {
const statusTranslations = {
Expand Down

0 comments on commit cb98c94

Please sign in to comment.