A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
fix(app): correct badge settings and guild badge links (#3659)
Hampusaa70ac0ef278
diff --git a/fluxer_app/src/features/app/components/layout/GuildHeader.tsx b/fluxer_app/src/features/app/components/layout/GuildHeader.tsxindex ce35a7a88..2a556e3df 100644--- a/fluxer_app/src/features/app/components/layout/GuildHeader.tsx+++ b/fluxer_app/src/features/app/components/layout/GuildHeader.tsx@@ -156,6 +156,7 @@ export const GuildHeader = observer(({guild, banner}: {guild: Guild; banner: Guifeatures={guild.features}badgeIds={guild.badgeIds}customBadgeLimit={2}+ linkablevariant={onBanner ? 'banner' : 'default'}tooltipPosition="bottom"data-flx="app.guild-header.guild-badge"diff --git a/fluxer_app/src/features/guild/components/GuildBadge.tsx b/fluxer_app/src/features/guild/components/GuildBadge.tsxindex ae2a3abb2..92ec626a1 100644--- a/fluxer_app/src/features/guild/components/GuildBadge.tsx+++ b/fluxer_app/src/features/guild/components/GuildBadge.tsx@@ -98,7 +98,9 @@ function CustomGuildBadge({target="_blank"rel="noopener noreferrer"className={styles.badgeWrapper}- onClick={(event) => handleExternalLinkClick(event, href)}+ onClick={(event) => handleExternalLinkClick(event, href, {stopPropagation: true})}+ onPointerDown={(event) => event.stopPropagation()}+ onKeyDown={(event) => event.stopPropagation()}data-flx="guild.guild-badge.custom-badge-link">{image}diff --git a/fluxer_app/src/features/ui/components/form/FormSwitch.tsx b/fluxer_app/src/features/ui/components/form/FormSwitch.tsxindex 6dedac303..951ec04f1 100644--- a/fluxer_app/src/features/ui/components/form/FormSwitch.tsx+++ b/fluxer_app/src/features/ui/components/form/FormSwitch.tsx@@ -9,6 +9,7 @@ import type React from 'react';import {forwardRef, useCallback, useId, useMemo, useRef} from 'react';interface SwitchProps {+ id?: string;label?: React.ReactNode;description?: React.ReactNode;value: boolean;@@ -23,13 +24,13 @@ interface SwitchProps {export const Switch = observer(forwardRef<HTMLDivElement, SwitchProps>(function Switch(- {label, description, value, onChange, disabled, ariaLabel, ariaLabelledBy, ariaDescribedBy, className, compact},+ {id, label, description, value, onChange, disabled, ariaLabel, ariaLabelledBy, ariaDescribedBy, className, compact},forwardedRef,) {const baseId = useId();const labelId = useMemo(() => `${baseId}-switch-label`, [baseId]);const descriptionId = useMemo(() => `${baseId}-switch-description`, [baseId]);- const switchId = useMemo(() => `${baseId}-switch`, [baseId]);+ const switchId = useMemo(() => id ?? `${baseId}-switch`, [id, baseId]);const hasLabel = useMemo(() => label !== undefined && label !== null && !(typeof label === 'string' && label.trim().length === 0),[label],diff --git a/fluxer_app/src/features/user/components/modals/tabs/my_profile_tab/ProfileBadgeSettings.module.css b/fluxer_app/src/features/user/components/modals/tabs/my_profile_tab/ProfileBadgeSettings.module.cssindex 46077867d..805af890b 100644--- a/fluxer_app/src/features/user/components/modals/tabs/my_profile_tab/ProfileBadgeSettings.module.css+++ b/fluxer_app/src/features/user/components/modals/tabs/my_profile_tab/ProfileBadgeSettings.module.css@@ -22,6 +22,15 @@min-width: 0;}+.rowLabel {+ display: flex;+ flex: 1;+ align-items: center;+ gap: 0.75rem;+ min-width: 0;+ cursor: pointer;+}+.artSlot {display: inline-flex;flex-shrink: 0;diff --git a/fluxer_app/src/features/user/components/modals/tabs/my_profile_tab/ProfileBadgeSettings.tsx b/fluxer_app/src/features/user/components/modals/tabs/my_profile_tab/ProfileBadgeSettings.tsxindex 0c4e4c436..68e6f4e6b 100644--- a/fluxer_app/src/features/user/components/modals/tabs/my_profile_tab/ProfileBadgeSettings.tsx+++ b/fluxer_app/src/features/user/components/modals/tabs/my_profile_tab/ProfileBadgeSettings.tsx@@ -17,7 +17,7 @@ import type {MessageDescriptor} from '@lingui/core';import {msg} from '@lingui/core/macro';import {useLingui} from '@lingui/react/macro';import {observer} from 'mobx-react-lite';-import type React from 'react';+import {type ReactNode, useId} from 'react';const BADGES_DESCRIPTION_DESCRIPTOR = msg({message: 'Choose which badges other people see on your profile.',@@ -149,24 +149,30 @@ function BadgeList({}: Omit<ProfileBadgeSettingsProps, 'preview'> & {ownBadges: ReadonlyArray<OwnProfileBadgeResponse>}) {const {i18n} = useLingui();const hidden = new Set(hiddenProfileBadges);+ const switchIdPrefix = useId();const premiumProductName = getPremiumProductName();return (<ul className={styles.list} data-flx="user.profile-badge-settings.list">{ownBadges.map((badge) => {const shown = !hidden.has(badge.key);+ const switchId = `${switchIdPrefix}-${badge.key}`;+ const badgeProductName = badge.key === 'visionary' ? 'Visionary' : premiumProductName;const numberHasNoEffect =badge.key === 'visionary_number' && (hidden.has('visionary') || variants.premium_badge_masked);const badgeVariants = shown ? (BADGE_VARIANTS[badge.key] ?? []) : [];return (<li key={badge.key} className={styles.item} data-flx="user.profile-badge-settings.item"><div className={styles.row} data-flx="user.profile-badge-settings.row">- <span className={styles.artSlot} data-flx="user.profile-badge-settings.art-slot">- <BadgeArt badge={badge} data-flx="user.profile-badge-settings.badge-art" />- </span>- <span className={styles.label} dir="auto" data-flx="user.profile-badge-settings.label">- {badge.label}- </span>+ <label htmlFor={switchId} className={styles.rowLabel} data-flx="user.profile-badge-settings.row-label">+ <span className={styles.artSlot} data-flx="user.profile-badge-settings.art-slot">+ <BadgeArt badge={badge} data-flx="user.profile-badge-settings.badge-art" />+ </span>+ <span className={styles.label} dir="auto" data-flx="user.profile-badge-settings.label">+ {badge.label}+ </span>+ </label><Switch+ id={switchId}value={shown}onChange={(value) => onToggleHidden(badge.key, !value)}disabled={disabled || numberHasNoEffect}@@ -185,8 +191,15 @@ function BadgeList({{badgeVariants.map((variant) => (<Switchkey={variant.field}- label={i18n._(variant.label, {premiumProductName, operatorPassName: OPERATOR_PASS_NAME})}- description={variant.description ? i18n._(variant.description, {premiumProductName}) : undefined}+ label={i18n._(variant.label, {+ premiumProductName: badgeProductName,+ operatorPassName: OPERATOR_PASS_NAME,+ })}+ description={+ variant.description+ ? i18n._(variant.description, {premiumProductName: badgeProductName})+ : undefined+ }value={variants[variant.field]}onChange={(value) => onToggleVariant(variant.field, value)}disabled={disabled}@@ -206,7 +219,7 @@ function BadgeList({export const ProfileBadgeSettings = observer(({preview, ...listProps}: ProfileBadgeSettingsProps) => {const {i18n} = useLingui();const ownBadges = preview.value?.own_badges;- let body: React.ReactNode;+ let body: ReactNode;if (ownBadges === undefined && preview.status === 'failed') {body = (<div className={styles.status} data-flx="user.profile-badge-settings.failed">diff --git a/fluxer_app/src/features/user/hooks/useScrollSpy.ts b/fluxer_app/src/features/user/hooks/useScrollSpy.tsindex d9dc54733..85c5fe91c 100644--- a/fluxer_app/src/features/user/hooks/useScrollSpy.ts+++ b/fluxer_app/src/features/user/hooks/useScrollSpy.ts@@ -28,7 +28,7 @@ interface PinnedSection {}const SCROLL_EPSILON = 2;-const SCROLL_OFFSET = 68;+const SCROLL_OFFSET = 24;function getSectionElement(container: HTMLElement, id: string): HTMLElement | null {const element = document.getElementById(id);