PluginProbe
Extendify / 3.0.4
Extendify v3.0.4
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / Library / components / ModalContent.jsx

ModalContent.jsx in Extendify 3.0.4, at src/Library/components/ModalContent.jsx

88 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { BlockPreviewButton } from '@library/components/BlockPreviewButton';
2 import { usePatterns } from '@library/hooks/usePatterns';
3 import { Spinner } from '@wordpress/components';
4 import { useEffect, useState } from '@wordpress/element';
5 import { __ } from '@wordpress/i18n';
6 import { useInView } from 'react-intersection-observer';
7 import Masonry from 'react-masonry-css';
8
9 export const ModalContent = ({ insertPattern, category }) => {
10 const { data, isLoading, setSize } = usePatterns({
11 category,
12 });
13 const [showLoading, setShowLoading] = useState(true);
14 const [loadMoreRef, inView] = useInView();
15 const noMore = data?.at(-1)?.length < 9; // hard coded for now
16
17 useEffect(() => {
18 if (isLoading) {
19 return setShowLoading(true);
20 }
21 const id = setTimeout(() => {
22 setShowLoading(false);
23 }, 750);
24 return () => clearTimeout(id);
25 }, [isLoading]);
26
27 useEffect(() => {
28 if (!inView || isLoading) return;
29 setSize((size) => size + 1);
30 }, [inView, isLoading, setSize]);
31
32 if (isLoading || !data?.length) {
33 return (
34 <div className="absolute inset-0 flex flex-col items-center justify-center text-center">
35 <Spinner />
36 <span className="sr-only">
37 {__('Loading Patterns...', 'extendify-local')}
38 </span>
39 </div>
40 );
41 }
42
43 return (
44 <>
45 <Masonry
46 breakpointCols={{
47 default: 3,
48 1600: 2,
49 1000: 1,
50 783: 2,
51 600: 1,
52 }}
53 columnClassName=""
54 className="relative flex w-full gap-6 p-8 pt-2"
55 >
56 {data.map((p) =>
57 p.map(({ id, code, patternReplacementCode }) => (
58 <BlockPreviewButton
59 key={id}
60 insertPattern={insertPattern}
61 code={patternReplacementCode ?? code}
62 />
63 )),
64 )}
65 </Masonry>
66 {showLoading ? (
67 <div className="absolute inset-0 z-0 flex flex-col items-center justify-center text-center">
68 <Spinner />
69 <span className="sr-only">
70 {__('Loading Patterns...', 'extendify-local')}
71 </span>
72 </div>
73 ) : null}
74 {showLoading || noMore ? null : (
75 <div
76 ref={loadMoreRef}
77 className="mb-6 mt-6 flex w-full justify-center md:mt-2"
78 >
79 <Spinner />
80 <span className="sr-only">
81 {__('Loading more patterns...', 'extendify-local')}
82 </span>
83 </div>
84 )}
85 </>
86 );
87 };
88