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

Initial github-actions configuration #1

Merged
merged 10 commits into from
Jan 18, 2021
Prev Previous commit
Next Next commit
lint-js: Reorder function to no-use-before-define
'showCustomContent' and 'showTopicsTopic' was used before it was
defined. This patch reorders the function declaration.

https://eslint.org/docs/rules/no-use-before-define

https://phabricator.endlessm.com/T31232
  • Loading branch information
danigm committed Jan 18, 2021
commit 5f722308f107425d843e27c53c524dd90071f0b4
158 changes: 79 additions & 79 deletions kolibri_explore_plugin/assets/src/modules/topicsTree/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,85 +10,6 @@ import { ContentNodeKinds } from 'kolibri.coreVue.vuex.constants';
import { PageNames, CUSTOM_PRESENTATION_TITLE } from '../../constants';
import { _collectionState, normalizeContentNode, contentState } from '../coreExplore/utils';

export function showTopicsChannel(store, id) {
return store.dispatch('loading').then(() => {
store.commit('SET_PAGE_NAME', PageNames.TOPICS_CHANNEL);
// Check if the channel has a node with a custom presentation. If
// so, go to it directly.
const getParams = {
search: CUSTOM_PRESENTATION_TITLE,
kind: ContentNodeKinds.HTML5,
channel_id: id,
};
ContentNodeSearchResource.getCollection(getParams)
.fetch()
.then(({ results }) => {
if (results.length) {
return showCustomContent(store, results[0].id);
}
return showTopicsTopic(store, { id, isRoot: true });
});
});
}

export function showTopicsContent(store, id) {
store.commit('SET_EMPTY_LOGGING_STATE');
store.commit('CORE_SET_PAGE_LOADING', true);
store.commit('SET_PAGE_NAME', PageNames.TOPICS_CONTENT);

const promises = [
ContentNodeResource.fetchModel({ id }),
ContentNodeResource.fetchNextContent(id),
store.dispatch('setChannelInfo'),
];
ConditionalPromise.all(promises).only(
samePageCheckGenerator(store),
([content, nextContent]) => {
const currentChannel = store.getters.getChannelObject(content.channel_id);
if (!currentChannel) {
router.replace({ name: PageNames.CONTENT_UNAVAILABLE });
return;
}
store.commit('topicsTree/SET_STATE', {
content: contentState(content, nextContent),
channel: currentChannel,
});
store.commit('CORE_SET_PAGE_LOADING', false);
store.commit('CORE_SET_ERROR', null);
},
error => {
store.dispatch('handleApiError', error);
}
);
}

export function showCustomContent(store, id) {
store.commit('SET_EMPTY_LOGGING_STATE');
store.commit('CORE_SET_PAGE_LOADING', true);
store.commit('SET_PAGE_NAME', PageNames.TOPICS_CUSTOM_CHANNEL);

const promises = [ContentNodeResource.fetchModel({ id }), store.dispatch('setChannelInfo')];
ConditionalPromise.all(promises).only(
samePageCheckGenerator(store),
([content]) => {
const currentChannel = store.getters.getChannelObject(content.channel_id);
if (!currentChannel) {
router.replace({ name: PageNames.CONTENT_UNAVAILABLE });
return;
}
store.commit('topicsTree/SET_STATE', {
content: contentState(content, content),
channel: currentChannel,
});
store.commit('CORE_SET_PAGE_LOADING', false);
store.commit('CORE_SET_ERROR', null);
},
error => {
store.dispatch('handleApiError', error);
}
);
}

export function showTopicsTopic(store, { id, isRoot = false }) {
return store.dispatch('loading').then(() => {
store.commit('SET_PAGE_NAME', isRoot ? PageNames.TOPICS_CHANNEL : PageNames.TOPICS_TOPIC);
Expand Down Expand Up @@ -143,3 +64,82 @@ export function showTopicsTopic(store, { id, isRoot = false }) {
);
});
}

export function showCustomContent(store, id) {
store.commit('SET_EMPTY_LOGGING_STATE');
store.commit('CORE_SET_PAGE_LOADING', true);
store.commit('SET_PAGE_NAME', PageNames.TOPICS_CUSTOM_CHANNEL);

const promises = [ContentNodeResource.fetchModel({ id }), store.dispatch('setChannelInfo')];
ConditionalPromise.all(promises).only(
samePageCheckGenerator(store),
([content]) => {
const currentChannel = store.getters.getChannelObject(content.channel_id);
if (!currentChannel) {
router.replace({ name: PageNames.CONTENT_UNAVAILABLE });
return;
}
store.commit('topicsTree/SET_STATE', {
content: contentState(content, content),
channel: currentChannel,
});
store.commit('CORE_SET_PAGE_LOADING', false);
store.commit('CORE_SET_ERROR', null);
},
error => {
store.dispatch('handleApiError', error);
}
);
}

export function showTopicsChannel(store, id) {
return store.dispatch('loading').then(() => {
store.commit('SET_PAGE_NAME', PageNames.TOPICS_CHANNEL);
// Check if the channel has a node with a custom presentation. If
// so, go to it directly.
const getParams = {
search: CUSTOM_PRESENTATION_TITLE,
kind: ContentNodeKinds.HTML5,
channel_id: id,
};
ContentNodeSearchResource.getCollection(getParams)
.fetch()
.then(({ results }) => {
if (results.length) {
return showCustomContent(store, results[0].id);
}
return showTopicsTopic(store, { id, isRoot: true });
});
});
}

export function showTopicsContent(store, id) {
store.commit('SET_EMPTY_LOGGING_STATE');
store.commit('CORE_SET_PAGE_LOADING', true);
store.commit('SET_PAGE_NAME', PageNames.TOPICS_CONTENT);

const promises = [
ContentNodeResource.fetchModel({ id }),
ContentNodeResource.fetchNextContent(id),
store.dispatch('setChannelInfo'),
];
ConditionalPromise.all(promises).only(
samePageCheckGenerator(store),
([content, nextContent]) => {
const currentChannel = store.getters.getChannelObject(content.channel_id);
if (!currentChannel) {
router.replace({ name: PageNames.CONTENT_UNAVAILABLE });
return;
}
store.commit('topicsTree/SET_STATE', {
content: contentState(content, nextContent),
channel: currentChannel,
});
store.commit('CORE_SET_PAGE_LOADING', false);
store.commit('CORE_SET_ERROR', null);
},
error => {
store.dispatch('handleApiError', error);
}
);
}