2023-03-19 19:51:55 -04:00
|
|
|
<script lang="ts">
|
2023-03-29 10:02:04 -04:00
|
|
|
import { ref, type Ref } from 'vue'
|
|
|
|
|
2023-03-19 19:51:55 -04:00
|
|
|
export default {
|
|
|
|
async setup() {
|
2023-03-24 18:48:45 -04:00
|
|
|
const res = await fetch(`${import.meta.env.VITE_BACKEND_URL}/api/discover`)
|
2023-03-29 10:02:04 -04:00
|
|
|
let data: Ref<any[] | undefined> = ref()
|
2023-03-24 18:48:45 -04:00
|
|
|
let frontend_url = import.meta.env.VITE_INSTANCE_URL
|
2023-03-29 10:02:04 -04:00
|
|
|
data.value = await res.json()
|
|
|
|
|
2023-03-19 19:51:55 -04:00
|
|
|
|
|
|
|
return {
|
2023-03-29 10:02:04 -04:00
|
|
|
data,
|
2023-03-25 12:53:10 -04:00
|
|
|
frontend_url,
|
|
|
|
filterTags: ''
|
2023-03-19 19:51:55 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
abbreviate(text: number) {
|
2023-03-24 18:48:45 -04:00
|
|
|
return Intl.NumberFormat('en-US', {
|
|
|
|
//@ts-ignore
|
|
|
|
notation: 'compact',
|
|
|
|
maximumFractionDigits: 1
|
|
|
|
}).format(text)
|
2023-03-25 12:53:10 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
filterSearches(toFilter: string) {
|
|
|
|
const categories = this.$refs.categoryItem
|
|
|
|
const wantedTags = toFilter.split(',').filter((v) => v.toLowerCase())
|
|
|
|
|
|
|
|
for (let category of categories as any) {
|
|
|
|
let tagElements = category.getElementsByTagName("span")
|
|
|
|
let tags = []
|
|
|
|
|
|
|
|
for (let tag of tagElements) {
|
|
|
|
tags.push(tag.innerText.toLowerCase())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create sets from the arrays
|
|
|
|
const [set1, set2] = [new Set(wantedTags), new Set(tags)]
|
|
|
|
const common = [...set1].filter(x => set2.has(x));
|
|
|
|
|
|
|
|
console.log(wantedTags)
|
|
|
|
|
|
|
|
if(common.length === wantedTags.length) {
|
|
|
|
category.style.display = ""
|
|
|
|
} else if (wantedTags[0] === "") {
|
|
|
|
category.style.display = ""
|
|
|
|
console.log('ok')
|
|
|
|
} else {
|
|
|
|
category.style.display = "none"
|
|
|
|
}
|
|
|
|
}
|
2023-03-29 10:02:04 -04:00
|
|
|
},
|
|
|
|
getNextCategory() {
|
|
|
|
window.onscroll = async () => {
|
|
|
|
let bottomOfWindow = document.documentElement.scrollTop + window.innerHeight === document.documentElement.offsetHeight;
|
|
|
|
if (bottomOfWindow && this.data) {
|
|
|
|
const cursor = this.data[this.data.length - 1].cursor
|
|
|
|
if(!cursor) return
|
|
|
|
const res = await fetch(`${import.meta.env.VITE_BACKEND_URL}/api/discover/?cursor=${cursor}`)
|
|
|
|
const data = await res.json()
|
|
|
|
|
|
|
|
for (let category of data) {
|
|
|
|
this.data.push(category)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2023-03-19 19:51:55 -04:00
|
|
|
}
|
2023-03-29 10:02:04 -04:00
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.getNextCategory()
|
2023-03-19 19:51:55 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div class="max-w-5xl mx-auto">
|
|
|
|
<div class="p-2">
|
2023-03-24 18:48:45 -04:00
|
|
|
<h1 class="font-bold text-5xl text-white">Discover</h1>
|
|
|
|
<p class="text-xl text-white">Sort through popular categories</p>
|
2023-03-19 19:51:55 -04:00
|
|
|
|
|
|
|
<div class="pt-5 inline-flex text-white">
|
|
|
|
<p class="mr-2 font-bold text-white">Filter by tag</p>
|
|
|
|
<form class="relative">
|
|
|
|
<label for="searchBar" class="hidden">Search</label>
|
2023-03-24 18:48:45 -04:00
|
|
|
<v-icon name="io-search-outline" class="absolute my-auto inset-y-0 left-2"></v-icon>
|
2023-03-19 19:51:55 -04:00
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
id="searchBar"
|
|
|
|
name="searchBar"
|
|
|
|
placeholder="Search"
|
2023-03-25 12:53:10 -04:00
|
|
|
v-model="filterTags"
|
|
|
|
@keyup="filterSearches(filterTags)"
|
2023-03-19 19:51:55 -04:00
|
|
|
class="rounded-md p-1 pl-8 text-black bg-neutral-500 placeholder:text-white"
|
|
|
|
/>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2023-03-25 12:53:10 -04:00
|
|
|
<ul ref="categoryList">
|
2023-03-24 18:48:45 -04:00
|
|
|
<li
|
|
|
|
v-for="category in data"
|
|
|
|
:key="category"
|
2023-03-25 12:53:10 -04:00
|
|
|
ref="categoryItem"
|
2023-03-24 18:48:45 -04:00
|
|
|
class="inline-flex m-2 hover:scale-105 transition-transform"
|
|
|
|
>
|
2023-03-19 19:51:55 -04:00
|
|
|
<div class="bg-ctp-crust max-w-[13.5rem] rounded-lg">
|
2023-03-24 18:48:45 -04:00
|
|
|
<router-link :to="`/game/${category.name}`">
|
|
|
|
<img :src="category.image" class="rounded-lg rounded-b-none" />
|
|
|
|
</router-link>
|
2023-03-19 19:51:55 -04:00
|
|
|
|
|
|
|
<div class="p-2">
|
|
|
|
<div>
|
2023-03-24 18:48:45 -04:00
|
|
|
<p class="font-bold text-white text-xl">{{ category.displayName }}</p>
|
|
|
|
<p class="text-sm text-white">{{ abbreviate(category.viewers) }} viewers</p>
|
2023-03-19 19:51:55 -04:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<ul class="h-8 overflow-hidden">
|
|
|
|
<li v-for="tag in category.tags" :key="tag" class="inline-flex">
|
2023-03-24 18:48:45 -04:00
|
|
|
<span
|
|
|
|
class="p-2.5 py-1.5 bg-ctp-surface0 rounded-md m-0.5 text-xs font-bold text-white"
|
|
|
|
>{{ tag }}</span
|
|
|
|
>
|
2023-03-19 19:51:55 -04:00
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</template>
|