Skip to content

Commit

Permalink
KCircularloader replaces the view more button when fetching more reso…
Browse files Browse the repository at this point in the history
…urces
  • Loading branch information
AllanOXDi committed Jan 30, 2024
1 parent 519ce79 commit fd0b6d5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
10 changes: 8 additions & 2 deletions kolibri/plugins/coach/assets/src/composables/useQuizResources.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import useFetchTree from './useFetchTree';
import { QuizExercise } from './quizCreationSpecs.js';

const logger = logging.getLogger(__filename);

const _loadingMore = ref(false);
/**
* @typedef {Object} QuizResourcesConfig
* @property { computed <string|null|undefined> } topicId - The id of the root node to fetch the
Expand Down Expand Up @@ -102,11 +102,16 @@ export default function useQuizResources({ topicId } = {}) {
*/
async function fetchMoreQuizResources() {
set(_loading, true);
set(_loadingMore, true);
return fetchMore().then(async results => {
set(_resources, [...get(_resources), ...results]);
return annotateTopicsWithDescendantCounts(
results.filter(({ kind }) => kind === ContentNodeKinds.TOPIC).map(topic => topic.id)
).then(() => set(_loading, false));
).then(() =>{
set(_loading, false);
set(_loadingMore, false);
}
);
});
}

Expand All @@ -126,6 +131,7 @@ export default function useQuizResources({ topicId } = {}) {
setResources,
resources: computed(() => get(_resources)),
loading: computed(() => get(_loading) || get(treeLoading)),
loadingMore: computed(() => get(_loadingMore)),
fetchQuizResources,
fetchMoreQuizResources,
hasCheckbox,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
:contentCardMessage="selectionMetadata"
:contentCardLink="contentLink"
:selectAllIndeterminate="selectAllIndeterminate"
:loadingMoreState="loadingMore"
@changeselectall="toggleTopicInWorkingResources"
@change_content_card="toggleSelected"
@moreresults="fetchMoreQuizResources"
Expand Down Expand Up @@ -171,6 +172,7 @@
hasMore,
annotateTopicsWithDescendantCounts,
setResources,
loadingMore,
} = useQuizResources({ topicId });
const _loading = ref(true);
Expand Down Expand Up @@ -249,6 +251,7 @@
hasCheckbox,
loading,
hasMore,
loadingMore,
fetchMoreQuizResources,
resetWorkingResourcePool,
contentPresentInWorkingResourcePool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@

<template>
<KButton
v-if="showButton"
v-if="showButton && !loadingMoreState"
:text="coreString('viewMoreAction')"
:primary="false"
@click="$emit('moreresults')"
/>
<KCircularLoader
v-if="viewMoreButtonState === 'waiting'"
v-if="viewMoreButtonState === 'waiting' & loadingMoreState"
:delay="false"
/>
<!-- TODO introduce messages in next version -->
Expand Down Expand Up @@ -120,6 +120,10 @@
type: Function, // ContentNode => Route
required: true,
},
loadingMoreState:{
type: Boolean,
default: false,
}
},
computed: {
showButton() {
Expand Down

0 comments on commit fd0b6d5

Please sign in to comment.