Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BACK_TO_TOP event and fire when button is clicked #4953

Merged
merged 15 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions frontend/src/components/VScrollButton.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<script setup lang="ts">
import { computed } from "vue"

import { useAnalytics } from "~/composables/use-analytics"
import { useSearchStore } from "~/stores/search"
import { useMediaStore } from "~/stores/media"

const positionWithoutSidebar = "ltr:right-4 rtl:left-4"
const positionWithSidebar = "ltr:right-[22rem] rtl:left-[22rem]"

Expand All @@ -9,15 +13,29 @@
{ isFilterSidebarVisible: true }
)

const { sendCustomEvent } = useAnalytics()
const searchStore = useSearchStore()
const mediaStore = useMediaStore()

defineEmits<{ tab: [KeyboardEvent] }>()

const hClass = computed(() =>
props.isFilterSidebarVisible ? positionWithSidebar : positionWithoutSidebar
)
const scrollToTop = (e: MouseEvent) => {
const element =
(e.currentTarget as HTMLElement)?.closest("#main-page") || window
const scrollToTop = (_: MouseEvent) => {

Check failure on line 25 in frontend/src/components/VScrollButton.vue

View workflow job for this annotation

GitHub Actions / Lint files

'_' is defined but never used
d3jawu marked this conversation as resolved.
Show resolved Hide resolved
const mainPage = document.getElementById("main-page")
const element = mainPage || window
element.scrollTo({ top: 0, left: 0, behavior: "smooth" })

sendCustomEvent("BACK_TO_TOP", {
query: searchStore.searchTerm,
page: mediaStore.currentPage,
scrollPixels: mainPage?.scrollTop || 0,
maxScroll:
mainPage && "scrollTopMax" in mainPage
? (mainPage.scrollTopMax as number)
: 0,
})
}
</script>

Expand Down
14 changes: 14 additions & 0 deletions frontend/src/types/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,20 @@
/** The content type being searched (can include All content) */
searchType: SearchType
}
/**
* Description: The user clicks on the "back to top" caret button in the bottom-right of
* the search results page.
*/
BACK_TO_TOP: {
/** The search query */
query: string
/** The current page of results the user is on. */
page: number
/** The number of pixels the user has scrolled. */
scrollPixels: number | undefined

Check failure on line 114 in frontend/src/types/analytics.ts

View workflow job for this annotation

GitHub Actions / Lint files

Payloads must be specific key-value pairs where keys are strings and values are either string, boolean, or number
/** The maximum number of pixels the user has scrolled on this pageload. */
maxScroll: number | undefined

Check failure on line 116 in frontend/src/types/analytics.ts

View workflow job for this annotation

GitHub Actions / Lint files

Payloads must be specific key-value pairs where keys are strings and values are either string, boolean, or number
}
/**
* Description: Whenever the user scrolls to the end of the results page.
* Useful to evaluate how often users load more results or click
Expand Down
Loading