From 76a032f18acb3f4d68a73b34aaedb7903ca2fba6 Mon Sep 17 00:00:00 2001 From: Samson Akol Date: Fri, 2 Sep 2022 14:16:39 +0300 Subject: [PATCH 1/5] translates 'Guest' string --- .../contentcuration/frontend/shared/translator.js | 1 + .../frontend/shared/vuex/session/index.js | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/contentcuration/contentcuration/frontend/shared/translator.js b/contentcuration/contentcuration/frontend/shared/translator.js index 5cf1f5b50f..28952712d0 100644 --- a/contentcuration/contentcuration/frontend/shared/translator.js +++ b/contentcuration/contentcuration/frontend/shared/translator.js @@ -24,6 +24,7 @@ const MESSAGES = { activityDurationTimeMinRequirement: 'Time must be greater than or equal to 1', activityDurationTooLongWarning: 'Please make sure this is the amount of time you want learners to spend on this resource to complete it', + guestName: 'Guest', }; export default createTranslator('sharedVue', MESSAGES); diff --git a/contentcuration/contentcuration/frontend/shared/vuex/session/index.js b/contentcuration/contentcuration/frontend/shared/vuex/session/index.js index 86e7e8485f..bcc6b216db 100644 --- a/contentcuration/contentcuration/frontend/shared/vuex/session/index.js +++ b/contentcuration/contentcuration/frontend/shared/vuex/session/index.js @@ -6,9 +6,9 @@ import { Session, User } from 'shared/data/resources'; import { forceServerSync } from 'shared/data/serverSync'; import translator from 'shared/translator'; -const GUEST_USER = { - first_name: 'Guest', -}; +const GUEST_USER = async () => ({ + first_name: translator.$tr('guestName'), +}); function langCode(language) { // Turns a Django language name (en-gb) into an ISO language code (en-GB) @@ -30,8 +30,8 @@ function langCode(language) { } export default { - state: () => ({ - currentUser: GUEST_USER, + state: async () => ({ + currentUser: await GUEST_USER, preferences: window.user_preferences === 'string' ? JSON.parse(window.user_preferences) @@ -49,8 +49,8 @@ export default { ...data, }; }, - REMOVE_SESSION(state) { - state.currentUser = GUEST_USER; + async REMOVE_SESSION(state) { + state.currentUser = await GUEST_USER; }, }, getters: { From e27bfe7ef1eb2bbdba511e82d7747d722e8e62cd Mon Sep 17 00:00:00 2001 From: Samson Akol Date: Fri, 2 Sep 2022 14:47:25 +0300 Subject: [PATCH 2/5] reverts to failing code --- .../frontend/shared/vuex/session/index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/contentcuration/contentcuration/frontend/shared/vuex/session/index.js b/contentcuration/contentcuration/frontend/shared/vuex/session/index.js index bcc6b216db..b0a1263dae 100644 --- a/contentcuration/contentcuration/frontend/shared/vuex/session/index.js +++ b/contentcuration/contentcuration/frontend/shared/vuex/session/index.js @@ -6,9 +6,9 @@ import { Session, User } from 'shared/data/resources'; import { forceServerSync } from 'shared/data/serverSync'; import translator from 'shared/translator'; -const GUEST_USER = async () => ({ +const GUEST_USER = { first_name: translator.$tr('guestName'), -}); +}; function langCode(language) { // Turns a Django language name (en-gb) into an ISO language code (en-GB) @@ -30,8 +30,8 @@ function langCode(language) { } export default { - state: async () => ({ - currentUser: await GUEST_USER, + state: () => ({ + currentUser: GUEST_USER, preferences: window.user_preferences === 'string' ? JSON.parse(window.user_preferences) @@ -49,8 +49,8 @@ export default { ...data, }; }, - async REMOVE_SESSION(state) { - state.currentUser = await GUEST_USER; + REMOVE_SESSION(state) { + state.currentUser = GUEST_USER; }, }, getters: { From 9e84c90f911a510517f2df8db1378f4076d45c85 Mon Sep 17 00:00:00 2001 From: Samson Akol Date: Fri, 2 Sep 2022 17:39:01 +0300 Subject: [PATCH 3/5] implements guest translator within app due to failure within state --- .../contentcuration/frontend/shared/app.js | 8 +++++++- .../frontend/shared/vuex/session/index.js | 13 +++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/contentcuration/contentcuration/frontend/shared/app.js b/contentcuration/contentcuration/frontend/shared/app.js index cc0e9f9bc7..e7c0ff198e 100644 --- a/contentcuration/contentcuration/frontend/shared/app.js +++ b/contentcuration/contentcuration/frontend/shared/app.js @@ -119,6 +119,7 @@ import ActionLink from 'shared/views/ActionLink'; import Menu from 'shared/views/Menu'; import { initializeDB, resetDB } from 'shared/data'; import { Session, injectVuexStore } from 'shared/data/resources'; +import translator from 'shared/translator'; // just say yes to devtools (in debug mode) if (process.env.NODE_ENV !== 'production') { @@ -303,7 +304,10 @@ export default async function startApp({ store, router, index }) { await initializeDB(); await i18nSetup(); - const currentUser = window.user || {}; + const guestUser = { + first_name: translator.$tr('guestName'), + }; + const currentUser = window.user || guestUser; const dbCurrentUser = (await Session.getSession()) || {}; if ( @@ -315,6 +319,8 @@ export default async function startApp({ store, router, index }) { } if (currentUser.id !== undefined && currentUser.id !== null) { await store.dispatch('saveSession', currentUser, { root: true }); + } else { + await store.dispatch('saveGuestSession', currentUser); } await Session.setChannelScope(); diff --git a/contentcuration/contentcuration/frontend/shared/vuex/session/index.js b/contentcuration/contentcuration/frontend/shared/vuex/session/index.js index b0a1263dae..d68d2f987d 100644 --- a/contentcuration/contentcuration/frontend/shared/vuex/session/index.js +++ b/contentcuration/contentcuration/frontend/shared/vuex/session/index.js @@ -6,10 +6,6 @@ import { Session, User } from 'shared/data/resources'; import { forceServerSync } from 'shared/data/serverSync'; import translator from 'shared/translator'; -const GUEST_USER = { - first_name: translator.$tr('guestName'), -}; - function langCode(language) { // Turns a Django language name (en-gb) into an ISO language code (en-GB) // Copied and modified from Django's to_locale function that does something similar @@ -31,7 +27,7 @@ function langCode(language) { export default { state: () => ({ - currentUser: GUEST_USER, + currentUser: {}, preferences: window.user_preferences === 'string' ? JSON.parse(window.user_preferences) @@ -50,7 +46,9 @@ export default { }; }, REMOVE_SESSION(state) { - state.currentUser = GUEST_USER; + state.currentUser = { + first_name: translator.$tr('guestName'), + }; }, }, getters: { @@ -98,6 +96,9 @@ export default { await Session.updateSession(currentUser); context.commit('ADD_SESSION', currentUser); }, + async saveGuestSession(context, guestUser) { + context.commit('ADD_SESSION', guestUser); + }, login(context, credentials) { return client.post(window.Urls.login(), credentials); }, From 7f1f268dd393168f269589f6c1e5da2cd57cf02a Mon Sep 17 00:00:00 2001 From: Samson Akol Date: Mon, 5 Sep 2022 14:32:27 +0300 Subject: [PATCH 4/5] Code clean up --- .../frontend/shared/vuex/session/index.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/contentcuration/contentcuration/frontend/shared/vuex/session/index.js b/contentcuration/contentcuration/frontend/shared/vuex/session/index.js index d68d2f987d..7a02b7051b 100644 --- a/contentcuration/contentcuration/frontend/shared/vuex/session/index.js +++ b/contentcuration/contentcuration/frontend/shared/vuex/session/index.js @@ -6,6 +6,8 @@ import { Session, User } from 'shared/data/resources'; import { forceServerSync } from 'shared/data/serverSync'; import translator from 'shared/translator'; +let guestUser = {}; + function langCode(language) { // Turns a Django language name (en-gb) into an ISO language code (en-GB) // Copied and modified from Django's to_locale function that does something similar @@ -27,7 +29,7 @@ function langCode(language) { export default { state: () => ({ - currentUser: {}, + currentUser: guestUser, preferences: window.user_preferences === 'string' ? JSON.parse(window.user_preferences) @@ -46,9 +48,7 @@ export default { }; }, REMOVE_SESSION(state) { - state.currentUser = { - first_name: translator.$tr('guestName'), - }; + state.currentUser = guestUser; }, }, getters: { @@ -96,8 +96,9 @@ export default { await Session.updateSession(currentUser); context.commit('ADD_SESSION', currentUser); }, - async saveGuestSession(context, guestUser) { - context.commit('ADD_SESSION', guestUser); + async saveGuestSession(context, currentUser) { + context.commit('ADD_SESSION', currentUser); + guestUser = currentUser; }, login(context, credentials) { return client.post(window.Urls.login(), credentials); From 8169d241cbf8e7cee7204492c8f2fa31e733e1bf Mon Sep 17 00:00:00 2001 From: Samson Akol Date: Wed, 7 Sep 2022 15:33:29 +0300 Subject: [PATCH 5/5] Reverts code and removes guest string --- .../contentcuration/frontend/shared/app.js | 8 +------- .../contentcuration/frontend/shared/translator.js | 1 - .../frontend/shared/vuex/session/index.js | 12 +++++------- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/contentcuration/contentcuration/frontend/shared/app.js b/contentcuration/contentcuration/frontend/shared/app.js index e7c0ff198e..cc0e9f9bc7 100644 --- a/contentcuration/contentcuration/frontend/shared/app.js +++ b/contentcuration/contentcuration/frontend/shared/app.js @@ -119,7 +119,6 @@ import ActionLink from 'shared/views/ActionLink'; import Menu from 'shared/views/Menu'; import { initializeDB, resetDB } from 'shared/data'; import { Session, injectVuexStore } from 'shared/data/resources'; -import translator from 'shared/translator'; // just say yes to devtools (in debug mode) if (process.env.NODE_ENV !== 'production') { @@ -304,10 +303,7 @@ export default async function startApp({ store, router, index }) { await initializeDB(); await i18nSetup(); - const guestUser = { - first_name: translator.$tr('guestName'), - }; - const currentUser = window.user || guestUser; + const currentUser = window.user || {}; const dbCurrentUser = (await Session.getSession()) || {}; if ( @@ -319,8 +315,6 @@ export default async function startApp({ store, router, index }) { } if (currentUser.id !== undefined && currentUser.id !== null) { await store.dispatch('saveSession', currentUser, { root: true }); - } else { - await store.dispatch('saveGuestSession', currentUser); } await Session.setChannelScope(); diff --git a/contentcuration/contentcuration/frontend/shared/translator.js b/contentcuration/contentcuration/frontend/shared/translator.js index 28952712d0..5cf1f5b50f 100644 --- a/contentcuration/contentcuration/frontend/shared/translator.js +++ b/contentcuration/contentcuration/frontend/shared/translator.js @@ -24,7 +24,6 @@ const MESSAGES = { activityDurationTimeMinRequirement: 'Time must be greater than or equal to 1', activityDurationTooLongWarning: 'Please make sure this is the amount of time you want learners to spend on this resource to complete it', - guestName: 'Guest', }; export default createTranslator('sharedVue', MESSAGES); diff --git a/contentcuration/contentcuration/frontend/shared/vuex/session/index.js b/contentcuration/contentcuration/frontend/shared/vuex/session/index.js index 7a02b7051b..86e7e8485f 100644 --- a/contentcuration/contentcuration/frontend/shared/vuex/session/index.js +++ b/contentcuration/contentcuration/frontend/shared/vuex/session/index.js @@ -6,7 +6,9 @@ import { Session, User } from 'shared/data/resources'; import { forceServerSync } from 'shared/data/serverSync'; import translator from 'shared/translator'; -let guestUser = {}; +const GUEST_USER = { + first_name: 'Guest', +}; function langCode(language) { // Turns a Django language name (en-gb) into an ISO language code (en-GB) @@ -29,7 +31,7 @@ function langCode(language) { export default { state: () => ({ - currentUser: guestUser, + currentUser: GUEST_USER, preferences: window.user_preferences === 'string' ? JSON.parse(window.user_preferences) @@ -48,7 +50,7 @@ export default { }; }, REMOVE_SESSION(state) { - state.currentUser = guestUser; + state.currentUser = GUEST_USER; }, }, getters: { @@ -96,10 +98,6 @@ export default { await Session.updateSession(currentUser); context.commit('ADD_SESSION', currentUser); }, - async saveGuestSession(context, currentUser) { - context.commit('ADD_SESSION', currentUser); - guestUser = currentUser; - }, login(context, credentials) { return client.post(window.Urls.login(), credentials); },