Skip to content

Commit

Permalink
chore: add back sort on modules
Browse files Browse the repository at this point in the history
  • Loading branch information
atinux committed Oct 3, 2024
1 parent 84bc6a9 commit e34eea7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
7 changes: 5 additions & 2 deletions composables/useModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,11 @@ export const useModules = () => {
filteredModules = filteredModules.reverse()
}

// sponsored & official modules in first place
return filteredModules.sort(isSponsorOrOfficial)
// sponsored & official modules in first place if no sort or order by
if (!route.query.sortBy && !route.query.orderBy) {
return filteredModules.sort(isSponsorOrOfficial)
}
return filteredModules
})

return {
Expand Down
43 changes: 37 additions & 6 deletions pages/modules/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const inputRef = ref()
const route = useRoute()
const { replaceRoute } = useFilters('modules')
const { fetchList, filteredModules, q, categories, stats } = useModules()
const { fetchList, filteredModules, q, categories, stats, selectedOrder, sorts, selectedSort } = useModules()
const { data: page } = await useAsyncData(route.path, () => queryContent(route.path).findOne())
Expand Down Expand Up @@ -64,7 +64,7 @@ const { copy } = useCopyToClipboard()
name="q"
icon="i-ph-magnifying-glass"
placeholder="Search..."
class="w-full mb-4"
class="w-full mb-2"
size="md"
autocomplete="off"
:ui="{ icon: { trailing: { pointer: '' } } }"
Expand All @@ -85,25 +85,56 @@ const { copy } = useCopyToClipboard()
</UKbd>
</template>
</UInput>
<UButtonGroup class="mb-4 w-full">
<USelectMenu
:model-value="selectedSort"
:options="sorts"
size="md"
color="white"
class="w-full"
@update:model-value="replaceRoute('sortBy', $event)"
/>
<UButton
:icon="selectedOrder.icon"
size="md"
color="gray"
@click="replaceRoute('orderBy', selectedOrder.key === 'desc' ? 'asc' : 'desc')"
/>
</UButtonGroup>
<UNavigationTree :links="[{ label: 'Categories', disabled: true, children: categories }]" />
</UAside>
</template>

<UPageBody class="lg:pl-12">
<div class="lg:hidden mb-6">
<UPageBody class="lg:pl-8">
<div class="lg:hidden mb-6 flex items-center gap-2">
<UInput
ref="inputRef"
type="search"
:model-value="q"
name="q"
icon="i-ph-magnifying-glass"
placeholder="Search a module..."
class="w-full mb-4"
size="md"
class="w-full"
size="sm"
autocomplete="off"
:ui="{ icon: { trailing: { pointer: '' } } }"
@update:model-value="replaceRoute('q', $event)"
/>
<UButtonGroup>
<USelectMenu
:model-value="selectedSort"
:options="sorts"
size="md"
color="white"
@update:model-value="replaceRoute('sortBy', $event)"
/>
<UButton
:icon="selectedOrder.icon"
size="md"
color="gray"
@click="replaceRoute('orderBy', selectedOrder.key === 'desc' ? 'asc' : 'desc')"
/>
</UButtonGroup>
</div>
<UPageGrid v-if="filteredModules?.length">
<UPageCard
Expand Down

0 comments on commit e34eea7

Please sign in to comment.