Skip to content

Commit e1b72fc

Browse files
authored
Merge pull request #1899 from DXCanas/mobile-cards-carousel
Mobile cards carousel
2 parents bfaba16 + 3e4c77a commit e1b72fc

File tree

4 files changed

+80
-34
lines changed

4 files changed

+80
-34
lines changed

kolibri/core/assets/src/mixins/responsive-window.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ function addWindowListener(cb) {
160160
}
161161

162162
function removeWindowListener(cb) {
163-
windowListeners.pop(cb);
163+
windowListeners.splice(windowListeners.indexOf(cb), 1);
164164
}
165165

166166
/* setup */

kolibri/plugins/learn/assets/src/views/content-card-carousel/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@
8282
const gutterWidth = 20;
8383
8484
export default {
85-
mixins: [responsiveElement],
8685
name: 'contentCardCarousel',
86+
mixins: [responsiveElement],
8787
$trs: { viewAllButtonLabel: 'View all' },
8888
props: {
8989
contents: {

kolibri/plugins/learn/assets/src/views/content-card/index.vue

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<template>
22

3-
<router-link :to="link" class="card" :style="cardHeight">
3+
<router-link :to="link" class="card">
44

5-
<div class="card-thumbnail" :style="backgroundImg">
5+
<div class="card-thumbnail" :style="cardThumbnail">
66
<content-icon v-if="!thumbnail" :kind="kind" :style="iconSize" class="card-thumbnail-backup"/>
77
<div v-show="progress > 0" class="card-progress-icon-wrapper">
88
<progress-icon :progress="progress"/>
@@ -85,28 +85,26 @@
8585
mastered() {
8686
return this.progress === 1;
8787
},
88-
cardHeight() {
89-
// set here so that parent component can set width and have height dynamically calculated
90-
return {
91-
height: `${this.elSize.width}px`,
92-
};
88+
thumbnailHeight() {
89+
return this.elSize.width * (9 / 16);
9390
},
9491
iconSize() {
95-
const cardHeight = this.elSize.width; // can use height or width because it's a square
9692
// maintain the thumbnail 16:9 ratio
97-
const thumbnailHeight = this.elSize.width * (9 / 16);
9893
return {
99-
'font-size': `${thumbnailHeight / 2}px`,
94+
'font-size': `${this.thumbnailHeight / 2}px`,
10095
};
10196
},
10297
inProgress() {
10398
return this.progress > 0 && this.progress < 1;
10499
},
105-
backgroundImg() {
100+
cardThumbnail() {
101+
const thumbnailStyles = {
102+
height: `${this.thumbnailHeight}px`,
103+
};
106104
if (this.thumbnail) {
107-
return { backgroundImage: `url('${this.thumbnail}')` };
105+
thumbnailStyles.backgroundImage = `url('${this.thumbnail}')`;
108106
}
109-
return {};
107+
return thumbnailStyles;
110108
},
111109
backgroundClass() {
112110
if (this.kind === 'exercise') {
@@ -138,8 +136,7 @@
138136
139137
$card-width = 210px
140138
$card-thumbnail-ratio = (9 / 16)
141-
$card-thumbnail-height = 100% * $card-thumbnail-ratio
142-
$card-text-height = $card-width - $card-thumbnail-height
139+
$card-text-height = $card-width - ($card-width * $card-thumbnail-ratio)
143140
$card-text-padding = ($card-width / (320 / 24))
144141
$card-elevation-resting = 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 3px 1px -2px rgba(0, 0, 0, 0.2), 0 1px 5px 0 rgba(0, 0, 0, 0.12)
145142
$card-elevation-raised = 0 8px 10px 1px rgba(0, 0, 0, 0.14), 0 3px 14px 2px rgba(0, 0, 0, 0.12), 0 5px 5px -3px rgba(0, 0, 0, 0.2)
@@ -161,7 +158,6 @@
161158
.card-thumbnail
162159
position: relative
163160
width: 100%
164-
height: $card-thumbnail-height
165161
background-size: cover
166162
background-position: center
167163
background-color: $core-grey

kolibri/plugins/learn/assets/src/views/learn-page/index.vue

Lines changed: 66 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,38 @@
44
<page-header :title="$tr('pageHeader')">
55
<mat-svg slot="icon" category="action" name="home"/>
66
</page-header>
7-
<content-card-carousel
8-
v-if="recommendations.resume.length"
7+
<component
8+
v-if="trimmedResume.length"
9+
:is="recommendationDisplay"
910
:gen-link="genLink"
10-
:contents="recommendations.resume"
11+
:contents="trimmedResume"
1112
:header="$tr('resumeSectionHeader')"
12-
:subheader="$tr('resumeSectionSubHeader', {numOfItems: recommendations.resume.length})"/>
13-
<content-card-carousel
14-
v-if="recommendations.nextSteps.length"
13+
:filter="false"
14+
:subheader="$tr('resumeSectionSubHeader', {numOfItems: trimmedResume.length})"/>
15+
<component
16+
v-if="trimmedNextSteps.length"
17+
:is="recommendationDisplay"
1518
:gen-link="genLink"
16-
:contents="recommendations.nextSteps"
19+
:contents="trimmedNextSteps"
1720
:header="$tr('suggestedNextStepsSectionHeader')"
18-
:subheader="$tr('suggestedNextStepsSectionSubHeader', {numOfItems: recommendations.nextSteps.length})"/>
19-
<content-card-carousel
20-
v-if="recommendations.popular.length"
21+
:filter="false"
22+
:subheader="$tr('suggestedNextStepsSectionSubHeader', {numOfItems: trimmedNextSteps.length})"/>
23+
<component
24+
v-if="trimmedPopular.length"
25+
:is="recommendationDisplay"
2126
:gen-link="genLink"
22-
:contents="recommendations.popular"
27+
:contents="trimmedPopular"
2328
:header="$tr('popularSectionHeader')"
24-
:subheader="$tr('popularSectionSubHeader', {numOfItems: recommendations.popular.length})"/>
25-
<content-card-carousel
26-
v-if="all.content.length"
29+
:filter="false"
30+
:subheader="$tr('popularSectionSubHeader', {numOfItems: trimmedPopular.length})"/>
31+
<component
32+
v-if="trimmedOverview.length"
33+
:is="recommendationDisplay"
2734
:showViewAll="true"
2835
:gen-link="genLink"
2936
:header="$tr('overviewSectionHeader')"
30-
:contents="all.content" />
37+
:filter="false"
38+
:contents="trimmedOverview" />
3139
</div>
3240

3341
</template>
@@ -39,8 +47,13 @@
3947
import { getCurrentChannelObject } from 'kolibri.coreVue.vuex.getters';
4048
import pageHeader from '../page-header';
4149
import contentCardCarousel from '../content-card-carousel';
50+
import contentCardGrid from '../content-card-grid';
51+
import responsiveWindow from 'kolibri.coreVue.mixins.responsiveWindow';
52+
53+
const mobileCardNumber = 3;
54+
4255
export default {
43-
$trNameSpace: 'learnPageIndex',
56+
name: 'recommendedPage',
4457
$trs: {
4558
pageHeader: 'Recommended',
4659
popularSectionHeader: 'Most popular',
@@ -51,9 +64,46 @@
5164
resumeSectionSubHeader: '{numOfItems, number} items to be resumed',
5265
overviewSectionHeader: 'Overview',
5366
},
67+
mixins: [responsiveWindow],
5468
components: {
5569
pageHeader,
5670
contentCardCarousel,
71+
contentCardGrid,
72+
},
73+
computed: {
74+
isMobile() {
75+
return this.windowSize.breakpoint <= 2;
76+
},
77+
recommendationDisplay() {
78+
if (this.isMobile) {
79+
return contentCardGrid;
80+
}
81+
return contentCardCarousel;
82+
},
83+
trimmedResume() {
84+
if (this.isMobile) {
85+
return this.recommendations.resume.slice(0, mobileCardNumber);
86+
}
87+
return this.recommendations.resume;
88+
},
89+
trimmedNextSteps() {
90+
if (this.isMobile) {
91+
return this.recommendations.nextSteps.slice(0, mobileCardNumber);
92+
}
93+
return this.recommendations.nextSteps;
94+
},
95+
trimmedPopular() {
96+
if (this.isMobile) {
97+
return this.recommendations.popular.slice(0, mobileCardNumber);
98+
}
99+
return this.recommendations.popular;
100+
},
101+
trimmedOverview() {
102+
if (this.isMobile) {
103+
return this.all.content.slice(0, mobileCardNumber);
104+
}
105+
return this.all.content;
106+
},
57107
},
58108
methods: {
59109
genLink(id, kind) {

0 commit comments

Comments
 (0)