Skip to content

Commit

Permalink
Merge pull request #9063 from marcellamaki/refactor-hybrid-learning-c…
Browse files Browse the repository at this point in the history
…ard-grid

Refactor hybrid learning card grid
  • Loading branch information
marcellamaki authored Mar 1, 2022
2 parents fd82aa8 + 83dfbaf commit 1fd1fc0
Show file tree
Hide file tree
Showing 6 changed files with 309 additions and 74 deletions.
39 changes: 25 additions & 14 deletions kolibri/plugins/learn/assets/src/views/BookmarkPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@
{{ $tr('noBookmarks') }}
</p>

<HybridLearningCardGrid
v-if="bookmarks.length"
:contents="bookmarks"
:currentPage="currentPage"
:genContentLink="genContentLink"
:cardViewStyle="windowIsSmall ? 'card' : 'list'"
<HybridLearningContentCardListView
v-for="content in bookmarks"
v-else
:key="content.id"
:content="content"
class="card-grid-item"
:isMobile="windowIsSmall"
:link="genContentLink(content)"
:footerIcons="footerIcons"
@removeFromBookmarks="removeFromBookmarks"
@toggleInfoPanel="toggleInfoPanel"
:createdDate="content.bookmark ? content.bookmark.created : null"
@viewInformation="toggleInfoPanel(content)"
@removeFromBookmarks="removeFromBookmarks(content.bookmark)"
/>

