From 4a53fc8204d5a3a3d5a77b3dfe128f0985153bf8 Mon Sep 17 00:00:00 2001 From: Kim <1877318+kimsible@users.noreply.github.com> Date: Mon, 10 Aug 2020 15:57:37 +0200 Subject: Add new anchors in my-settings and handle offset sub-menu height (#3032) * Add anchors setting and handle offset with sub-meu * Use PeerTube scroll logic * Add anchor for top my-settings * Improve scroller with smooth behavior and css offset * Fix anchor position when using history navigation Co-authored-by: kimsible --- client/src/app/+admin/admin.component.scss | 4 ++++ .../my-account-settings/my-account-settings.component.html | 2 ++ client/src/app/+my-account/my-account.component.scss | 4 ++++ client/src/app/app.component.ts | 13 +++++++++---- client/src/app/menu/menu.component.html | 8 ++++---- .../shared-user-settings/user-video-settings.component.html | 2 ++ client/src/sass/application.scss | 6 +++++- 7 files changed, 30 insertions(+), 9 deletions(-) diff --git a/client/src/app/+admin/admin.component.scss b/client/src/app/+admin/admin.component.scss index 61a2744ba..a764efc76 100644 --- a/client/src/app/+admin/admin.component.scss +++ b/client/src/app/+admin/admin.component.scss @@ -6,3 +6,7 @@ my-top-menu-dropdown { } @include sub-menu-h1; + +::ng-deep .anchor { + top: #{-($header-height + $sub-menu-height + 20px)}; // offsetTop scrollToAnchor +} diff --git a/client/src/app/+my-account/my-account-settings/my-account-settings.component.html b/client/src/app/+my-account/my-account-settings/my-account-settings.component.html index 2ad014f01..de8353851 100644 --- a/client/src/app/+my-account/my-account-settings/my-account-settings.component.html +++ b/client/src/app/+my-account/my-account-settings/my-account-settings.component.html @@ -1,5 +1,7 @@

Settings

+
+
diff --git a/client/src/app/+my-account/my-account.component.scss b/client/src/app/+my-account/my-account.component.scss index a5bb499b4..6c1d9519c 100644 --- a/client/src/app/+my-account/my-account.component.scss +++ b/client/src/app/+my-account/my-account.component.scss @@ -11,3 +11,7 @@ @include sub-menu-h1; } + +::ng-deep .anchor { + top: #{-($header-height + $sub-menu-height + 20px)}; // offsetTop scrollToAnchor +} diff --git a/client/src/app/app.component.ts b/client/src/app/app.component.ts index ff0e28aa5..5c64db522 100644 --- a/client/src/app/app.component.ts +++ b/client/src/app/app.component.ts @@ -119,12 +119,17 @@ export class AppComponent implements OnInit, AfterViewInit { const scrollEvent = eventsObs.pipe(filter((e: Event): e is Scroll => e instanceof Scroll)) scrollEvent.subscribe(e => { - if (e.position) { - return this.viewportScroller.scrollToPosition(e.position) + // scrollToAnchor first to preserve anchor position when using history navigation + if (e.anchor) { + setTimeout(() => { + this.viewportScroller.scrollToAnchor(e.anchor) + }) + + return } - if (e.anchor) { - return this.viewportScroller.scrollToAnchor(e.anchor) + if (e.position) { + return this.viewportScroller.scrollToPosition(e.position) } if (resetScroll) { diff --git a/client/src/app/menu/menu.component.html b/client/src/app/menu/menu.component.html index 71fb2c154..7f83a6fb8 100644 --- a/client/src/app/menu/menu.component.html +++ b/client/src/app/menu/menu.component.html @@ -21,7 +21,7 @@ - + Account settings @@ -37,13 +37,13 @@ {{ language }} - + Videos: {{ videoLanguages.join(', ') }} - + Sensitive: @@ -56,7 +56,7 @@ - + More account settings diff --git a/client/src/app/shared/shared-user-settings/user-video-settings.component.html b/client/src/app/shared/shared-user-settings/user-video-settings.component.html index 0dda33af2..bb9f59070 100644 --- a/client/src/app/shared/shared-user-settings/user-video-settings.component.html +++ b/client/src/app/shared/shared-user-settings/user-video-settings.component.html @@ -1,5 +1,6 @@
+
@@ -20,6 +21,7 @@
+
diff --git a/client/src/sass/application.scss b/client/src/sass/application.scss index 1dbdd4064..4f2278414 100644 --- a/client/src/sass/application.scss +++ b/client/src/sass/application.scss @@ -18,6 +18,10 @@ $assets-path: '../../assets/'; display: none !important; } +html { + scroll-behavior: smooth; +} + body { /*** theme ***/ // now beware node-sass requires interpolation @@ -307,7 +311,7 @@ table { .anchor { position: relative; - top: #{-($header-height + 20px)}; + top: #{-($header-height + 20px)}; // offsetTop scrollToAnchor } @media screen and (max-width: #{breakpoint(xxl)}) { -- cgit v1.2.3