@codeleap/web 3.12.1 → 3.12.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeleap/web",
3
- "version": "3.12.1",
3
+ "version": "3.12.3",
4
4
  "main": "src/index.ts",
5
5
  "repository": {
6
6
  "url": "https://github.com/codeleap-uk/internal-libs-monorepo.git",
@@ -1,6 +1,6 @@
1
1
  import React from 'react'
2
2
  import { useWindowSize } from '@react-hook/window-size'
3
- import { AnyFunction, onUpdate, usePrevious } from '@codeleap/common'
3
+ import { AnyFunction, onUpdate, usePrevious, useState } from '@codeleap/common'
4
4
 
5
5
  import {
6
6
  useMasonry,
@@ -10,8 +10,11 @@ import {
10
10
  useResizeObserver,
11
11
  MasonryProps,
12
12
  RenderComponentProps,
13
+ MasonryScroller,
13
14
  } from 'masonic'
14
15
 
16
+ import { EmptyPlaceholder } from '../components/EmptyPlaceholder'
17
+
15
18
  export type ItemMasonryProps<T> = RenderComponentProps<T>
16
19
 
17
20
  export type ListMasonryProps<T> = MasonryProps<T> & {
@@ -20,7 +23,17 @@ export type ListMasonryProps<T> = MasonryProps<T> & {
20
23
  }
21
24
 
22
25
  export function ListMasonry<Item>(props: ListMasonryProps<Item>) {
23
- const data = props?.items || []
26
+ const {
27
+ columnCount,
28
+ columnGutter,
29
+ rowGutter,
30
+ items,
31
+ render,
32
+ } = props
33
+
34
+ const data = items || []
35
+
36
+ const [reloadingLayout, setReloadingLayout] = useState(false)
24
37
 
25
38
  const dataPreviousLength = usePrevious(data?.length)
26
39
 
@@ -34,7 +47,11 @@ export function ListMasonry<Item>(props: ListMasonryProps<Item>) {
34
47
 
35
48
  onUpdate(() => {
36
49
  if (!!masonryUpdater && !!props?.itemsRehydrateIndicator) {
37
- props?.onRefreshItems?.(() => null)
50
+ setReloadingLayout(true)
51
+
52
+ setTimeout(() => {
53
+ setReloadingLayout(false)
54
+ }, 3000)
38
55
  }
39
56
  }, [masonryUpdater])
40
57
 
@@ -47,34 +64,42 @@ export function ListMasonry<Item>(props: ListMasonryProps<Item>) {
47
64
 
48
65
  const containerPosition = useContainerPosition(containerRef, windowSize)
49
66
 
50
- const listProps = Object.assign(
51
- {
52
- offset: containerPosition?.offset,
53
- width: containerPosition?.width || containerRef?.current?.clientWidth || windowSize?.[0],
54
- height: windowSize?.[1],
55
- containerRef,
56
- scrollFps: props?.scrollFps || 12,
57
- },
58
- props
59
- ) as any
60
-
61
- listProps.positioner = usePositioner({
67
+ const listProps = {
68
+ offset: containerPosition?.offset,
69
+ width: containerPosition?.width || containerRef?.current?.clientWidth || windowSize?.[0],
70
+ height: windowSize?.[1],
71
+ containerRef,
72
+ scrollFps: props?.scrollFps || 12,
73
+ }
74
+
75
+ const positioner = usePositioner({
62
76
  width: listProps?.width,
63
- columnGutter: listProps?.columnGutter,
64
- columnWidth: listProps?.columnWidth,
65
- columnCount: listProps?.columnCount,
66
- maxColumnCount: listProps?.columnCount,
67
- rowGutter: listProps?.rowGutter
68
- }, [masonryUpdater])
77
+ columnGutter: columnGutter,
78
+ columnCount: columnCount,
79
+ maxColumnCount: columnCount,
80
+ rowGutter: rowGutter
81
+ }, [masonryUpdater, reloadingLayout])
69
82
 
70
- const { scrollTop, isScrolling } = useScroller(listProps?.offset, listProps?.scrollFps)
83
+ const resizeObserver = useResizeObserver(positioner)
71
84
 
72
- listProps.resizeObserver = useResizeObserver(listProps.positioner)
85
+ if (reloadingLayout) {
86
+ return (
87
+ <EmptyPlaceholder loading={true} />
88
+ )
89
+ }
73
90
 
74
- return useMasonry({
75
- ...listProps,
76
- scrollTop,
77
- isScrolling,
78
- items: data,
79
- })
91
+ return (
92
+ <MasonryScroller
93
+ // {...props}
94
+ positioner={positioner}
95
+ resizeObserver={resizeObserver}
96
+ containerRef={containerRef}
97
+ items={data}
98
+ height={listProps?.height}
99
+ offset={listProps?.offset}
100
+ overscanBy={6}
101
+ render={render}
102
+ scrollFps={listProps?.scrollFps}
103
+ />
104
+ )
80
105
  }