Skip to content

Commit

Permalink
sort project in my projects page
Browse files Browse the repository at this point in the history
  • Loading branch information
khansadaoudi committed Sep 12, 2024
1 parent 0c2145e commit d530e56
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/pages/MyProjects.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@
</q-page>
</template>
<script lang="ts">
import { mapState } from 'pinia';
import { mapState, mapActions } from 'pinia';
import { useUserStore } from 'src/pinia/modules/user';
import { useProjectStore } from 'src/pinia/modules/project';
import { notifyError, notifyMessage } from 'src/utils/notify';
import { project_extended_t } from 'src/api/backend-types';
import { defineComponent } from 'vue';
Expand All @@ -75,6 +76,7 @@ import api from 'src/api/backend-api';
import ProjectCard from 'src/components/project/ProjectCard.vue';
import CreaProjectCard from 'src/components/project/CreaProjectCard.vue';
export default defineComponent({
name: 'MyProjects',
components: {
Expand Down Expand Up @@ -111,12 +113,14 @@ export default defineComponent({
});
},
methods: {
...mapActions(useProjectStore, ['sortProjects']),
getUserProjects() {
api
.getUserProjects()
.then((response) => {
this.myProjects = response.data;
this.filteredProjects = this.myProjects;
this.sortProjects(this.filteredProjects);
})
.catch((error) => {
notifyError({ error: `Error happened while loading user projects ${error} `});
Expand Down
7 changes: 2 additions & 5 deletions src/pages/ProjectsHub.vue
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export default defineComponent({
this.getProjects();
},
methods: {
...mapActions(useProjectStore, ['isMyProject', 'isOldProject']),
...mapActions(useProjectStore, ['isMyProject', 'isOldProject', 'sortProjects']),
toggleProjectView() {
this.listMode = !this.listMode;
LocalStorage.set('project_view', this.listMode);
Expand All @@ -259,16 +259,13 @@ export default defineComponent({
this.projectsLanguages = [...new Set(this.projects.map((project) => project.language))]
.filter((language) => language !== '' && language !== null)
.map((language, i) => ({ index: i + 1, name: language }));
this.sortProjects();
this.sortProjects(this.visibleProjects)
this.initLoading = false;
})
.catch((error) => {
notifyError({ error });
});
},
sortProjects() {
this.visibleProjects.sort((a, b) => b.lastAccess - a.lastAccess);
},
deleteProject(projectName: string) {
api
.deleteProject(projectName)
Expand Down
3 changes: 3 additions & 0 deletions src/pinia/modules/project/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ export const useProjectStore = defineStore('project', {
const ayear = -3600 * 24 * 365;
return project.lastAccess < ayear || (project.numberSamples < 1 && project.lastAccess < -3600);
},
sortProjects(projects: project_extended_t[]) {
projects.sort((a, b) => b.lastAccess - a.lastAccess);
},
resetAnnotationFeaturesSUD(): void {
this.annotationFeatures = defaultState().annotationFeaturesSUD;
},
Expand Down

0 comments on commit d530e56

Please sign in to comment.