From 0b2e5c29d56dde668521d63c9cda0b0a21b96cc1 Mon Sep 17 00:00:00 2001 From: daniyal Date: Thu, 29 Aug 2024 23:01:41 +0500 Subject: [PATCH] feat: add image gallery --- package-lock.json | 21 +++++++++ package.json | 2 + src/pages/innerMod.tsx | 105 ++++++++++++++++++++++++----------------- 3 files changed, 86 insertions(+), 42 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0502f4c..3d378b3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,7 @@ "date-fns": "3.6.0", "dompurify": "3.1.6", "file-saver": "2.0.5", + "fslightbox-react": "1.7.6", "lodash": "4.17.21", "nostr-login": "1.5.2", "nostr-tools": "2.7.1", @@ -39,6 +40,7 @@ "devDependencies": { "@types/dompurify": "3.0.5", "@types/file-saver": "2.0.7", + "@types/fslightbox-react": "1.7.7", "@types/lodash": "4.17.7", "@types/papaparse": "5.3.14", "@types/react": "^18.3.3", @@ -1929,6 +1931,15 @@ "resolved": "https://registry.npmjs.org/@types/filewriter/-/filewriter-0.0.33.tgz", "integrity": "sha512-xFU8ZXTw4gd358lb2jw25nxY9QAgqn2+bKKjKOYfNCzN4DKCFetK7sPtrlpg66Ywe3vWY9FNxprZawAh9wfJ3g==" }, + "node_modules/@types/fslightbox-react": { + "version": "1.7.7", + "resolved": "https://registry.npmjs.org/@types/fslightbox-react/-/fslightbox-react-1.7.7.tgz", + "integrity": "sha512-pp9Y7/+L4NFlMp+PdESx66EG0/m70aqg81FNlLP08dGWvRRSvNJFv08Jc91IEQkbh/C1PpokCekNCWZqpWxiyQ==", + "dev": true, + "dependencies": { + "@types/react": "*" + } + }, "node_modules/@types/lodash": { "version": "4.17.7", "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.7.tgz", @@ -3352,6 +3363,16 @@ "node": "^8.16.0 || ^10.6.0 || >=11.0.0" } }, + "node_modules/fslightbox-react": { + "version": "1.7.6", + "resolved": "https://registry.npmjs.org/fslightbox-react/-/fslightbox-react-1.7.6.tgz", + "integrity": "sha512-7LN2GZRLHo2vZGKdH+BZDJUoUDkCRCLlZ5hOwtLtZplmGZQ9nqzpG54cTax7XNjbYGTWLT6BHdMiL5zOEhiRlA==", + "peerDependencies": { + "prop-types": ">=15.6.2", + "react": ">=16.8.0", + "react-dom": ">=16.8.0" + } + }, "node_modules/gensync": { "version": "1.0.0-beta.2", "resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz", diff --git a/package.json b/package.json index f625277..f4cec95 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "date-fns": "3.6.0", "dompurify": "3.1.6", "file-saver": "2.0.5", + "fslightbox-react": "1.7.6", "lodash": "4.17.21", "nostr-login": "1.5.2", "nostr-tools": "2.7.1", @@ -41,6 +42,7 @@ "devDependencies": { "@types/dompurify": "3.0.5", "@types/file-saver": "2.0.7", + "@types/fslightbox-react": "1.7.7", "@types/lodash": "4.17.7", "@types/papaparse": "5.3.14", "@types/react": "^18.3.3", diff --git a/src/pages/innerMod.tsx b/src/pages/innerMod.tsx index b3b401d..9df1856 100644 --- a/src/pages/innerMod.tsx +++ b/src/pages/innerMod.tsx @@ -51,6 +51,7 @@ import { unformatNumber, signAndPublish } from '../utils' +import FsLightbox from 'fslightbox-react' export const InnerModPage = () => { const { naddr } = useParams() @@ -935,6 +936,18 @@ const Body = ({ const postBodyRef = useRef(null) const viewFullPostBtnRef = useRef(null) + const [lightBoxController, setLightBoxController] = useState({ + toggler: false, + slide: 1 + }) + + const openLightBoxOnSlide = (slide: number) => { + setLightBoxController((prev) => ({ + toggler: !prev.toggler, + slide + })) + } + const viewFullPost = () => { if (postBodyRef.current && viewFullPostBtnRef.current) { postBodyRef.current.style.maxHeight = 'unset' @@ -950,52 +963,60 @@ const Body = ({ }) return ( -
-
-
-
-

{title}

-
+ <> +
- -
-

View

+ className='IBMSMSMBSSPostPicture' + style={{ + background: `url(${featuredImageUrl}) center / cover no-repeat` + }} + >
+
+
+

{title}

+
+
+ +
+

View

+
+
+
+ {screenshotsUrls.map((url, index) => ( + {`ScreenShot-${index}`} openLightBoxOnSlide(index + 1)} + /> + ))} +
+
+ {nsfw && ( +
+

NSFW

+
+ )} + + {tags.map((tag, index) => ( + + {tag} + + ))}
-
- {screenshotsUrls.map((url, index) => ( - {`ScreenShot-${index}`} - ))} -
-
- {nsfw && ( -
-

NSFW

-
- )} - - {tags.map((tag, index) => ( - - {tag} - - ))} -
-
+ + ) }