Skip to content

Commit 815cf59

Browse files
author
Lionel Laské
committed
Merge branch 'fix-view-scroll-bar-position' of https://github.com/karthik-dev56/sugarizer into pr/1908
2 parents b0f6c00 + a1be3fe commit 815cf59

File tree

1 file changed

+29
-46
lines changed

1 file changed

+29
-46
lines changed

js/screens/listview.js

Lines changed: 29 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
const ListView = {
66
name: 'ListView',
7-
template: `<transition-group name="fade" appear>
7+
template: `<transition-group name="fade" appear @after-enter="restoreScroll">
88
<div class="listview" v-for="(activity, index) in sortedActivities" :key="activity.id">
99
<div class="listview_left" >
1010
<icon
@@ -94,7 +94,7 @@ const ListView = {
9494
constant: {
9595
timerPopupDuration: 1000,
9696
},
97-
move_scrollbar: true, // Flag to control scroll restoration
97+
scrollRestored: false,
9898
scrollbar_session_value: 0, // Saved scroll position from user preferences
9999
}
100100
},
@@ -103,8 +103,7 @@ const ListView = {
103103

104104
mounted() {
105105
this.getUser();
106-
107-
// Setup scroll event listener to save scroll position (like original PR #948)
106+
// Setup scroll event listener to save scroll position
108107
const container = document.getElementById('canvas');
109108
if (container) {
110109
container.addEventListener('scroll', this.onScroll);
@@ -117,8 +116,6 @@ const ListView = {
117116
if (container) {
118117
container.removeEventListener('scroll', this.onScroll);
119118
}
120-
121-
this.move_scrollbar = false;
122119
},
123120

124121
beforeUnmount() {
@@ -143,34 +140,33 @@ const ListView = {
143140

144141
methods: {
145142
async getUser() {
146-
sugarizer.modules.user.get().then((user) => {
143+
// Keep promise-style error handling while keeping the function async
144+
// Return the underlying promise so callers can await if needed.
145+
return sugarizer.modules.user.get().then((user) => {
147146
this.buddycolor = user.color;
147+
this.scrollbar_session_value = user.scrollValue || 0;
148148
sugarizer.modules.activities.updateFavorites(user.favorites);
149-
this.activities = sugarizer.modules.activities.get().filter((activity) => {
150-
return activity.name.toUpperCase().includes(this.filter.toUpperCase())
151-
});
149+
this.activities = sugarizer.modules.activities.get().filter(a =>
150+
a.name.toUpperCase().includes(this.filter.toUpperCase())
151+
);
152152
this.favactivities = sugarizer.modules.activities.getFavoritesName();
153153
this.activitiesLoaded = true;
154-
155-
this.scrollbar_session_value = user.scrollValue || 0;
156-
157-
// Restore scroll position AFTER activities are loaded
158-
this.$nextTick(() => {
159-
if (this.scrollbar_session_value > 0 && this.move_scrollbar) {
160-
const container = document.getElementById('canvas');
161-
if (container) {
162-
// Use a small delay to ensure content is fully rendered
163-
setTimeout(() => {
164-
container.scrollTop = this.scrollbar_session_value;
165-
}, 100);
166-
}
167-
}
168-
});
169154
}, (error) => {
170-
throw new Error('Unable to load the user, error ' + error);
155+
// preserve original rejection semantics
156+
throw new Error('Unable to get the user, error ' + error);
171157
});
172158
},
173159

160+
restoreScroll() {
161+
if (this.scrollRestored) return;
162+
this.scrollRestored = true;
163+
164+
const container = document.getElementById('canvas');
165+
if (container && this.scrollbar_session_value > 0) {
166+
container.scrollTop = this.scrollbar_session_value;
167+
}
168+
},
169+
174170
async toggleFavorite(activity) {
175171
sugarizer.modules.stats.trace('list_view', 'switch_favorite', activity.id, null);
176172

@@ -225,26 +221,13 @@ const ListView = {
225221
},
226222

227223
onScroll(event) {
228-
if (!this.move_scrollbar) {
229-
const container = event.target;
230-
const scrollPos = Math.ceil(container.scrollTop);
231-
const maxScroll = Math.ceil(container.scrollHeight - container.clientHeight);
232-
233-
const scrollValue = scrollPos > maxScroll ? maxScroll : scrollPos;
234-
sugarizer.modules.user.update({ scrollValue: scrollValue });
235-
}
236-
237-
if (this.move_scrollbar) {
238-
const container = event.target;
239-
const currentScroll = Math.ceil(container.scrollTop);
240-
241-
// Stop automatic scrolling once we reach or pass the saved position
242-
if (currentScroll >= this.scrollbar_session_value) {
243-
this.move_scrollbar = false;
244-
} else {
245-
container.scrollTop = this.scrollbar_session_value;
246-
}
247-
}
224+
const container = event.target;
225+
const scrollPos = Math.ceil(container.scrollTop);
226+
const maxScroll = Math.ceil(container.scrollHeight - container.clientHeight);
227+
228+
sugarizer.modules.user.update({
229+
scrollValue: Math.min(scrollPos, maxScroll)
230+
});
248231
},
249232

250233
computePopup() {

0 commit comments

Comments
 (0)