mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-17 21:15:32 +09:00
fix(app): freeze embed author and footer icons under motion settings (#1853)
This commit is contained in:
1 parent
a98a9fe6a9
commit
aad7e1a551
2 files changed
+14
-18
No files matched your search
@@ -113,10 +113,6 @@
|
|||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.embedIconPending {
|
|
||||||
opacity: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.embedTitle {
|
.embedTitle {
|
||||||
font-size: 1em;
|
font-size: 1em;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
import {useAnimatedMediaPlaybackAllowed} from '@app/features/app/hooks/useAnimatedMediaPlayback';
|
import {useShouldAnimate} from '@app/features/app/hooks/useShouldAnimate';
|
||||||
import styles from '@app/features/channel/components/embeds/ChannelEmbed.module.css';
|
import styles from '@app/features/channel/components/embeds/ChannelEmbed.module.css';
|
||||||
import {EmbedLink} from '@app/features/channel/components/embeds/channel_embed/EmbedLink';
|
import {EmbedLink} from '@app/features/channel/components/embeds/channel_embed/EmbedLink';
|
||||||
import {SafeMarkdown} from '@app/features/messaging/components/markdown';
|
import {SafeMarkdown} from '@app/features/messaging/components/markdown';
|
||||||
import {MarkdownContext} from '@app/features/messaging/components/markdown/renderers/RendererTypes';
|
import {MarkdownContext} from '@app/features/messaging/components/markdown/renderers/RendererTypes';
|
||||||
import {useCachedImageLoaded} from '@app/features/messaging/hooks/useCachedImageLoaded';
|
|
||||||
import {buildMediaProxyURL} from '@app/features/messaging/utils/MediaProxyUtils';
|
import {buildMediaProxyURL} from '@app/features/messaging/utils/MediaProxyUtils';
|
||||||
import * as DateUtils from '@app/features/user/utils/DateFormatting';
|
import * as DateUtils from '@app/features/user/utils/DateFormatting';
|
||||||
import type {EmbedAuthor, EmbedField, EmbedFooter} from '@fluxer/schema/src/domains/message/EmbedSchemas';
|
import type {EmbedAuthor, EmbedField, EmbedFooter} from '@fluxer/schema/src/domains/message/EmbedSchemas';
|
||||||
@@ -14,6 +13,13 @@ import {clsx} from 'clsx';
|
|||||||
import {observer} from 'mobx-react-lite';
|
import {observer} from 'mobx-react-lite';
|
||||||
import {type FC, useMemo} from 'react';
|
import {type FC, useMemo} from 'react';
|
||||||
|
|
||||||
|
const STILL_EMBED_ICON_OPTIONS = {format: 'webp', animated: false} as const;
|
||||||
|
|
||||||
|
const resolveEmbedIconSrc = (proxyIconUrl: string | undefined, allowMotion: boolean): string | undefined => {
|
||||||
|
if (!proxyIconUrl) return undefined;
|
||||||
|
return buildMediaProxyURL(proxyIconUrl, allowMotion ? {} : STILL_EMBED_ICON_OPTIONS);
|
||||||
|
};
|
||||||
|
|
||||||
export const EmbedProvider: FC<{provider?: EmbedAuthor}> = observer(({provider}) => {
|
export const EmbedProvider: FC<{provider?: EmbedAuthor}> = observer(({provider}) => {
|
||||||
if (!provider) return null;
|
if (!provider) return null;
|
||||||
return (
|
return (
|
||||||
@@ -29,18 +35,15 @@ export const EmbedProvider: FC<{provider?: EmbedAuthor}> = observer(({provider})
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
export const EmbedAuthorComponent: FC<{author?: EmbedAuthor}> = observer(({author}) => {
|
export const EmbedAuthorComponent: FC<{author?: EmbedAuthor}> = observer(({author}) => {
|
||||||
const animatedMediaPlaybackAllowed = useAnimatedMediaPlaybackAllowed();
|
const allowIconMotion = useShouldAnimate({kind: 'gif'});
|
||||||
const iconSrc = author?.proxy_icon_url
|
const iconSrc = resolveEmbedIconSrc(author?.proxy_icon_url, allowIconMotion);
|
||||||
? buildMediaProxyURL(author.proxy_icon_url, animatedMediaPlaybackAllowed ? {} : {format: 'webp', animated: false})
|
|
||||||
: undefined;
|
|
||||||
const iconLoaded = useCachedImageLoaded(iconSrc);
|
|
||||||
if (!author) return null;
|
if (!author) return null;
|
||||||
return (
|
return (
|
||||||
<div className={styles.embedAuthor} data-flx="channel.embeds.embed.embed-author-component.embed-author">
|
<div className={styles.embedAuthor} data-flx="channel.embeds.embed.embed-author-component.embed-author">
|
||||||
{iconSrc && (
|
{iconSrc && (
|
||||||
<img
|
<img
|
||||||
alt=""
|
alt=""
|
||||||
className={clsx(styles.embedAuthorIcon, !iconLoaded && styles.embedIconPending)}
|
className={styles.embedAuthorIcon}
|
||||||
src={iconSrc}
|
src={iconSrc}
|
||||||
width={24}
|
width={24}
|
||||||
height={24}
|
height={24}
|
||||||
@@ -178,12 +181,9 @@ export const EmbedFooterComponent: FC<{
|
|||||||
channelId?: string;
|
channelId?: string;
|
||||||
}> = observer(({timestamp, footer, messageId, channelId}) => {
|
}> = observer(({timestamp, footer, messageId, channelId}) => {
|
||||||
const {i18n} = useLingui();
|
const {i18n} = useLingui();
|
||||||
const animatedMediaPlaybackAllowed = useAnimatedMediaPlaybackAllowed();
|
const allowIconMotion = useShouldAnimate({kind: 'gif'});
|
||||||
const formattedTimestamp = timestamp ? DateUtils.getRelativeDateString(timestamp, i18n) : undefined;
|
const formattedTimestamp = timestamp ? DateUtils.getRelativeDateString(timestamp, i18n) : undefined;
|
||||||
const iconSrc = footer?.proxy_icon_url
|
const iconSrc = resolveEmbedIconSrc(footer?.proxy_icon_url, allowIconMotion);
|
||||||
? buildMediaProxyURL(footer.proxy_icon_url, animatedMediaPlaybackAllowed ? {} : {format: 'webp', animated: false})
|
|
||||||
: undefined;
|
|
||||||
const iconLoaded = useCachedImageLoaded(iconSrc);
|
|
||||||
if (!(footer || formattedTimestamp)) return null;
|
if (!(footer || formattedTimestamp)) return null;
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@@ -193,7 +193,7 @@ export const EmbedFooterComponent: FC<{
|
|||||||
{iconSrc && (
|
{iconSrc && (
|
||||||
<img
|
<img
|
||||||
alt=""
|
alt=""
|
||||||
className={clsx(styles.embedFooterIcon, !iconLoaded && styles.embedIconPending)}
|
className={styles.embedFooterIcon}
|
||||||
src={iconSrc}
|
src={iconSrc}
|
||||||
width={20}
|
width={20}
|
||||||
height={20}
|
height={20}
|
||||||
|
|||||||
Reference in new issue
Block a user