From 14356325e42d87c43f33b975fbb1d963cfa67251 Mon Sep 17 00:00:00 2001 From: Innei Date: Tue, 17 Sep 2024 23:05:12 +0800 Subject: [PATCH] fix(ui): social media gap if no media Signed-off-by: Innei --- .../src/components/ui/platform-icon/index.tsx | 7 +- .../entry-column/Items/picture-masonry.tsx | 6 +- .../entry-column/Items/social-media-item.tsx | 114 +++++++++--------- 3 files changed, 68 insertions(+), 59 deletions(-) diff --git a/src/renderer/src/components/ui/platform-icon/index.tsx b/src/renderer/src/components/ui/platform-icon/index.tsx index 5f0ea31b1..6f6f942a9 100644 --- a/src/renderer/src/components/ui/platform-icon/index.tsx +++ b/src/renderer/src/components/ui/platform-icon/index.tsx @@ -13,6 +13,7 @@ const IconMap = Object.values(LinkParsers).reduce( {} as Record, ) +const shouldAddWhiteBgUrls = ["1x.com"] export const PlatformIcon: FC<{ url: string children: React.JSX.Element @@ -23,7 +24,11 @@ export const PlatformIcon: FC<{ if (!iconName || !IconMap[iconName]) { return ( - + url.includes(_)) ? "bg-white" : ""} ${className}`} + style={style} + {...rest} + > {children} ) diff --git a/src/renderer/src/modules/entry-column/Items/picture-masonry.tsx b/src/renderer/src/modules/entry-column/Items/picture-masonry.tsx index 58113bc59..c43e11a22 100644 --- a/src/renderer/src/modules/entry-column/Items/picture-masonry.tsx +++ b/src/renderer/src/modules/entry-column/Items/picture-masonry.tsx @@ -76,7 +76,7 @@ export const PictureMasonry: FC = (props) => { useLayoutEffect(() => { const $warpper = containerRef.current if (!$warpper) return - const recal = throttle(() => { + const handler = () => { const column = getCurrentColumn($warpper.clientWidth) setCurrentItemWidth(Math.trunc($warpper.clientWidth / column - 20)) @@ -85,7 +85,8 @@ export const PictureMasonry: FC = (props) => { nextFrame(() => { setIsInitLayout(true) }) - }, 50) + } + const recal = throttle(handler, 50) let previousWidth = $warpper.offsetWidth const resizeObserver = new ResizeObserver((entries) => { @@ -94,6 +95,7 @@ export const PictureMasonry: FC = (props) => { if (newWidth !== previousWidth) { previousWidth = newWidth + recal() } } diff --git a/src/renderer/src/modules/entry-column/Items/social-media-item.tsx b/src/renderer/src/modules/entry-column/Items/social-media-item.tsx index fc74b76a8..2b5cecbfa 100644 --- a/src/renderer/src/modules/entry-column/Items/social-media-item.tsx +++ b/src/renderer/src/modules/entry-column/Items/social-media-item.tsx @@ -93,65 +93,67 @@ export const SocialMediaItem: EntryListItemFC = ({ entryId, entryPreview, transl {!!entry.collections && } -
- {entry.entries.media?.map((media, i, mediaList) => { - const style: Partial<{ - width: string - height: string - }> = {} - const boundsWidth = jotaiStore.get(socialMediaContentWidthAtom) - if (media.height && media.width) { - // has 1 picture, max width is container width, but max height is less than window height: 2/3 - if (mediaList.length === 1) { - style.width = `${boundsWidth}px` - style.height = `${(boundsWidth * media.height) / media.width}px` - if (Number.parseInt(style.height) > (window.innerHeight * 2) / 3) { - style.height = `${(window.innerHeight * 2) / 3}px` - style.width = `${(Number.parseInt(style.height) * media.width) / media.height}px` + {!!entry.entries.media?.length && ( +
+ {entry.entries.media.map((media, i, mediaList) => { + const style: Partial<{ + width: string + height: string + }> = {} + const boundsWidth = jotaiStore.get(socialMediaContentWidthAtom) + if (media.height && media.width) { + // has 1 picture, max width is container width, but max height is less than window height: 2/3 + if (mediaList.length === 1) { + style.width = `${boundsWidth}px` + style.height = `${(boundsWidth * media.height) / media.width}px` + if (Number.parseInt(style.height) > (window.innerHeight * 2) / 3) { + style.height = `${(window.innerHeight * 2) / 3}px` + style.width = `${(Number.parseInt(style.height) * media.width) / media.height}px` + } + } + // has 2 pictures, max width is container half width, and - gap 8px + else if (mediaList.length === 2) { + style.width = `${(boundsWidth - 8) / 2}px` + style.height = `${(((boundsWidth - 8) / 2) * media.height) / media.width}px` + } + // has over 2 pictures, max width is container 1/3 width + else if (mediaList.length > 2) { + style.width = `${boundsWidth / 3}px` + style.height = `${((boundsWidth / 3) * media.height) / media.width}px` } } - // has 2 pictures, max width is container half width, and - gap 8px - else if (mediaList.length === 2) { - style.width = `${(boundsWidth - 8) / 2}px` - style.height = `${(((boundsWidth - 8) / 2) * media.height) / media.width}px` - } - // has over 2 pictures, max width is container 1/3 width - else if (mediaList.length > 2) { - style.width = `${boundsWidth / 3}px` - style.height = `${((boundsWidth / 3) * media.height) / media.width}px` - } - } - const proxySize = { - width: Number.parseInt(style.width || "0") || 0, - height: Number.parseInt(style.height || "0") || 0, - } - return ( - { - e.stopPropagation() - previewMedia( - mediaList.map((m) => ({ - url: m.url, - type: m.type, - fallbackUrl: - m.preview_image_url ?? getImageProxyUrl({ url: m.url, ...proxySize }), - })), - i, - ) - }} - /> - ) - })} -
+ const proxySize = { + width: Number.parseInt(style.width || "0") || 0, + height: Number.parseInt(style.height || "0") || 0, + } + return ( + { + e.stopPropagation() + previewMedia( + mediaList.map((m) => ({ + url: m.url, + type: m.type, + fallbackUrl: + m.preview_image_url ?? getImageProxyUrl({ url: m.url, ...proxySize }), + })), + i, + ) + }} + /> + ) + })} +
+ )}