Skip to content

Commit

Permalink
Merge pull request #12574 from rtibbles/channelling
Browse files Browse the repository at this point in the history
Move core channel state into coach - the only place it is still used.
  • Loading branch information
marcellamaki committed Aug 29, 2024
2 parents 190f921 + fd2c397 commit 65db937
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 48 deletions.
28 changes: 0 additions & 28 deletions kolibri/core/assets/src/state/modules/core/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import logger from 'kolibri.lib.logging';
import {
FacilityResource,
FacilityDatasetResource,
ChannelResource,
UserProgressResource,
UserSyncStatusResource,
PingbackNotificationResource,
Expand Down Expand Up @@ -38,20 +37,6 @@ const logging = logger.getLogger(__filename);
* the API to state in the Vuex store
*/

function _channelListState(data) {
return data.map(channel => ({
id: channel.id,
title: channel.name,
description: channel.description,
tagline: channel.tagline,
root_id: channel.root,
last_updated: channel.last_updated,
version: channel.version,
thumbnail: channel.thumbnail,
num_coach_contents: channel.num_coach_contents,
}));
}

function _notificationListState(data) {
return data.map(notification => ({
id: notification.id,
Expand Down Expand Up @@ -261,19 +246,6 @@ export function getFacilityConfig(store, facilityId) {
});
}

export function setChannelInfo(store) {
return ChannelResource.fetchCollection({ getParams: { available: true } }).then(
channelsData => {
store.commit('SET_CORE_CHANNEL_LIST', _channelListState(channelsData));
return channelsData;
},
error => {
store.dispatch('handleApiError', { error });
return error;
},
);
}

export function fetchPoints(store) {
const { isUserLoggedIn, currentUserId } = store.getters;
if (isUserLoggedIn && store.state.totalProgress === null) {
Expand Down
10 changes: 0 additions & 10 deletions kolibri/core/assets/src/state/modules/core/getters.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ export function facilities(state) {
return state.facilities;
}

export function getChannels(state) {
return state.channels.list;
}

export function getChannelObject(state) {
return function getter(channelId) {
return getChannels(state).find(channel => channel.id === channelId);
};
}

export function totalPoints(state) {
return state.totalProgress * MaxPointsPerContent;
}
Expand Down
4 changes: 0 additions & 4 deletions kolibri/core/assets/src/state/modules/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ export default {
pageSessionId: 0,
totalProgress: null,
notifications: [],
channels: {
list: [],
currentId: null,
},
allowRemoteAccess: plugin_data.allowRemoteAccess,
// facility
facilityConfig: {},
Expand Down
3 changes: 0 additions & 3 deletions kolibri/core/assets/src/state/modules/core/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ export default {
INCREMENT_TOTAL_PROGRESS(state, progress) {
state.totalProgress += progress;
},
SET_CORE_CHANNEL_LIST(state, channelList) {
state.channels.list = channelList;
},
CORE_SET_NOTIFICATIONS(state, notifications) {
state.notifications = notifications;
},
Expand Down
29 changes: 28 additions & 1 deletion kolibri/plugins/coach/assets/src/app.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { get } from '@vueuse/core';
import useUser from 'kolibri.coreVue.composables.useUser';
import redirectBrowser from 'kolibri.utils.redirectBrowser';
import { setChannelInfo } from 'kolibri.coreVue.vuex.actions';
import router from 'kolibri.coreVue.router';
import { ChannelResource } from 'kolibri.resources';
import KolibriApp from 'kolibri_app';
import useSnackbar from 'kolibri.coreVue.composables.useSnackbar';
import { PageNames } from './constants';
Expand All @@ -16,6 +16,33 @@ import GroupEnrollPage from './views/plan/GroupEnrollPage';
import pages from './views/reports/allReportsPages';
import HomeActivityPage from './views/home/HomeActivityPage';

function _channelListState(data) {
return data.map(channel => ({
id: channel.id,
title: channel.name,
description: channel.description,
tagline: channel.tagline,
root_id: channel.root,
last_updated: channel.last_updated,
version: channel.version,
thumbnail: channel.thumbnail,
num_coach_contents: channel.num_coach_contents,
}));
}

export function setChannelInfo(store) {
return ChannelResource.fetchCollection({ getParams: { available: true } }).then(
channelsData => {
store.commit('SET_CHANNEL_LIST', _channelListState(channelsData));
return channelsData;
},
error => {
store.dispatch('handleApiError', { error });
return error;
},
);
}

class CoachToolsModule extends KolibriApp {
get stateSetters() {
return [setChannelInfo];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default {
getters: {
getChannelForNode(state, getters, rootState) {
return function getter(node) {
return rootState.core.channels.list.find(({ id }) => id === node.channel_id);
return rootState.channels.list.find(({ id }) => id === node.channel_id);
};
},
},
Expand Down
15 changes: 15 additions & 0 deletions kolibri/plugins/coach/assets/src/modules/pluginModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export default {
pageName: '',
toolbarRoute: {},
toolbarTitle: '',
channels: {
list: [],
currentId: null,
},
};
},
mutations: {
Expand All @@ -43,6 +47,9 @@ export default {
SET_TOOLBAR_ROUTE(state, toolbarRoute) {
state.toolbarRoute = toolbarRoute;
},
SET_CHANNEL_LIST(state, channelList) {
state.channels.list = channelList;
},
},
getters: {
classListPageEnabled(state) {
Expand All @@ -62,6 +69,14 @@ export default {
}
return false;
},
getChannels(state) {
return state.channels.list;
},
getChannelObject(state, getters) {
return function getter(channelId) {
return getters.getChannels(state).find(channel => channel.id === channelId);
};
},
},
actions: {
setClassList(store, facilityId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('LessonsSearchFilters', () => {

it('has the correct channel filter options based on search results', async () => {
const { wrapper, els } = makeWrapper();
wrapper.vm.$store.state.core.channels.list = [{ id: '123', title: 'Channel 123' }];
wrapper.vm.$store.state.channels.list = [{ id: '123', title: 'Channel 123' }];
wrapper.setProps({
searchResults: {
channel_ids: ['123'],
Expand Down

0 comments on commit 65db937

Please sign in to comment.