mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-20 15:20:18 +00:00
[TSK-1292] Remember panel scroll positions (#3143)
Signed-off-by: Ruslan Bayandinov <wazsone@ya.ru>
This commit is contained in:
parent
6d7b2f4bf6
commit
6d3f49cb31
@ -14,10 +14,13 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
-->
|
-->
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { afterUpdate } from 'svelte'
|
||||||
|
import { Writable, writable } from 'svelte/store'
|
||||||
|
|
||||||
import activity from '@hcengineering/activity'
|
import activity from '@hcengineering/activity'
|
||||||
import calendar from '@hcengineering/calendar'
|
import calendar from '@hcengineering/calendar'
|
||||||
import type { Doc } from '@hcengineering/core'
|
import { Doc } from '@hcengineering/core'
|
||||||
import type { Asset } from '@hcengineering/platform'
|
import { Asset } from '@hcengineering/platform'
|
||||||
import {
|
import {
|
||||||
AnySvelteComponent,
|
AnySvelteComponent,
|
||||||
Component,
|
Component,
|
||||||
@ -46,6 +49,40 @@
|
|||||||
export let useMaxWidth: boolean | undefined = undefined
|
export let useMaxWidth: boolean | undefined = undefined
|
||||||
export let isFullSize = false
|
export let isFullSize = false
|
||||||
export let embedded = false
|
export let embedded = false
|
||||||
|
|
||||||
|
let lastHref: string
|
||||||
|
let scroll: HTMLDivElement
|
||||||
|
let timer: number
|
||||||
|
let lastScrollHeight: number = -1
|
||||||
|
let count: number = 0
|
||||||
|
|
||||||
|
const waitCount = 10
|
||||||
|
const PanelScrollTop: Writable<Record<string, number>> = writable<Record<string, number>>({})
|
||||||
|
|
||||||
|
const startScrollHeightCheck = () => {
|
||||||
|
clearTimeout(timer)
|
||||||
|
timer = setTimeout(() => {
|
||||||
|
if (lastScrollHeight <= scroll.scrollHeight && count <= waitCount) {
|
||||||
|
count = lastScrollHeight < scroll.scrollHeight ? 0 : count + 1
|
||||||
|
lastScrollHeight = scroll.scrollHeight
|
||||||
|
|
||||||
|
startScrollHeightCheck()
|
||||||
|
} else {
|
||||||
|
lastScrollHeight = -1
|
||||||
|
count = 0
|
||||||
|
|
||||||
|
scroll.scrollTop = $PanelScrollTop[window.location.href]
|
||||||
|
$PanelScrollTop[window.location.href] = 0
|
||||||
|
lastHref = window.location.href
|
||||||
|
}
|
||||||
|
}, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
afterUpdate(() => {
|
||||||
|
if (lastHref !== window.location.href) {
|
||||||
|
startScrollHeightCheck()
|
||||||
|
}
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Panel
|
<Panel
|
||||||
@ -150,7 +187,14 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
<Scroller>
|
<Scroller
|
||||||
|
bind:divScroll={scroll}
|
||||||
|
on:divScrollTop={(event) => {
|
||||||
|
if (lastHref === window.location.href && event && event.detail !== $PanelScrollTop[lastHref]) {
|
||||||
|
$PanelScrollTop[lastHref] = event.detail
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
<div class="popupPanel-body__main-content py-8 clear-mins" class:max={useMaxWidth}>
|
<div class="popupPanel-body__main-content py-8 clear-mins" class:max={useMaxWidth}>
|
||||||
<slot />
|
<slot />
|
||||||
{#if !withoutActivity}
|
{#if !withoutActivity}
|
||||||
|
@ -62,7 +62,6 @@
|
|||||||
let divBox: HTMLElement
|
let divBox: HTMLElement
|
||||||
let divBar: HTMLElement
|
let divBar: HTMLElement
|
||||||
let divBarH: HTMLElement
|
let divBarH: HTMLElement
|
||||||
let divScrollContainer: HTMLElement
|
|
||||||
let isScrolling: 'vertical' | 'horizontal' | false = false
|
let isScrolling: 'vertical' | 'horizontal' | false = false
|
||||||
let dXY: number
|
let dXY: number
|
||||||
let belowContent: number | undefined = undefined
|
let belowContent: number | undefined = undefined
|
||||||
@ -88,6 +87,8 @@
|
|||||||
|
|
||||||
const checkBar = (): void => {
|
const checkBar = (): void => {
|
||||||
if (divBar && divScroll) {
|
if (divBar && divScroll) {
|
||||||
|
dispatch('divScrollTop', divScroll.scrollTop)
|
||||||
|
|
||||||
const trackH = divScroll.clientHeight - shiftTop - shiftBottom - 4
|
const trackH = divScroll.clientHeight - shiftTop - shiftBottom - 4
|
||||||
const scrollH = divScroll.scrollHeight
|
const scrollH = divScroll.scrollHeight
|
||||||
const proc = scrollH / trackH
|
const proc = scrollH / trackH
|
||||||
@ -448,7 +449,6 @@
|
|||||||
<svelte:window on:resize={_resize} />
|
<svelte:window on:resize={_resize} />
|
||||||
|
|
||||||
<div
|
<div
|
||||||
bind:this={divScrollContainer}
|
|
||||||
class="scroller-container {orientir} {invertScroll ? 'invert' : 'normal'}"
|
class="scroller-container {orientir} {invertScroll ? 'invert' : 'normal'}"
|
||||||
class:buttons={buttons === 'normal'}
|
class:buttons={buttons === 'normal'}
|
||||||
class:union={buttons === 'union'}
|
class:union={buttons === 'union'}
|
||||||
|
Loading…
Reference in New Issue
Block a user