Skip to content

Commit

Permalink
add pagination in card view for project hub
Browse files Browse the repository at this point in the history
  • Loading branch information
khansadaoudi committed Dec 4, 2024
1 parent cd22b76 commit 1a787b7
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/pages/ProjectsHub.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,16 @@
</q-virtual-scroll>
<div v-if="!$q.platform.is.mobile" class="q-pa-md row q-gutter-md">
<ProjectCard
v-for="project in filteredProjects"
v-for="project in paginatedProjects"
:key="project.id"
style="max-width: 270px"
:style="`max-width: ${projectCardWidth}px;`"
:project="project"
:parent-delete-project="deleteProject"
></ProjectCard>
</div>
<div class="q-pa-lg flex flex-center">
<q-pagination v-model="pageIndex" :min="currentPage" :max="Math.ceil(filteredProjects.length / totalItemPerPageCardView)" :input="true" />
</div>
</q-card-section>
<!-- Here starts the list view -->
<q-card-section v-else>
Expand All @@ -123,7 +126,7 @@
</q-virtual-scroll>
</q-list>
<div class="q-pa-lg flex flex-center">
<q-pagination v-model="pageIndex" :min="currentPage" :max="Math.ceil(filteredProjects.length / totalItemPerPage)" :input="true" />
<q-pagination v-model="pageIndex" :min="currentPage" :max="Math.ceil(filteredProjects.length / totalItemPerPageListView)" :input="true" />
</div>
</q-card-section>
</q-card>
Expand Down Expand Up @@ -179,7 +182,9 @@ export default defineComponent({
ayear: -3600 * 24 * 365,
currentPage: 1,
pageIndex: 1,
totalItemPerPage: 10,
totalItemPerPageListView: 10,
totalItemPerPageCardView: 24,
projectCardWidth: 0,
selectedLanguagesForFilter: [],
projectsLanguages,
};
Expand Down Expand Up @@ -221,9 +226,10 @@ export default defineComponent({
}
},
paginatedProjects(): project_extended_t[] {
const totalItemPerPage = this.listMode ? this.totalItemPerPageListView : this.totalItemPerPageCardView;
return this.filteredProjects.slice(
(this.pageIndex - 1) * this.totalItemPerPage,
(this.pageIndex - 1) * this.totalItemPerPage + this.totalItemPerPage
(this.pageIndex - 1) * totalItemPerPage,
(this.pageIndex - 1) * totalItemPerPage + totalItemPerPage
);
},
},
Expand All @@ -246,6 +252,7 @@ export default defineComponent({
this.initLoading = true;
this.listMode = LocalStorage.getItem('project_view') || false;
this.getProjects();
this.projectCardWidth = Math.trunc(window.innerWidth / 7);
},
methods: {
...mapActions(useProjectStore, ['isMyProject', 'isOldProject', 'sortProjects']),
Expand Down

0 comments on commit 1a787b7

Please sign in to comment.