<KButton
Expand Down Expand Up @@ -78,11 +81,11 @@
import client from 'kolibri.client';
import urls from 'kolibri.urls';
import genContentLink from '../utils/genContentLink';
import { PageNames } from '../constants';
import { normalizeContentNode } from '../modules/coreLearn/utils.js';
import useContentNodeProgress from '../composables/useContentNodeProgress';
import LearningActivityChip from './LearningActivityChip';
import HybridLearningCardGrid from './HybridLearningCardGrid';
import HybridLearningContentCardListView from './HybridLearningContentCardListView';
import BrowseResourceMetadata from './BrowseResourceMetadata';
export default {
Expand All @@ -96,7 +99,7 @@
BrowseResourceMetadata,
FullScreenSidePanel,
LearningActivityChip,
HybridLearningCardGrid,
HybridLearningContentCardListView,
},
mixins: [commonCoreStrings, responsiveWindowMixin],
setup() {
Expand All @@ -115,8 +118,8 @@
footerIcons() {
return { infoOutline: 'viewInformation', close: 'removeFromBookmarks' };
},
currentPage() {
return PageNames.BOOKMARKS;
backRoute() {
return this.$route.name;
},
},
created() {
Expand All @@ -129,7 +132,15 @@
},
methods: {
...mapActions(['createSnackbar']),
genContentLink,
genContentLink(content) {
return genContentLink(
content.id,
this.topicId,
content.is_leaf,
this.backRoute,
this.context
);
},
loadMore() {
if (!this.loading) {
this.loading = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<template>

<div>
<!-- small and xs displays -->
<CardGrid v-if="windowIsSmall" data-test="mobile-card-grid">
<ResourceCard
v-for="(content, idx) in contents"
:key="`resource-${idx}`"
:data-test="'resource-card-' + idx"
:contentNode="content"
:to="genContentLink(content)"
@openCopiesModal="$emit('openCopiesModal', content.copies)"
/>
</CardGrid>
<!-- large displays, card view -->
<CardGrid
v-else-if="!windowIsSmall && currentCardViewStyle === 'card'"
:gridType="gridType"
data-test="non-mobile-card-grid"
>
<HybridLearningContentCard
v-for="(content, idx) in contents"
:key="`resource-${idx}`"
class="card-grid-item"
:data-test="'content-card-' + idx"
:isMobile="windowIsSmall"
:content="content"
:link="genContentLink(content)"
@openCopiesModal="$emit('openCopiesModal', content.copies)"
@toggleInfoPanel="$emit('toggleInfoPanel', content)"
/>
</CardGrid>
<!-- large displays, list view -->
<HybridLearningContentCardListView
v-for="content in contents"
v-else-if="!windowIsSmall && currentCardViewStyle === 'list'"
:key="content.id"
:content="content"
class="card-grid-item"
:data-test="'card-list-view-' + idx"
:link="genContentLink(content)"
:footerIcons="footerIcons"
:createdDate="content.bookmark ? content.bookmark.created : null"
@openCopiesModal="$emit('openCopiesModal', content.copies)"
@viewInformation="$emit('toggleInfoPanel', content)"
@removeFromBookmarks="$emit('removeFromBookmarks',content, contents)"
/>
</div>

</template>


<script>
import responsiveWindowMixin from 'kolibri.coreVue.mixins.responsiveWindowMixin';
import genContentLink from '../utils/genContentLink';
import CardGrid from './cards/CardGrid';
import ResourceCard from './cards/ResourceCard';
import HybridLearningContentCard from './HybridLearningContentCard';
import HybridLearningContentCardListView from './HybridLearningContentCardListView';
export default {
name: 'LibraryAndChannelBrowserMainContent',
components: {
CardGrid,
HybridLearningContentCard,
HybridLearningContentCardListView,
ResourceCard,
},
mixins: [responsiveWindowMixin],
props: {
contents: {
type: Array,
required: true,
},
currentCardViewStyle: {
type: String,
required: true,
default: 'card',
validator(value) {
return ['card', 'list'].includes(value);
},
},
// Used to define the "type" (number of columns) for <CardGrid />
// Currently only either `1` or `2`
// See props in CardGrid.vue for more details on # of cards per level
gridType: {
type: Number,
required: true,
default: 1,
},
},
computed: {
footerIcons() {
return { info: 'viewInformation' };
},
backRoute() {
return this.$route.name;
},
},
methods: {
genContentLink(content) {
return genContentLink(
content.id,
this.topicId,
content.is_leaf,
this.backRoute,
this.context
);
},
},
};
</script>
87 changes: 43 additions & 44 deletions kolibri/plugins/learn/assets/src/views/LibraryPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,30 @@
:ariaLabel="$tr('viewAsList')"
:color="$themeTokens.text"
:tooltip="$tr('viewAsList')"
:disabled="currentViewStyle === 'list'"
:disabled="currentCardViewStyle === 'list'"
@click="toggleCardView('list')"
/>
<KIconButton
icon="channel"
:ariaLabel="$tr('viewAsGrid')"
:color="$themeTokens.text"
:tooltip="$tr('viewAsGrid')"
:disabled="currentViewStyle === 'card'"
:disabled="currentCardViewStyle === 'card'"
@click="toggleCardView('card')"
/>
</div>
<h2 v-if="resumableContentNodes.length">
{{ $tr('recent') }}
</h2>
<HybridLearningCardGrid
v-if="resumableContentNodes.length"
:cardViewStyle="currentViewStyle"
:numCols="numCols"
:genContentLink="genContentLink"
:contents="trimmedResume"
:footerIcons="footerIcons"
:currentPage="currentPage"
@toggleInfoPanel="toggleInfoPanel"
/>
<div v-if="resumableContentNodes.length">
<h2>
{{ $tr('recent') }}
</h2>
<LibraryAndChannelBrowserMainContent
:contents="resumableContentNodes"
:currentCardViewStyle="currentCardViewStyle"
:gridType="1"
@openCopiesModal="openCopiesModal"
@toggleInfoPanel="toggleInfoPanel"
/>
</div>
<KButton
v-if="moreResumableContentNodes"
appearance="basic-link"
Expand All @@ -81,15 +80,15 @@
:ariaLabel="$tr('viewAsList')"
:color="$themeTokens.text"
:tooltip="$tr('viewAsList')"
:disabled="currentViewStyle === 'list'"
:disabled="currentCardViewStyle === 'list'"
@click="toggleCardView('list')"
/>
<KIconButton
icon="channel"
:ariaLabel="$tr('viewAsGrid')"
:color="$themeTokens.text"
:tooltip="$tr('viewAsGrid')"
:disabled="currentViewStyle === 'card'"
:disabled="currentCardViewStyle === 'card'"
@click="toggleCardView('card')"
/>
</div>
Expand All @@ -99,14 +98,11 @@
@clearSearch="clearSearch"
/>
<!-- Grid of search results -->
<HybridLearningCardGrid
v-if="results.length"
:numCols="numCols"
:cardViewStyle="currentViewStyle"
:genContentLink="genContentLink"
<LibraryAndChannelBrowserMainContent
:contents="results"
:footerIcons="footerIcons"
:currentPage="currentPage"
:currentCardViewStyle="currentCardViewStyle"
:gridType="1"
@openCopiesModal="openCopiesModal"
@toggleInfoPanel="toggleInfoPanel"
/>
<!-- conditionally displayed button if there are additional results -->
Expand Down Expand Up @@ -197,6 +193,13 @@
@input="handleCategory"
/>

<CopiesModal
v-if="displayedCopies.length"
:copies="displayedCopies"
:genContentLink="genContentLink"
@submit="displayedCopies = []"
/>

<FullScreenSidePanel
v-if="sidePanelContent"
alignment="right"
Expand Down Expand Up @@ -245,21 +248,18 @@
import FilterTextbox from 'kolibri.coreVue.components.FilterTextbox';
import { crossComponentTranslator } from 'kolibri.utils.i18n';
import genContentLink from '../utils/genContentLink';
import { PageNames } from '../constants';
import useSearch from '../composables/useSearch';
import useLearnerResources from '../composables/useLearnerResources';
import BrowseResourceMetadata from './BrowseResourceMetadata';
import commonLearnStrings from './commonLearnStrings';
import ChannelCardGroupGrid from './ChannelCardGroupGrid';
import LearningActivityChip from './LearningActivityChip';
import HybridLearningCardGrid from './HybridLearningCardGrid';
import LibraryAndChannelBrowserMainContent from './LibraryAndChannelBrowserMainContent';
import CopiesModal from './CopiesModal';
import EmbeddedSidePanel from './EmbeddedSidePanel';
import CategorySearchModal from './CategorySearchModal';
import SearchChips from './SearchChips';
const mobileCarouselLimit = 3;
const desktopCarouselLimit = 15;
export default {
name: 'LibraryPage',
metaInfo() {
Expand All @@ -268,14 +268,15 @@
};
},
components: {
HybridLearningCardGrid,
LibraryAndChannelBrowserMainContent,
ChannelCardGroupGrid,
LearningActivityChip,
EmbeddedSidePanel,
FullScreenSidePanel,
CategorySearchModal,
BrowseResourceMetadata,
SearchChips,
CopiesModal,
},
mixins: [commonLearnStrings, commonCoreStrings, responsiveWindowMixin],
setup() {
Expand Down Expand Up @@ -318,27 +319,16 @@
},
data: function() {
return {
currentViewStyle: 'card',
currentCardViewStyle: 'card',
currentCategory: null,
showSearchModal: false,
sidePanelIsOpen: false,
sidePanelContent: null,
displayedCopies: [],
};
},
computed: {
...mapState(['rootNodes']),
carouselLimit() {
return this.windowIsSmall ? mobileCarouselLimit : desktopCarouselLimit;
},
trimmedResume() {
return this.resumableContentNodes.slice(0, this.carouselLimit);
},
currentPage() {
return PageNames.LIBRARY;
},
footerIcons() {
return { infoOutline: 'viewInformation' };
},
sidePanelWidth() {
if (this.windowIsSmall || this.windowIsMedium) {
return 0;
Expand Down Expand Up @@ -407,8 +397,11 @@
this.showSearchModal = true;
!(this.windowIsSmall || this.windowIsMedium) ? (this.sidePanelIsOpen = false) : '';
},
openCopiesModal(copies) {
this.displayedCopies = copies;
},
toggleCardView(value) {
this.currentViewStyle = value;
this.currentCardViewStyle = value;
},
toggleSidePanelVisibility() {
this.sidePanelIsOpen = !this.sidePanelIsOpen;
Expand Down Expand Up @@ -474,6 +467,12 @@
margin-right: 24px;
}
$gutters: 24px;
.card-grid-item {
margin-bottom: $gutters;
}
.loader {
margin-top: 60px;
}
Expand Down
Loading

0 comments on commit 1fd1fc0

Please sign in to comment.