Skip to content

Commit

Permalink
PR updates to address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
marcellamaki committed Aug 15, 2023
1 parent 9ca1d20 commit 6a2447d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { set } from '@vueuse/core';
import redirectBrowser from 'kolibri.utils.redirectBrowser';
import urls from 'kolibri.urls';
import client from 'kolibri.client';
import Vue from 'kolibri.lib.vue';

const downloadRequestsTranslator = createTranslator('DownloadRequests', {
downloadStartedLabel: {
Expand All @@ -35,11 +36,9 @@ export default function useDownloadRequests(store) {
function fetchUserDownloadRequests(params) {
return ContentRequestResource.list(params)
.then(downloadRequests => {
const downloads = downloadRequests.reduce((acc, obj) => {
acc[obj.id] = obj;
return acc;
}, {});
set(downloadRequestMap, downloads);
for (const obj of downloadRequests) {
set(downloadRequestMap, obj.id, obj);
}
set(loading, false);
})
.then(store.dispatch('notLoading'));
Expand Down Expand Up @@ -99,16 +98,7 @@ export default function useDownloadRequests(store) {
id: content.id,
contentnode_id: content.contentnode_id,
});
return Promise.resolve();
}

function removeDownloadsRequest(contentList) {
contentList.forEach(content => {
ContentRequestResource.deleteModel({
id: content.id,
contentnode_id: content.contentnode_id,
});
});
Vue.delete(downloadRequestMap, content.id);
return Promise.resolve();
}

Expand Down Expand Up @@ -136,7 +126,6 @@ export default function useDownloadRequests(store) {
addDownloadRequest,
loading,
removeDownloadRequest,
removeDownloadsRequest,
downloadRequestsTranslator,
isDownloadingByLearner,
isDownloadedByLearner,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,18 @@
const activityType = computed(() => query.value.activity || 'all');
const downloads = ref([]);
const sortedFilteredDownloads = () => {
let downloadsToDisplay = [];
let downloadsToDisplay = Object.values(downloadRequestMap || {});
if (downloadRequestMap) {
for (const [, value] of Object.entries(downloadRequestMap.value)) {
for (const [, value] of Object.entries(downloadRequestMap)) {
downloadsToDisplay.push(value);
}
if (activityType) {
if (activityType.value !== 'all') {
downloadsToDisplay = downloadsToDisplay.filter(download =>
download.metadata.learning_activities.includes(activityType.value)
);
}
}
if (sort) {
switch (sort.value) {
case 'newest':
Expand All @@ -169,13 +176,6 @@
break;
}
}
if (activityType) {
if (activityType.value !== 'all') {
downloadsToDisplay = downloadsToDisplay.filter(download =>
download.metadata.learning_activities.includes(activityType.value)
);
}
}
}
set(totalPageNumber, Math.ceil(downloadsToDisplay.length / pageSizeNumber.value));
set(downloads, downloadsToDisplay);
Expand Down Expand Up @@ -295,10 +295,8 @@
},
removeResources() {
this.$emit('removeResources', this.resourcesToDelete);
this.selectedDownloads = this.selectedDownloads.filter(
resourceId => !this.resourcesToDelete.includes(resourceId)
);
this.resourcesToDelete = [];
this.sortedFilteredDownloads();
},
getIcon(activities) {
return this.getLearningActivityIcon(activities);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,12 @@

<script>
import { get, set } from '@vueuse/core';
import { get } from '@vueuse/core';
import bytesForHumans from 'kolibri.utils.bytesForHumans';
import AppBarPage from 'kolibri.coreVue.components.AppBarPage';
import { computed, getCurrentInstance, watch, ref } from 'kolibri.lib.vueCompositionApi';
import commonCoreStrings from 'kolibri.coreVue.mixins.commonCoreStrings';
import responsiveWindowMixin from 'kolibri.coreVue.mixins.responsiveWindowMixin';
import Vue from 'kolibri.lib.vue';
import useDownloadRequests from '../../composables/useDownloadRequests';
import DownloadsList from './DownloadsList';
import ActivityFilter from './Filters/ActivityFilter.vue';
Expand All @@ -81,7 +80,6 @@
fetchAvailableFreespace,
availableSpace,
removeDownloadRequest,
removeDownloadsRequest,
} = useDownloadRequests();
const store = getCurrentInstance().proxy.$store;
Expand All @@ -105,9 +103,6 @@
fetchDownloads();
fetchAvailableFreespace();
watch(route, fetchDownloads);
watch(downloadRequestMap, () => {
set(totalPageNumber, downloadRequestMap.totalPageNumber);
});
return {
downloadRequestMap,
Expand All @@ -117,19 +112,14 @@
fetchAvailableFreespace,
sort,
removeDownloadRequest,
removeDownloadsRequest,
};
},
computed: {
sizeOfMyDownloads() {
let size;
if (this.downloadRequestMap && this.downloadRequestMap.value) {
size = Object.values(this.downloadRequestMap.value).reduce(
(acc, object) => acc + object.metadata.file_size,
0
);
}
return size;
return Object.values(this.downloadRequestMap).reduce(
(acc, object) => acc + object.metadata.file_size,
0
);
},
},
methods: {
Expand All @@ -143,11 +133,9 @@
removeResources(resources) {
if (resources.length === 1) {
this.removeDownloadRequest(resources[0]);
Vue.delete(this.downloadRequestMap.value, resources[0].id);
} else {
resources.map(resource => {
this.removeDownloadsRequest({ id: resource.id });
Vue.delete(this.downloadRequestMap.value, resource.id);
resources.forEach(resource => {
this.removeDownloadRequest({ id: resource.id });
});
}
},
Expand Down

0 comments on commit 6a2447d

Please sign in to comment.