Skip to content

Commit

Permalink
navigates to previous route
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanOXDi committed Feb 6, 2025
1 parent b27e41f commit f19ef0b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { ref } from 'vue';
import { ref, getCurrentInstance } from 'vue';
import ContentNodeResource from 'kolibri-common/apiResources/ContentNodeResource';

export default function useFetchContentNode(contentId) {
const contentNode = ref({});
const ancestors = ref([]);
const questions = ref([]);
const loading = ref(true);
const store = getCurrentInstance().proxy.$store;

const fetchContentNode = async () => {
ContentNodeResource.fetchModel({
Expand All @@ -25,7 +26,7 @@ export default function useFetchContentNode(contentId) {
}
})
.catch(error => {
this.$store.dispatch('handleApiError', { error });
store.dispatch('handleApiError', { error });
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

<div>
<div class="channel-header">
<div>
<h6>
{{ coreString('selectFromChannels') }}
</h6>
</div>
<p>
{{ coreString('selectFromChannels') }}
</p>

<div>
<template v-if="isSelected">
Expand Down Expand Up @@ -34,21 +32,18 @@
:ancestors="[...ancestors, currentContentNode]"
:channelsLink="channelsLink"
:topicsLink="topicsLink"
class="align-breadcrumbs"
/>

<div class="title-class">
<h5>
<KLabeledIcon :label="currentContentNode.kind">
<template #icon>
<LearningActivityIcon :kind="learningActivities" />
</template>
<template>
{{ currentContentNode.title }}
</template>
</KLabeledIcon>
</h5>
</div>
<h2>
<KLabeledIcon :label="currentContentNode.kind">
<template #icon>
<LearningActivityIcon :kind="learningActivities" />
</template>
<template>
{{ currentContentNode.title }}
</template>
</KLabeledIcon>
</h2>

<ContentArea
:header="questionLabel(selectedQuestionIndex)"
Expand Down Expand Up @@ -128,6 +123,7 @@
licenseDataHeader$,
addedIndicator$,
notAvailableLabel$,
minutes$,
} = searchAndFilterStrings;
return {
Expand All @@ -136,6 +132,7 @@
copyrightHolderDataHeader$,
addedIndicator$,
notAvailableLabel$,
minutes$,
};
},
props: {
Expand Down Expand Up @@ -223,14 +220,7 @@
this.$emit('removeResource', this.currentContentNode);
},
getTime(seconds) {
return this.$tr('minutes', { value: Math.floor(seconds / 60) });
},
},
$trs: {
minutes: {
message: '{value, number, integer} {value, plural, one {minute} other {minutes}}',
context:
'Indicates time spent by learner on a specific activity. Only translate minute/minutes.',
return this.minutes$({ value: Math.floor(seconds / 60) });
},
},
};
Expand All @@ -241,12 +231,11 @@
<style lang="scss" scoped>
.license-detail-style {
margin: 30px 0 32px;
margin-top: 10px;
}
/deep/ .content-renderer {
position: relative;
top: -40px;
max-height: 500px;
}
Expand All @@ -256,14 +245,8 @@
justify-content: space-between;
}
.title-class {
position: relative;
top: -30px;
}
.align-breadcrumbs {
position: relative;
top: -35px;
.channel-header p {
font-weight: 600;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

<script>
import { getCurrentInstance, ref } from 'vue';
import commonCoreStrings from 'kolibri/uiText/commonCoreStrings';
import useFetchContentNode from '../../../../../../../composables/useFetchContentNode';
import { coachStrings } from '../../../../../../common/commonCoachStrings';
Expand All @@ -31,17 +32,32 @@
},
mixins: [commonCoreStrings],
setup(props) {
const previousRoute = ref(null);
const instance = getCurrentInstance();
const { contentNode, ancestors, questions, loading } = useFetchContentNode(props.contentId);
const { manageLessonResourcesTitle$ } = coachStrings;
props.setTitle(manageLessonResourcesTitle$());
props.setGoBack(null);
const routeBack = () => {
const backRoute = previousRoute.value?.name
? previousRoute.value
: {
name: PageNames.LESSON_SELECT_RESOURCES_INDEX,
};
instance.proxy.$router.push(backRoute);
};
return {
contentNode,
ancestors,
questions,
loading,
routeBack,
// eslint-disable-next-line vue/no-unused-properties
previousRoute,
};
},
props: {
Expand Down Expand Up @@ -69,24 +85,20 @@
}
return false;
},
routeBack() {
const { params, query } = this.$route;
return {
name: PageNames.LESSON_SELECT_RESOURCES_TOPIC_TREE,
params: params,
query: query,
};
},
},
beforeRouteEnter(to, from, next) {
next(vm => {
vm.previousRoute = from;
});
},
methods: {
handleAddResource(content) {
this.routeBack;
this.routeBack();
this.$emit('selectResources', [content]);
this.showSnackbarNotification('resourcesAddedWithCount', { count: 1 });
},
handleRemoveResource(content) {
this.routeBack();
this.$emit('deselectResources', [content]);
this.showSnackbarNotification('resourcesRemovedWithCount', { count: 1 });
},
},
};
Expand Down
5 changes: 5 additions & 0 deletions packages/kolibri-common/strings/searchAndFilterStrings.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,9 @@ export const searchAndFilterStrings = createTranslator('SearchAndFilterStrings',
message: 'Not available',
context: 'Message that shows when the value of key is null',
},
minutes: {
message: '{value, number, integer} {value, plural, one {minute} other {minutes}}',
context:
'Indicates time spent by learner on a specific activity. Only translate minute/minutes.',
},
});

0 comments on commit f19ef0b

Please sign in to comment.