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

Update now value in SyncStatusDisplay #12110

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
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To justify the composable, we could use this in the ElapsedTime component as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a follow-up issue for this in #12114

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
Loading