Skip to content

Commit

Permalink
migrating to the useUser composable (coach plugin)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanaelg16 committed Jul 23, 2024
1 parent 69860dd commit 7f9a301
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 15 deletions.
4 changes: 3 additions & 1 deletion kolibri/plugins/coach/assets/src/composables/useCoreCoach.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import logger from 'kolibri.lib.logging';
import { get } from '@vueuse/core';
import { computed, getCurrentInstance } from 'kolibri.lib.vueCompositionApi';
import { currentLanguage, isRtl } from 'kolibri.utils.i18n';
import useUser from 'kolibri.coreVue.composables.useUser';
import { coachStrings } from '../views/common/commonCoachStrings';

const logging = logger.getLogger(__filename);
Expand All @@ -15,13 +16,14 @@ export default function useCoreCoach(store) {
const authorized = computed(() => store.getters.userIsAuthorizedForCoach);
const classId = computed(() => get(route).params.classId);
const groups = computed(() => store.getters['classSummary/groups']);
const { isSuperuser } = useUser();

function getAppBarTitle() {
let facilityName;
// Using coachStrings.$tr() here because mixins are not applied
// prior to props being processed.
const { facility_id, name } = store.state.classSummary;
if (facility_id && store.state.core.facilities.length > 1 && store.getters.isSuperuser) {
if (facility_id && store.state.core.facilities.length > 1 && isSuperuser) {
const match = find(store.state.core.facilities, { id: facility_id }) || {};
facilityName = match.name;
}
Expand Down
3 changes: 2 additions & 1 deletion kolibri/plugins/coach/assets/src/composables/useGroups.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ref } from 'kolibri.lib.vueCompositionApi';
import samePageCheckGenerator from 'kolibri.utils.samePageCheckGenerator';
import { LearnerGroupResource, FacilityUserResource } from 'kolibri.resources';
import useUser from 'kolibri.coreVue.composables.useUser';

// Place outside the function to keep the state
const groupsAreLoading = ref(false);
Expand All @@ -13,7 +14,7 @@ export function useGroups() {
async function showGroupsPage(store, classId) {
const initClassInfoPromise = store.dispatch('initClassInfo', classId);
const getFacilitiesPromise =
store.getters.isSuperuser && store.state.core.facilities.length === 0
useUser().isSuperuser && store.state.core.facilities.length === 0
? store.dispatch('getFacilities').catch(() => {})
: Promise.resolve();

Expand Down
3 changes: 2 additions & 1 deletion kolibri/plugins/coach/assets/src/composables/useLessons.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ref } from 'kolibri.lib.vueCompositionApi';
import { LearnerGroupResource } from 'kolibri.resources';
import useUser from 'kolibri.coreVue.composables.useUser';
import { LessonsPageNames } from '../constants/lessonsConstants';

// Place outside the function to keep the state
Expand All @@ -14,7 +15,7 @@ export function useLessons() {
async function showLessonsRootPage(store, classId) {
const initClassInfoPromise = store.dispatch('initClassInfo', classId);
const getFacilitiesPromise =
store.getters.isSuperuser && store.state.core.facilities.length === 0
useUser().isSuperuser && store.state.core.facilities.length === 0
? store.dispatch('getFacilities').catch(() => {})
: Promise.resolve();

Expand Down
9 changes: 7 additions & 2 deletions kolibri/plugins/coach/assets/src/views/AllFacilitiesPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import CoreTable from 'kolibri.coreVue.components.CoreTable';
import commonCoreStrings from 'kolibri.coreVue.mixins.commonCoreStrings';
import useUser from 'kolibri.coreVue.composables.useUser';
import commonCoach from './common';
import CoachAppBarPage from './CoachAppBarPage';
Expand All @@ -51,6 +52,10 @@
CoreTable,
},
mixins: [commonCoach, commonCoreStrings],
setup() {
const { facility_id, userIsMultiFacilityAdmin } = useUser();
return { facility_id, userIsMultiFacilityAdmin };
},
props: {
subtopicName: {
type: String,
Expand All @@ -64,8 +69,8 @@
},
},
beforeMount() {
if (!this.$store.getters.userIsMultiFacilityAdmin) {
const singleFacility = { id: this.$store.getters.userFacilityId };
if (!this.userIsMultiFacilityAdmin) {
const singleFacility = { id: this.facility_id };
this.$router.replace(this.coachClassListPageLink(singleFacility));
}
},
Expand Down
8 changes: 6 additions & 2 deletions kolibri/plugins/coach/assets/src/views/CoachClassListPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@

<script>
import { mapGetters, mapState } from 'vuex';
import { mapState } from 'vuex';
import find from 'lodash/find';
import commonCoreStrings from 'kolibri.coreVue.mixins.commonCoreStrings';
import urls from 'kolibri.urls';
import useUser from 'kolibri.coreVue.composables.useUser';
import { PageNames } from '../constants';
import CoachAppBarPage from './CoachAppBarPage';
import commonCoach from './common';
Expand All @@ -79,6 +80,10 @@
CoachAppBarPage,
},
mixins: [commonCoach, commonCoreStrings],
setup() {
const { isClassCoach, isFacilityCoach, userIsMultiFacilityAdmin } = useUser();
return { isClassCoach, isFacilityCoach, userIsMultiFacilityAdmin };
},
props: {
subtopicName: {
type: String,
Expand All @@ -87,7 +92,6 @@
},
},
computed: {
...mapGetters(['isAdmin', 'isClassCoach', 'isFacilityCoach', 'userIsMultiFacilityAdmin']),
...mapState(['classList', 'dataLoading']),
// Message that shows up when state.classList is empty
emptyStateDetails() {
Expand Down
10 changes: 9 additions & 1 deletion kolibri/plugins/coach/assets/src/views/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import MasteryModel from 'kolibri.coreVue.components.MasteryModel';
import filter from 'lodash/filter';
import get from 'lodash/get';
import orderBy from 'lodash/orderBy';
import useUser from 'kolibri.coreVue.composables.useUser';
import { PageNames } from '../constants';
import { LastPages } from '../constants/lastPagesConstants';
import { STATUSES } from '../modules/classSummary/constants';
Expand Down Expand Up @@ -66,8 +67,15 @@ export default {
TimeDuration,
},
mixins: [coachStringsMixin],
setup() {
const { isAdmin, isCoach, isSuperuser } = useUser();
return {
isAdmin,
isCoach,
isSuperuser,
};
},
computed: {
...mapGetters(['isAdmin', 'isCoach', 'isSuperuser']),
...mapState('classSummary', { classId: 'id', className: 'name' }),
...mapState('classSummary', [
'adHocGroupsMap',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,20 @@
import { mapGetters } from 'vuex';
import pickBy from 'lodash/pickBy';
import commonCoreStrings from 'kolibri.coreVue.mixins.commonCoreStrings';
import useUser from 'kolibri.coreVue.composables.useUser';
import { ClassesPageNames } from '../../../../../../learn/assets/src/constants';
import commonCoach from '../../common';
import { LastPages } from '../../../constants/lastPagesConstants';
export default {
name: 'OverviewBlock',
mixins: [commonCoach, commonCoreStrings],
setup() {
const { userIsMultiFacilityAdmin } = useUser();
return { userIsMultiFacilityAdmin };
},
computed: {
...mapGetters(['classListPageEnabled', 'userIsMultiFacilityAdmin']),
...mapGetters(['classListPageEnabled']),
coachNames() {
return this.coaches.map(coach => coach.name);
},
Expand All @@ -79,7 +84,7 @@
},
classListLink() {
let facility_id;
if (this.$store.getters.userIsMultiFacilityAdmin) {
if (this.userIsMultiFacilityAdmin) {
facility_id = this.$store.state.classSummary.facility_id;
}
return this.$router.getRoute('CoachClassListPage', { facility_id });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
created() {
const initClassInfoPromise = this.$store.dispatch('initClassInfo', this.classId);
const getFacilitiesPromise =
this.$store.getters.isSuperuser && this.$store.state.core.facilities.length === 0
this.isSuperuser && this.$store.state.core.facilities.length === 0
? this.$store.dispatch('getFacilities').catch(() => {})
: Promise.resolve();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import isEqual from 'lodash/isEqual';
import { LessonResource } from 'kolibri.resources';
import commonCoreStrings from 'kolibri.coreVue.mixins.commonCoreStrings';
import useUser from 'kolibri.coreVue.composables.useUser';
import { coachStringsMixin } from '../../common/commonCoachStrings';
import CoachImmersivePage from '../../CoachImmersivePage';
import AssignmentDetailsModal from '../assignments/AssignmentDetailsModal';
Expand All @@ -49,6 +50,10 @@
ResourceListTable,
},
mixins: [coachStringsMixin, commonCoreStrings],
setup() {
const { isSuperuser } = useUser();
return { isSuperuser };
},
props: {
showResourcesTable: {
type: Boolean,
Expand Down Expand Up @@ -96,7 +101,7 @@
this.$route.params.classId,
);
const getFacilitiesPromise =
this.$store.getters.isSuperuser && this.$store.state.core.facilities.length === 0
this.isSuperuser && this.$store.state.core.facilities.length === 0
? this.$store.dispatch('getFacilities').catch(() => {})
: Promise.resolve();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
import BottomAppBar from 'kolibri.coreVue.components.BottomAppBar';
import commonCoreStrings from 'kolibri.coreVue.mixins.commonCoreStrings';
import useKResponsiveWindow from 'kolibri-design-system/lib/composables/useKResponsiveWindow';
import useUser from 'kolibri.coreVue.composables.useUser';
import commonCoach from '../../common';
import CoachAppBarPage from '../../CoachAppBarPage';
import CoachImmersivePage from '../../CoachImmersivePage';
Expand Down Expand Up @@ -149,8 +150,10 @@
mixins: [commonCoach, commonCoreStrings],
setup() {
const { windowIsSmall } = useKResponsiveWindow();
const { getUserPermissions } = useUser();
return {
windowIsSmall,
getUserPermissions,
};
},
data() {
Expand Down Expand Up @@ -180,7 +183,6 @@
'ancestors',
]),
...mapGetters('lessonSummary/resources', ['numRemainingSearchResults']),
...mapGetters(['getUserPermissions']),
toolbarRoute() {
if (this.$route.query.last) {
return this.$router.getRoute(this.$route.query.last);
Expand Down
5 changes: 4 additions & 1 deletion kolibri/plugins/coach/assets/src/views/plan/PlanHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import { mapGetters } from 'vuex';
import commonCoreStrings from 'kolibri.coreVue.mixins.commonCoreStrings';
import useUser from 'kolibri.coreVue.composables.useUser';
import commonCoach from '../common';
import { PageNames } from '../../constants';
import { LessonsPageNames } from '../../constants/lessonsConstants';
Expand All @@ -40,9 +41,11 @@
mixins: [commonCoach, commonCoreStrings],
setup() {
const { saveTabsClick, wereTabsClickedRecently } = useCoachTabs();
const { userIsMultiFacilityAdmin } = useUser();
return {
saveTabsClick,
wereTabsClickedRecently,
userIsMultiFacilityAdmin,
};
},
props: {
Expand All @@ -57,7 +60,7 @@
};
},
computed: {
...mapGetters(['classListPageEnabled', 'userIsMultiFacilityAdmin']),
...mapGetters(['classListPageEnabled']),
LessonsPageNames() {
return LessonsPageNames;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import { mapGetters } from 'vuex';
import commonCoreStrings from 'kolibri.coreVue.mixins.commonCoreStrings';
import useUser from 'kolibri.coreVue.composables.useUser';
import commonCoach from '../common';
import { REPORTS_TABS_ID, ReportsTabs } from '../../constants/tabsConstants';
import { useCoachTabs } from '../../composables/useCoachTabs';
Expand All @@ -40,9 +41,11 @@
mixins: [commonCoach, commonCoreStrings],
setup() {
const { saveTabsClick, wereTabsClickedRecently } = useCoachTabs();
const { userIsMultiFacilityAdmin } = useUser();
return {
saveTabsClick,
wereTabsClickedRecently,
userIsMultiFacilityAdmin,
};
},
props: {
Expand All @@ -61,7 +64,7 @@
};
},
computed: {
...mapGetters(['classListPageEnabled', 'userIsMultiFacilityAdmin']),
...mapGetters(['classListPageEnabled']),
reportTitle() {
return this.title || this.coachString('reportsLabel');
},
Expand Down

0 comments on commit 7f9a301

Please sign in to comment.