Drop Down menu
This commit is contained in:
parent
e0b6ffd62b
commit
33c2631aa7
1 changed files with 53 additions and 37 deletions
|
|
@ -1,13 +1,35 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
|
import {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuContent,
|
||||||
|
DropdownMenuItem,
|
||||||
|
DropdownMenuTrigger,
|
||||||
|
} from '#components'
|
||||||
import { useInfiniteScroll } from '@vueuse/core'
|
import { useInfiniteScroll } from '@vueuse/core'
|
||||||
import { Loader } from 'lucide-vue-next'
|
import { ArrowUpDown, Loader } from 'lucide-vue-next'
|
||||||
|
|
||||||
const links = ref([])
|
const links = ref([])
|
||||||
const limit = 24
|
const limit = 24
|
||||||
let cursor = ''
|
let cursor = ''
|
||||||
let listComplete = false
|
let listComplete = false
|
||||||
let listError = false
|
let listError = false
|
||||||
const sortBy = ref('created_desc') // created_desc, created_asc, alpha_asc, alpha_desc
|
const sortBy = ref('newest')
|
||||||
|
|
||||||
|
const displayedLinks = computed(() => {
|
||||||
|
const sorted = [...links.value]
|
||||||
|
switch (sortBy.value) {
|
||||||
|
case 'newest':
|
||||||
|
return sorted.sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime())
|
||||||
|
case 'oldest':
|
||||||
|
return sorted.sort((a, b) => new Date(a.created_at).getTime() - new Date(b.created_at).getTime())
|
||||||
|
case 'az':
|
||||||
|
return sorted.sort((a, b) => (a.title || '').localeCompare(b.title || ''))
|
||||||
|
case 'za':
|
||||||
|
return sorted.sort((a, b) => (b.title || '').localeCompare(a.title || ''))
|
||||||
|
default:
|
||||||
|
return sorted
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
async function getLinks() {
|
async function getLinks() {
|
||||||
try {
|
try {
|
||||||
|
|
@ -15,7 +37,6 @@ async function getLinks() {
|
||||||
query: {
|
query: {
|
||||||
limit,
|
limit,
|
||||||
cursor,
|
cursor,
|
||||||
sort: sortBy.value,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
links.value = links.value.concat(data.links).filter(Boolean) // Sometimes cloudflare will return null, filter out
|
links.value = links.value.concat(data.links).filter(Boolean) // Sometimes cloudflare will return null, filter out
|
||||||
|
|
@ -64,43 +85,38 @@ function updateLinkList(link, type) {
|
||||||
</DashboardNav>
|
</DashboardNav>
|
||||||
<LazyDashboardLinksSearch />
|
<LazyDashboardLinksSearch />
|
||||||
</div>
|
</div>
|
||||||
<div class="flex gap-2 items-center">
|
<div class="flex items-center gap-2">
|
||||||
<Button
|
<DropdownMenu>
|
||||||
variant="outline"
|
<DropdownMenuTrigger as-child>
|
||||||
size="sm"
|
<Button variant="outline" size="sm">
|
||||||
:class="{ 'bg-primary text-primary-foreground': sortBy === 'created_desc' }"
|
<ArrowUpDown class="mr-2 h-4 w-4" />
|
||||||
@click="sortBy = 'created_desc'; links = []; cursor = ''; getLinks()"
|
Sort by: {{
|
||||||
>
|
sortBy === 'newest' ? 'Newest First'
|
||||||
Newest First
|
: sortBy === 'oldest' ? 'Oldest First'
|
||||||
</Button>
|
: sortBy === 'az' ? 'A to Z'
|
||||||
<Button
|
: 'Z to A'
|
||||||
variant="outline"
|
}}
|
||||||
size="sm"
|
</Button>
|
||||||
:class="{ 'bg-primary text-primary-foreground': sortBy === 'created_asc' }"
|
</DropdownMenuTrigger>
|
||||||
@click="sortBy = 'created_asc'; links = []; cursor = ''; getLinks()"
|
<DropdownMenuContent>
|
||||||
>
|
<DropdownMenuItem @click="sortBy = 'newest'">
|
||||||
Oldest First
|
Newest First
|
||||||
</Button>
|
</DropdownMenuItem>
|
||||||
<Button
|
<DropdownMenuItem @click="sortBy = 'oldest'">
|
||||||
variant="outline"
|
Oldest First
|
||||||
size="sm"
|
</DropdownMenuItem>
|
||||||
:class="{ 'bg-primary text-primary-foreground': sortBy === 'alpha_asc' }"
|
<DropdownMenuItem @click="sortBy = 'az'">
|
||||||
@click="sortBy = 'alpha_asc'; links = []; cursor = ''; getLinks()"
|
A to Z
|
||||||
>
|
</DropdownMenuItem>
|
||||||
A to Z
|
<DropdownMenuItem @click="sortBy = 'za'">
|
||||||
</Button>
|
Z to A
|
||||||
<Button
|
</DropdownMenuItem>
|
||||||
variant="outline"
|
</DropdownMenuContent>
|
||||||
size="sm"
|
</DropdownMenu>
|
||||||
:class="{ 'bg-primary text-primary-foreground': sortBy === 'alpha_desc' }"
|
|
||||||
@click="sortBy = 'alpha_desc'; links = []; cursor = ''; getLinks()"
|
|
||||||
>
|
|
||||||
Z to A
|
|
||||||
</Button>
|
|
||||||
</div>
|
</div>
|
||||||
<section class="grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-3">
|
<section class="grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-3">
|
||||||
<DashboardLinksLink
|
<DashboardLinksLink
|
||||||
v-for="link in links"
|
v-for="link in displayedLinks"
|
||||||
:key="link.id"
|
:key="link.id"
|
||||||
:link="link"
|
:link="link"
|
||||||
@update:link="updateLinkList"
|
@update:link="updateLinkList"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue