feat(servers): allow scrolling faq into view via hashes (#2893)

Co-authored-by: Prospector <6166773+Prospector@users.noreply.github.com>
This commit is contained in:
nullptr
2024-11-03 16:35:24 +00:00
committed by GitHub
parent 06f01aa85c
commit f212d04261

View File

@@ -403,7 +403,7 @@
<div class="relative flex flex-col gap-4 rounded-2xl bg-bg p-6 text-left md:p-12">
<h1 class="m-0 text-lg font-bold">Frequently Asked Questions</h1>
<div class="flex flex-col gap-1">
<details class="group">
<details pyro-hash="cpus" class="group" :open="route.hash === '#cpus'">
<summary class="flex cursor-pointer items-center py-3 font-bold text-contrast">
<span class="mr-2 transition-transform duration-200 group-open:rotate-90">
<RightArrowIcon />
@@ -416,7 +416,7 @@
</p>
</details>
<details class="group">
<details pyro-hash="ddos" class="group" :open="route.hash === '#ddos'">
<summary class="flex cursor-pointer items-center py-3 font-bold text-contrast">
<span class="mr-2 transition-transform duration-200 group-open:rotate-90">
<RightArrowIcon />
@@ -430,7 +430,7 @@
</p>
</details>
<details class="group">
<details pyro-hash="region" class="group" :open="route.hash === '#region'">
<summary class="flex cursor-pointer items-center py-3 font-bold text-contrast">
<span class="mr-2 transition-transform duration-200 group-open:rotate-90">
<RightArrowIcon />
@@ -444,7 +444,7 @@
</p>
</details>
<details class="group">
<details pyro-hash="storage" class="group" :open="route.hash === '#storage'">
<summary class="flex cursor-pointer items-center py-3 font-bold text-contrast">
<span class="mr-2 transition-transform duration-200 group-open:rotate-90">
<RightArrowIcon />
@@ -457,7 +457,7 @@
</p>
</details>
<details class="group">
<details pyro-hash="players" class="group" :open="route.hash === '#players'">
<summary class="flex cursor-pointer items-center py-3 font-bold text-contrast">
<span class="mr-2 transition-transform duration-200 group-open:rotate-90">
<RightArrowIcon />
@@ -890,6 +890,22 @@ const isAtCapacity = computed(
() => isSmallAtCapacity.value && isMediumAtCapacity.value && isLargeAtCapacity.value,
);
const scrollToFaq = () => {
if (route.hash) {
// where pyro-hash === route.hash
const faq = document.querySelector(`[pyro-hash="${route.hash.slice(1)}"]`);
if (faq) {
const top = faq.getBoundingClientRect().top;
const offset = window.innerHeight / 2 - faq.clientHeight / 2;
window.scrollTo({ top: window.scrollY + top - offset, behavior: "smooth" });
}
}
};
onMounted(scrollToFaq);
watch(() => route.hash, scrollToFaq);
const selectProduct = async (product, custom) => {
if (isAtCapacity.value) {
addNotification({