Skip to content

Commit

Permalink
Fix scrolling and groups
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoffyw committed Jun 28, 2024
1 parent 3bd3a95 commit 5f0df8d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/router/scroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ export function restoreScrollPosition(path: string) {
}
}

export function removeScrollPosition(path: string) {
scroll_positions.delete(path);
}


export function saveGroupOpened(path: string, ids: number[]) {
groups_opened.set(path, ids);
}
Expand Down
6 changes: 5 additions & 1 deletion src/views/SongSelectionView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { nextTick, onMounted, ref } from "vue";
import { getAllBookMetaData, getSongMetaData } from "@/scripts/book_import";
import { RouterLink, useRouter, useRoute, onBeforeRouteLeave } from "vue-router";
import { useLocalStorage, useSessionStorage } from "@vueuse/core";
import { saveScrollPosition, restoreScrollPosition, saveGroupOpened, getGroupOpened, removeGroupOpened } from "@/router/scroll";
import { saveScrollPosition, restoreScrollPosition, saveGroupOpened, getGroupOpened, removeGroupOpened, removeScrollPosition } from "@/router/scroll";
const props = defineProps<{
book: string;
Expand All @@ -14,6 +14,10 @@ const route = useRoute();
// Saving position in book
onBeforeRouteLeave((_, from) => {
saveScrollPosition(from.fullPath);
if(!_.fullPath.includes("/display")) {
removeGroupOpened(from.fullPath);
removeScrollPosition(from.fullPath);
}
});
const error_active = ref(false);
Expand Down
28 changes: 25 additions & 3 deletions src/views/TopicalIndexView.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script setup lang="ts">
import { onMounted, ref, computed } from "vue";
import { onMounted, ref, computed, nextTick } from "vue";
import { getAllBookMetaData, getSongMetaData, getBookIndex } from "@/scripts/book_import";
import { RouterLink, useRoute, useRouter } from "vue-router";
import { RouterLink, onBeforeRouteLeave, useRoute, useRouter } from "vue-router";
import type { Song } from "@/scripts/types";
import { useSessionStorage } from "@vueuse/core";
import { saveScrollPosition, restoreScrollPosition, saveGroupOpened, getGroupOpened, removeGroupOpened } from "@/router/scroll";
import { saveScrollPosition, restoreScrollPosition, saveGroupOpened, getGroupOpened, removeGroupOpened, removeScrollPosition } from "@/router/scroll";
const props = defineProps<{
book: string;
Expand Down Expand Up @@ -34,6 +34,14 @@ const songs_to_display = computed(() => {
return [];
});
onBeforeRouteLeave((_, from) => {
saveScrollPosition(from.fullPath);
if(!_.fullPath.includes("/display")) {
removeGroupOpened(from.fullPath);
removeScrollPosition(from.fullPath);
}
});
onMounted(async () => {
BOOK_METADATA = await getAllBookMetaData();
BOOK_SONG_METADATA = await getSongMetaData(props.book);
Expand All @@ -56,6 +64,7 @@ onMounted(async () => {
}
topical_index.value[topic_name].sort((a, b) => a.title.replace(/[.,/#!$%^&*;:{}=\-_'"`~()]/g, "").localeCompare(b.title.replace(/[.,/#!$%^&*;:{}=\-_'"`~()]/g, "")));
}
song_number_groups.value = Object.keys(topical_index.value);
for (const song_number of Object.keys(BOOK_SONG_METADATA)) {
let song: Song = BOOK_SONG_METADATA[song_number];
alphabeticalSongs.value.push({
Expand All @@ -74,6 +83,18 @@ onMounted(async () => {
title.value = "Topical Index";
icon.value = "../assets/text.svg";
}
let group_ids = getGroupOpened(route.fullPath);
if(group_ids != undefined) {
group_ids.forEach((id) => {
song_number_groups_active.value.push(song_number_groups.value[id]);
})
}
// Restoring position in book
await nextTick();
// The v-for for song buttons now should be active, so we can scroll to the saved position
restoreScrollPosition(route.fullPath);
});
function hideList(topic: string) {
Expand Down Expand Up @@ -140,6 +161,7 @@ function toggleDropdown(topic: string) {
} else {
song_number_groups_active.value.push(topic);
}
let ids: number[] = [];
song_number_groups_active.value.forEach((group_id) => {
var index = song_number_groups.value.indexOf(group_id);
Expand Down

0 comments on commit 5f0df8d

Please sign in to comment.