-
Notifications
You must be signed in to change notification settings - Fork 743
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
Integrate shopping cart into lesson resource selection side panel #12996
Changes from all commits
cc50a0a
e80d354
d6ab330
4a3d32b
78414b6
c89b9f8
12467f4
85a925d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -196,6 +196,7 @@ | |
.content-list { | ||
display: block; | ||
padding: 0; | ||
margin: 0; | ||
list-style: none; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -26,11 +26,14 @@ | |||
:setTitle="setTitle" | ||||
:setGoBack="setGoBack" | ||||
:topic="topic" | ||||
:disabled="isSaving" | ||||
AlexVelezLl marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
:channelsFetch="channelsFetch" | ||||
:bookmarksFetch="bookmarksFetch" | ||||
:treeFetch="treeFetch" | ||||
:selectionRules="selectionRules" | ||||
:selectedResources="selectedResources" | ||||
:unselectableResourceIds="unselectableResourceIds" | ||||
:selectedResourcesSize="selectedResourcesSize" | ||||
@selectResources="selectResources" | ||||
@deselectResources="deselectResources" | ||||
@setSelectedResources="setSelectedResources" | ||||
|
@@ -40,29 +43,50 @@ | |||
<div class="bottom-nav-container"> | ||||
<KButtonGroup> | ||||
<KRouterLink | ||||
v-if="selectedResources.length > 0" | ||||
v-if=" | ||||
selectedResources.length > 0 && | ||||
$route.name !== PageNames.LESSON_PREVIEW_SELECTED_RESOURCES | ||||
AlexVelezLl marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
" | ||||
:to="{ name: PageNames.LESSON_PREVIEW_SELECTED_RESOURCES }" | ||||
> | ||||
{{ selectedResourcesMessage }} | ||||
</KRouterLink> | ||||
<KButton | ||||
primary | ||||
:disabled="isSaving" | ||||
:text="saveAndFinishAction$()" | ||||
@click="closeSidePanel" | ||||
@click="save" | ||||
/> | ||||
</KButtonGroup> | ||||
</div> | ||||
</template> | ||||
|
||||
<KModal | ||||
v-if="isCloseConfirmationModalOpen" | ||||
appendToOverlay | ||||
:submitText="continueAction$()" | ||||
:cancelText="cancelAction$()" | ||||
:title="closeConfirmationTitle$()" | ||||
@cancel="isCloseConfirmationModalOpen = false" | ||||
@submit="closeSidePanel(false)" | ||||
> | ||||
{{ closeConfirmationMessage$() }} | ||||
</KModal> | ||||
</SidePanelModal> | ||||
|
||||
</template> | ||||
|
||||
|
||||
<script> | ||||
|
||||
import uniqBy from 'lodash/uniqBy'; | ||||
import { mapState, mapActions, mapMutations } from 'vuex'; | ||||
|
||||
import SidePanelModal from 'kolibri-common/components/SidePanelModal'; | ||||
import notificationStrings from 'kolibri/uiText/notificationStrings'; | ||||
import { coreStrings } from 'kolibri/uiText/commonCoreStrings'; | ||||
import bytesForHumans from 'kolibri/uiText/bytesForHumans'; | ||||
import useSnackbar from 'kolibri/composables/useSnackbar'; | ||||
import { PageNames } from '../../../../../constants'; | ||||
import { coachStrings } from '../../../../common/commonCoachStrings'; | ||||
import useResourceSelection from '../../../../../composables/useResourceSelection'; | ||||
|
@@ -86,7 +110,18 @@ | |||
setSelectedResources, | ||||
} = useResourceSelection(); | ||||
|
||||
const { saveAndFinishAction$ } = coreStrings; | ||||
const { createSnackbar } = useSnackbar(); | ||||
|
||||
const { resourcesAddedWithCount$ } = notificationStrings; | ||||
function notifyResourcesAdded(count) { | ||||
createSnackbar(resourcesAddedWithCount$({ count })); | ||||
} | ||||
const { saveLessonError$, closeConfirmationTitle$, closeConfirmationMessage$ } = coachStrings; | ||||
function notifySaveLessonError() { | ||||
createSnackbar(saveLessonError$()); | ||||
} | ||||
|
||||
const { saveAndFinishAction$, continueAction$, cancelAction$ } = coreStrings; | ||||
|
||||
return { | ||||
loading, | ||||
|
@@ -99,18 +134,27 @@ | |||
selectResources, | ||||
deselectResources, | ||||
setSelectedResources, | ||||
notifyResourcesAdded, | ||||
notifySaveLessonError, | ||||
cancelAction$, | ||||
continueAction$, | ||||
saveAndFinishAction$, | ||||
closeConfirmationTitle$, | ||||
closeConfirmationMessage$, | ||||
}; | ||||
}, | ||||
data() { | ||||
return { | ||||
title: '', | ||||
goBack: null, | ||||
isSaving: false, | ||||
isCloseConfirmationModalOpen: false, | ||||
PageNames, | ||||
}; | ||||
}, | ||||
computed: { | ||||
totalSize() { | ||||
...mapState('lessonSummary', ['currentLesson', 'workingResources']), | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, have we not migrated lesson editing over to using composition API for state? Are we updating the lessonSummary vuex whenever we edit things as well? cc @marcellamaki There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, thats why I had to call this And in the LessonSummaryPage, we also update this workingResources array when we remove a resource from the lesson kolibri/kolibri/plugins/coach/assets/src/views/lessons/LessonSummaryPage/index.vue Line 343 in 0b44855
|
||||
selectedResourcesSize() { | ||||
let size = 0; | ||||
this.selectedResources.forEach(resource => { | ||||
const { files = [] } = resource; | ||||
|
@@ -124,15 +168,74 @@ | |||
const { someResourcesSelected$ } = coachStrings; | ||||
return someResourcesSelected$({ | ||||
count: this.selectedResources.length, | ||||
bytesText: bytesForHumans(this.totalSize), | ||||
bytesText: bytesForHumans(this.selectedResourcesSize), | ||||
}); | ||||
}, | ||||
unselectableResourceIds() { | ||||
return this.workingResources.map(resource => resource.contentnode_id); | ||||
}, | ||||
}, | ||||
methods: { | ||||
closeSidePanel() { | ||||
this.$router.push({ | ||||
name: PageNames.LESSON_SUMMARY_BETTER, | ||||
}); | ||||
...mapActions('lessonSummary', ['saveLessonResources', 'addToResourceCache']), | ||||
...mapMutations('lessonSummary', { | ||||
setWorkingResources: 'SET_WORKING_RESOURCES', | ||||
}), | ||||
getNewResources() { | ||||
return uniqBy( | ||||
[ | ||||
...this.workingResources, | ||||
...this.selectedResources.map(resource => ({ | ||||
contentnode_id: resource.id, | ||||
content_id: resource.content_id, | ||||
channel_id: resource.channel_id, | ||||
})), | ||||
], | ||||
'contentnode_id', | ||||
); | ||||
}, | ||||
async save() { | ||||
if (!this.selectedResources.length) { | ||||
this.closeSidePanel(false); | ||||
return; | ||||
} | ||||
this.isSaving = true; | ||||
const newResources = this.getNewResources(); | ||||
|
||||
// As we are just adding resources, we can rely on the difference in length | ||||
// to determine if there are new resources to save. | ||||
const countNewResources = newResources.length - this.workingResources.length; | ||||
if (countNewResources > 0) { | ||||
try { | ||||
await this.saveLessonResources({ | ||||
lessonId: this.currentLesson.id, | ||||
resources: newResources, | ||||
}); | ||||
} catch (error) { | ||||
this.notifySaveLessonError(); | ||||
this.isSaving = false; | ||||
throw error; | ||||
} | ||||
for (const resource of this.selectedResources) { | ||||
this.addToResourceCache({ node: resource }); | ||||
} | ||||
this.setWorkingResources(newResources); | ||||
// Notify the lesson summary page that the working resources have been updated | ||||
// so that it can update the backup resources. | ||||
this.$emit('workingResourcesUpdated'); | ||||
this.notifyResourcesAdded(countNewResources); | ||||
} | ||||
this.closeSidePanel(false); | ||||
}, | ||||
closeSidePanel(verifyHasNewResources = true) { | ||||
const newResources = this.getNewResources(); | ||||
const hasNewResources = newResources.length > this.workingResources.length; | ||||
if (hasNewResources && verifyHasNewResources) { | ||||
this.isCloseConfirmationModalOpen = true; | ||||
} else { | ||||
this.$router.push({ | ||||
name: PageNames.LESSON_SUMMARY_BETTER, | ||||
}); | ||||
} | ||||
}, | ||||
setTitle(title) { | ||||
this.title = title; | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does adding the
.vue
suffix help with IDE file discovery? Just wondering if we should standardize on one way or the other. Our webpack config handles discovery of vue files without the extension, but maybe IDEs are not handling it as well?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, its just for VS Code. without it, VS Code expect it to be a
js
file, and therefore, it just dont find the file. Adding the.vue
let us navigate to the file just doing cntrl + click and It is much more comfortable. Although I haven't taken the time to investigate if I can configure VS Code for this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may also be influencing why this is not being supported vitejs/vite#178
Vite is also removing support for imports of vue components without the extension.
We are probably going to be better off bending with the wind!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree!