Skip to content
This repository has been archived by the owner on Aug 3, 2024. It is now read-only.

Commit

Permalink
sort by on user projects page
Browse files Browse the repository at this point in the history
  • Loading branch information
kohsine committed Jun 14, 2023
1 parent 177a487 commit d9b76c2
Showing 1 changed file with 65 additions and 2 deletions.
67 changes: 65 additions & 2 deletions pages/user/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,29 @@
</a>
</template>
</div>
<div class="card search-controls">
<div class="sort-controls">
<div class="labeled-control">
<span class="labeled-control__label">Sort by</span>
<Multiselect
v-model="sortType"
placeholder="Select one"
class="search-controls__sorting labeled-control__control"
track-by="display"
label="display"
:options="sortTypes"
:searchable="false"
:close-on-select="true"
:show-labels="false"
:allow-empty="false"
>
<template #singleLabel="{ option }">
{{ option.display }}
</template>
</Multiselect>
</div>
</div>
</div>
</div>
<div class="normal-page__content">
<Promotion />
Expand Down Expand Up @@ -195,7 +218,7 @@
: projects
)
.slice()
.sort((a, b) => b.downloads - a.downloads)"
.sort(sortProjects)"
:id="project.slug || project.id"
:key="project.id"
:name="project.title"
Expand Down Expand Up @@ -238,6 +261,7 @@
</div>
</template>
<script setup>
import { Multiselect } from 'vue-multiselect'
import ProjectCard from '~/components/ui/ProjectCard.vue'
import Badge from '~/components/ui/Badge.vue'
import Promotion from '~/components/ads/Promotion.vue'
Expand Down Expand Up @@ -266,6 +290,13 @@ import Avatar from '~/components/ui/Avatar.vue'
const data = useNuxtApp()
const route = useRoute()
const sortTypes = shallowReadonly([
{ display: 'Downloads', name: 'downloads' },
{ display: 'Follow count', name: 'follows' },
{ display: 'Recently published', name: 'newest' },
{ display: 'Recently updated', name: 'updated' },
])
const sortType = ref({ display: 'Downloads', name: 'downloads' })
let user, projects
try {
Expand Down Expand Up @@ -322,7 +353,18 @@ const metaDescription = ref(
? `${user.value.bio} - Download ${user.value.username}'s projects on Modrinth`
: `Download ${user.value.username}'s projects on Modrinth`
)
const sortProjects = (a, b) => {
switch (sortType.value.name) {
case 'downloads':
return b.downloads - a.downloads
case 'newest':
return Date.parse(b.published) - Date.parse(a.published)
case 'updated':
return Date.parse(b.updated) - Date.parse(a.updated)
case 'follows':
return b.followers - a.followers
}
}
const projectTypes = computed(() => {
const obj = {}
Expand Down Expand Up @@ -445,6 +487,27 @@ export default defineNuxtComponent({
}
}
.sort-controls {
width: 100%;
display: flex;
flex-direction: row;
gap: var(--spacing-card-md);
flex-wrap: wrap;
align-items: center;
.labeled-control {
flex: 1;
display: flex;
flex-direction: row;
align-items: center;
gap: 0.5rem;
.labeled-control__label {
white-space: nowrap;
}
}
}
.mobile-username {
margin: 0.25rem 0;
}
Expand Down

0 comments on commit d9b76c2

Please sign in to comment.