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 store scroll feature to BitAppShell (#10233) #10234

Merged
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace BitBlazorUI {
export class AppShell {
private static STORE_KEY = 'bit-appshell-scrolls';

public static PreScroll: number = 0;

private static _currentUrl: string;
@@ -9,9 +11,10 @@ namespace BitBlazorUI {
public static initScroll(container: HTMLElement, url: string) {
AppShell._container = container;
AppShell._currentUrl = url;
AppShell._scrolls[url] = AppShell.PreScroll;
if (AppShell.PreScroll > 0) {
AppShell._container.scrollTo({ top: AppShell.PreScroll, behavior: 'instant' });
AppShell._scrolls = JSON.parse(sessionStorage.getItem(this.STORE_KEY) || '{}');
AppShell.storeScroll(url, AppShell.PreScroll > 0 ? AppShell.PreScroll : AppShell._scrolls[url]);
if (AppShell._scrolls[url]! > 0) {
AppShell._container.scrollTo({ top: AppShell._scrolls[url], behavior: 'instant' });
}
AppShell.addScroll();
}
@@ -22,7 +25,7 @@ namespace BitBlazorUI {

public static afterRenderScroll(url: string) {
AppShell._currentUrl = url;
AppShell._scrolls[url] = AppShell._scrolls[url] || 0;
AppShell.storeScroll(url, AppShell._scrolls[url]);
AppShell._container?.scrollTo({ top: AppShell._scrolls[url], behavior: 'instant' });
AppShell.addScroll();
}
@@ -40,7 +43,12 @@ namespace BitBlazorUI {
}

private static onScroll() {
AppShell._scrolls[AppShell._currentUrl] = AppShell._container?.scrollTop;
AppShell.storeScroll(AppShell._currentUrl, AppShell._container?.scrollTop);
}

private static storeScroll(url: string, value: number | undefined) {
AppShell._scrolls[url] = value || 0;
window.sessionStorage.setItem(this.STORE_KEY, JSON.stringify(AppShell._scrolls));
}
}
}