You've already forked AstralRinth
forked from didirus/AstralRinth
* Start of app redesign * format * continue progress * Content page nearly done * Fix recursion issues with content page * Fix update all alignment * Discover page progress * Settings progress * Removed unlocked-size hack that breaks web * Revamp project page, refactor web project page to share code with app, fixed loading bar, misc UI/UX enhancements, update ko-fi logo, update arrow icons, fix web issues caused by floating-vue migration, fix tooltip issues, update web tooltips, clean up web hydration issues * Ads + run prettier * Begin auth refactor, move common messages to ui lib, add i18n extraction to all apps, begin Library refactor * fix ads not hiding when plus log in * rev lockfile changes/conflicts * Fix sign in page * Add generated * (mostly) Data driven search * Fix search mobile issue * profile fixes * Project versions page, fix typescript on UI lib and misc fixes * Remove unused gallery component * Fix linkfunction err * Search filter controls at top, localization for locked filters * Fix provided filter names * Fix navigating from instance browse to main browse * Friends frontend (#2995) * Friends system frontend * (almost) finish frontend * finish friends, fix lint * Fix lint --------- Signed-off-by: Geometrically <18202329+Geometrically@users.noreply.github.com> * Refresh macOS app icon * Update web search UI more * Fix link opens * Fix frontend build --------- Signed-off-by: Geometrically <18202329+Geometrically@users.noreply.github.com> Co-authored-by: Jai A <jaiagr+gpg@pm.me> Co-authored-by: Geometrically <18202329+Geometrically@users.noreply.github.com>
131 lines
3.3 KiB
Vue
131 lines
3.3 KiB
Vue
<script setup>
|
|
import { ref, onUnmounted, computed } from 'vue'
|
|
import { useRoute } from 'vue-router'
|
|
import RowDisplay from '@/components/RowDisplay.vue'
|
|
import { list } from '@/helpers/profile.js'
|
|
import { profile_listener } from '@/helpers/events'
|
|
import { useBreadcrumbs } from '@/store/breadcrumbs'
|
|
import { handleError } from '@/store/notifications.js'
|
|
import dayjs from 'dayjs'
|
|
import { get_search_results } from '@/helpers/cache.js'
|
|
|
|
const featuredModpacks = ref({})
|
|
const featuredMods = ref({})
|
|
const filter = ref('')
|
|
|
|
const route = useRoute()
|
|
const breadcrumbs = useBreadcrumbs()
|
|
|
|
breadcrumbs.setRootContext({ name: 'Home', link: route.path })
|
|
|
|
const recentInstances = ref([])
|
|
|
|
const offline = ref(!navigator.onLine)
|
|
window.addEventListener('offline', () => {
|
|
offline.value = true
|
|
})
|
|
window.addEventListener('online', () => {
|
|
offline.value = false
|
|
})
|
|
|
|
const getInstances = async () => {
|
|
const profiles = await list().catch(handleError)
|
|
|
|
recentInstances.value = profiles.sort((a, b) => {
|
|
const dateA = dayjs(a.last_played ?? 0)
|
|
const dateB = dayjs(b.last_played ?? 0)
|
|
|
|
if (dateA.isSame(dateB)) {
|
|
return a.name.localeCompare(b.name)
|
|
}
|
|
|
|
return dateB - dateA
|
|
})
|
|
|
|
const filters = []
|
|
for (const instance of recentInstances.value) {
|
|
if (instance.linked_data && instance.linked_data.project_id) {
|
|
filters.push(`NOT"project_id"="${instance.linked_data.project_id}"`)
|
|
}
|
|
}
|
|
filter.value = filters.join(' AND ')
|
|
}
|
|
|
|
const getFeaturedModpacks = async () => {
|
|
const response = await get_search_results(
|
|
`?facets=[["project_type:modpack"]]&limit=10&index=follows&filters=${filter.value}`,
|
|
)
|
|
|
|
if (response) {
|
|
featuredModpacks.value = response.result.hits
|
|
} else {
|
|
featuredModpacks.value = []
|
|
}
|
|
}
|
|
const getFeaturedMods = async () => {
|
|
const response = await get_search_results('?facets=[["project_type:mod"]]&limit=10&index=follows')
|
|
|
|
if (response) {
|
|
featuredMods.value = response.result.hits
|
|
} else {
|
|
featuredModpacks.value = []
|
|
}
|
|
}
|
|
|
|
await getInstances()
|
|
|
|
await Promise.all([getFeaturedModpacks(), getFeaturedMods()])
|
|
|
|
const unlistenProfile = await profile_listener(async (e) => {
|
|
await getInstances()
|
|
|
|
if (e.event === 'added' || e.event === 'created' || e.event === 'removed') {
|
|
await Promise.all([getFeaturedModpacks(), getFeaturedMods()])
|
|
}
|
|
})
|
|
|
|
// computed sums of recentInstances, featuredModpacks, featuredMods, treating them as arrays if they are not
|
|
const total = computed(() => {
|
|
return (
|
|
(recentInstances.value?.length ?? 0) +
|
|
(featuredModpacks.value?.length ?? 0) +
|
|
(featuredMods.value?.length ?? 0)
|
|
)
|
|
})
|
|
|
|
onUnmounted(() => {
|
|
unlistenProfile()
|
|
})
|
|
</script>
|
|
|
|
<template>
|
|
<div class="p-6 flex flex-col gap-2">
|
|
<h1 class="m-0 text-2xl">Welcome back!</h1>
|
|
<RowDisplay
|
|
v-if="total > 0"
|
|
:instances="[
|
|
{
|
|
label: 'Jump back in',
|
|
route: '/library',
|
|
instances: recentInstances,
|
|
instance: true,
|
|
downloaded: true,
|
|
},
|
|
{
|
|
label: 'Popular packs',
|
|
route: '/browse/modpack',
|
|
instances: featuredModpacks,
|
|
downloaded: false,
|
|
},
|
|
{
|
|
label: 'Popular mods',
|
|
route: '/browse/mod',
|
|
instances: featuredMods,
|
|
downloaded: false,
|
|
},
|
|
]"
|
|
:can-paginate="true"
|
|
/>
|
|
</div>
|
|
</template>
|