forked from github/cinny
refactor: unify join rule icon mapping and update call/space icons
- bump folds from 2.5.0 to 2.6.0 - replace separate room/space join-rule icon hooks with useJoinRuleIcons(roomType) - route join-rule icons through getRoomIconSrc for consistent room type handling - simplify getRoomIconSrc by removing the locked override path - use VolumeHighGlobe for public call rooms and VolumeHighLock for private call rooms
This commit is contained in:
8
package-lock.json
generated
8
package-lock.json
generated
@@ -33,7 +33,7 @@
|
|||||||
"emojibase-data": "15.3.2",
|
"emojibase-data": "15.3.2",
|
||||||
"file-saver": "2.0.5",
|
"file-saver": "2.0.5",
|
||||||
"focus-trap-react": "10.0.2",
|
"focus-trap-react": "10.0.2",
|
||||||
"folds": "2.5.0",
|
"folds": "2.6.0",
|
||||||
"html-dom-parser": "4.0.0",
|
"html-dom-parser": "4.0.0",
|
||||||
"html-react-parser": "4.2.0",
|
"html-react-parser": "4.2.0",
|
||||||
"i18next": "23.12.2",
|
"i18next": "23.12.2",
|
||||||
@@ -7179,9 +7179,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/folds": {
|
"node_modules/folds": {
|
||||||
"version": "2.5.0",
|
"version": "2.6.0",
|
||||||
"resolved": "https://registry.npmjs.org/folds/-/folds-2.5.0.tgz",
|
"resolved": "https://registry.npmjs.org/folds/-/folds-2.6.0.tgz",
|
||||||
"integrity": "sha512-UJhvXAQ1XnZ9w10KJwSW+frvzzWE/zcF0dH3fDVCD70RFHAxwEi0UkkVS8CaZGxZF2Wvt3qTJyTS5LW3LwwUAw==",
|
"integrity": "sha512-9353l0KFBptqUXYBJhoZ0ZEs7ofLUeSmcZEtzn23IbAM1SG7R3tTQTk24lcLKJu95qMGxuC3no8MQTQExNHUNw==",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@vanilla-extract/css": "1.9.2",
|
"@vanilla-extract/css": "1.9.2",
|
||||||
|
|||||||
@@ -45,7 +45,7 @@
|
|||||||
"emojibase-data": "15.3.2",
|
"emojibase-data": "15.3.2",
|
||||||
"file-saver": "2.0.5",
|
"file-saver": "2.0.5",
|
||||||
"focus-trap-react": "10.0.2",
|
"focus-trap-react": "10.0.2",
|
||||||
"folds": "2.5.0",
|
"folds": "2.6.0",
|
||||||
"html-dom-parser": "4.0.0",
|
"html-dom-parser": "4.0.0",
|
||||||
"html-react-parser": "4.2.0",
|
"html-react-parser": "4.2.0",
|
||||||
"i18next": "23.12.2",
|
"i18next": "23.12.2",
|
||||||
|
|||||||
@@ -16,34 +16,24 @@ import {
|
|||||||
import { JoinRule } from 'matrix-js-sdk';
|
import { JoinRule } from 'matrix-js-sdk';
|
||||||
import FocusTrap from 'focus-trap-react';
|
import FocusTrap from 'focus-trap-react';
|
||||||
import { stopPropagation } from '../utils/keyboard';
|
import { stopPropagation } from '../utils/keyboard';
|
||||||
|
import { getRoomIconSrc } from '../utils/room';
|
||||||
|
|
||||||
export type ExtraJoinRules = 'knock_restricted';
|
export type ExtraJoinRules = 'knock_restricted';
|
||||||
export type ExtendedJoinRules = JoinRule | ExtraJoinRules;
|
export type ExtendedJoinRules = JoinRule | ExtraJoinRules;
|
||||||
|
|
||||||
type JoinRuleIcons = Record<ExtendedJoinRules, IconSrc>;
|
type JoinRuleIcons = Record<ExtendedJoinRules, IconSrc>;
|
||||||
export const useRoomJoinRuleIcon = (): JoinRuleIcons =>
|
|
||||||
|
export const useJoinRuleIcons = (roomType?: string): JoinRuleIcons =>
|
||||||
useMemo(
|
useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
[JoinRule.Invite]: Icons.HashLock,
|
[JoinRule.Invite]: getRoomIconSrc(Icons, roomType, JoinRule.Invite),
|
||||||
[JoinRule.Knock]: Icons.HashLock,
|
[JoinRule.Knock]: getRoomIconSrc(Icons, roomType, JoinRule.Knock),
|
||||||
knock_restricted: Icons.Hash,
|
knock_restricted: getRoomIconSrc(Icons, roomType, JoinRule.Restricted),
|
||||||
[JoinRule.Restricted]: Icons.Hash,
|
[JoinRule.Restricted]: getRoomIconSrc(Icons, roomType, JoinRule.Restricted),
|
||||||
[JoinRule.Public]: Icons.HashGlobe,
|
[JoinRule.Public]: getRoomIconSrc(Icons, roomType, JoinRule.Public),
|
||||||
[JoinRule.Private]: Icons.HashLock,
|
[JoinRule.Private]: getRoomIconSrc(Icons, roomType, JoinRule.Private),
|
||||||
}),
|
}),
|
||||||
[]
|
[roomType]
|
||||||
);
|
|
||||||
export const useSpaceJoinRuleIcon = (): JoinRuleIcons =>
|
|
||||||
useMemo(
|
|
||||||
() => ({
|
|
||||||
[JoinRule.Invite]: Icons.SpaceLock,
|
|
||||||
[JoinRule.Knock]: Icons.SpaceLock,
|
|
||||||
knock_restricted: Icons.Space,
|
|
||||||
[JoinRule.Restricted]: Icons.Space,
|
|
||||||
[JoinRule.Public]: Icons.SpaceGlobe,
|
|
||||||
[JoinRule.Private]: Icons.SpaceLock,
|
|
||||||
}),
|
|
||||||
[]
|
|
||||||
);
|
);
|
||||||
|
|
||||||
type JoinRuleLabels = Record<ExtendedJoinRules, string>;
|
type JoinRuleLabels = Record<ExtendedJoinRules, string>;
|
||||||
|
|||||||
@@ -46,8 +46,7 @@ export const RoomIcon = forwardRef<
|
|||||||
Omit<ComponentProps<typeof Icon>, 'src'> & {
|
Omit<ComponentProps<typeof Icon>, 'src'> & {
|
||||||
joinRule?: JoinRule;
|
joinRule?: JoinRule;
|
||||||
roomType?: string;
|
roomType?: string;
|
||||||
locked?: boolean;
|
|
||||||
}
|
}
|
||||||
>(({ joinRule, roomType, locked, ...props }, ref) => (
|
>(({ joinRule, roomType, ...props }, ref) => (
|
||||||
<Icon src={getRoomIconSrc(Icons, roomType, joinRule, locked)} {...props} ref={ref} />
|
<Icon src={getRoomIconSrc(Icons, roomType, joinRule)} {...props} ref={ref} />
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -6,9 +6,8 @@ import { useAtomValue } from 'jotai';
|
|||||||
import {
|
import {
|
||||||
ExtendedJoinRules,
|
ExtendedJoinRules,
|
||||||
JoinRulesSwitcher,
|
JoinRulesSwitcher,
|
||||||
useRoomJoinRuleIcon,
|
useJoinRuleIcons,
|
||||||
useRoomJoinRuleLabel,
|
useRoomJoinRuleLabel,
|
||||||
useSpaceJoinRuleIcon,
|
|
||||||
} from '../../../components/JoinRulesSwitcher';
|
} from '../../../components/JoinRulesSwitcher';
|
||||||
import { SequenceCard } from '../../../components/sequence-card';
|
import { SequenceCard } from '../../../components/sequence-card';
|
||||||
import { SequenceCardStyle } from '../../room-settings/styles.css';
|
import { SequenceCardStyle } from '../../room-settings/styles.css';
|
||||||
@@ -75,8 +74,7 @@ export function RoomJoinRules({ permissions }: RoomJoinRulesProps) {
|
|||||||
return r;
|
return r;
|
||||||
}, [allowKnockRestricted, allowRestricted, allowKnock, space]);
|
}, [allowKnockRestricted, allowRestricted, allowKnock, space]);
|
||||||
|
|
||||||
const icons = useRoomJoinRuleIcon();
|
const icons = useJoinRuleIcons(room.getType());
|
||||||
const spaceIcons = useSpaceJoinRuleIcon();
|
|
||||||
const labels = useRoomJoinRuleLabel();
|
const labels = useRoomJoinRuleLabel();
|
||||||
|
|
||||||
const [submitState, submit] = useAsyncCallback(
|
const [submitState, submit] = useAsyncCallback(
|
||||||
@@ -137,7 +135,7 @@ export function RoomJoinRules({ permissions }: RoomJoinRulesProps) {
|
|||||||
}
|
}
|
||||||
after={
|
after={
|
||||||
<JoinRulesSwitcher
|
<JoinRulesSwitcher
|
||||||
icons={room.isSpaceRoom() ? spaceIcons : icons}
|
icons={icons}
|
||||||
labels={labels}
|
labels={labels}
|
||||||
rules={joinRules}
|
rules={joinRules}
|
||||||
value={rule}
|
value={rule}
|
||||||
|
|||||||
@@ -161,7 +161,8 @@ export const getOrphanParents = (roomToParents: RoomToParents, roomId: string):
|
|||||||
|
|
||||||
export const isMutedRule = (rule: IPushRule) =>
|
export const isMutedRule = (rule: IPushRule) =>
|
||||||
// Check for empty actions (new spec) or dont_notify (deprecated)
|
// Check for empty actions (new spec) or dont_notify (deprecated)
|
||||||
(rule.actions.length === 0 || rule.actions[0] === 'dont_notify') && rule.conditions?.[0]?.kind === 'event_match';
|
(rule.actions.length === 0 || rule.actions[0] === 'dont_notify') &&
|
||||||
|
rule.conditions?.[0]?.kind === 'event_match';
|
||||||
|
|
||||||
export const findMutedRule = (overrideRules: IPushRule[], roomId: string) =>
|
export const findMutedRule = (overrideRules: IPushRule[], roomId: string) =>
|
||||||
overrideRules.find((rule) => rule.rule_id === roomId && isMutedRule(rule));
|
overrideRules.find((rule) => rule.rule_id === roomId && isMutedRule(rule));
|
||||||
@@ -260,57 +261,41 @@ export const getUnreadInfos = (mx: MatrixClient): UnreadInfo[] => {
|
|||||||
export const getRoomIconSrc = (
|
export const getRoomIconSrc = (
|
||||||
icons: Record<IconName, IconSrc>,
|
icons: Record<IconName, IconSrc>,
|
||||||
roomType?: string,
|
roomType?: string,
|
||||||
joinRule?: JoinRule,
|
joinRule?: JoinRule
|
||||||
locked?: boolean
|
|
||||||
): IconSrc => {
|
): IconSrc => {
|
||||||
type RoomIcons = {
|
if (roomType === RoomType.Space) {
|
||||||
base: IconSrc;
|
if (joinRule === JoinRule.Public) return icons.SpaceGlobe;
|
||||||
locked: IconSrc;
|
if (
|
||||||
public: IconSrc;
|
joinRule === JoinRule.Invite ||
|
||||||
};
|
joinRule === JoinRule.Knock ||
|
||||||
|
joinRule === JoinRule.Private
|
||||||
const roomTypeIcons: Record<string, RoomIcons> = {
|
) {
|
||||||
[RoomType.Call]: {
|
return icons.SpaceLock;
|
||||||
base: icons.VolumeHigh,
|
|
||||||
locked: icons.Lock,
|
|
||||||
public: icons.VolumeHigh,
|
|
||||||
},
|
|
||||||
[RoomType.Space]: {
|
|
||||||
base: icons.Space,
|
|
||||||
locked: icons.SpaceLock,
|
|
||||||
public: icons.SpaceGlobe,
|
|
||||||
},
|
|
||||||
default: {
|
|
||||||
base: icons.Hash,
|
|
||||||
locked: icons.HashLock,
|
|
||||||
public: icons.HashGlobe,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const roomIcons = roomTypeIcons[roomType ?? 'default'] ?? roomTypeIcons.default;
|
|
||||||
|
|
||||||
let roomIcon = roomIcons.base;
|
|
||||||
|
|
||||||
if (locked) {
|
|
||||||
roomIcon = roomIcons.locked;
|
|
||||||
} else {
|
|
||||||
switch (joinRule) {
|
|
||||||
case JoinRule.Invite:
|
|
||||||
case JoinRule.Knock:
|
|
||||||
roomIcon = roomIcons.locked;
|
|
||||||
break;
|
|
||||||
case JoinRule.Restricted:
|
|
||||||
roomIcon = roomIcons.base;
|
|
||||||
break;
|
|
||||||
case JoinRule.Public:
|
|
||||||
roomIcon = roomIcons.public;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
return icons.Space;
|
||||||
}
|
}
|
||||||
|
|
||||||
return roomIcon;
|
if (roomType === RoomType.Call) {
|
||||||
|
if (joinRule === JoinRule.Public) return icons.VolumeHighGlobe;
|
||||||
|
if (
|
||||||
|
joinRule === JoinRule.Invite ||
|
||||||
|
joinRule === JoinRule.Knock ||
|
||||||
|
joinRule === JoinRule.Private
|
||||||
|
) {
|
||||||
|
return icons.VolumeHighLock;
|
||||||
|
}
|
||||||
|
return icons.VolumeHigh;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (joinRule === JoinRule.Public) return icons.HashGlobe;
|
||||||
|
if (
|
||||||
|
joinRule === JoinRule.Invite ||
|
||||||
|
joinRule === JoinRule.Knock ||
|
||||||
|
joinRule === JoinRule.Private
|
||||||
|
) {
|
||||||
|
return icons.HashLock;
|
||||||
|
}
|
||||||
|
return icons.Hash;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getRoomAvatarUrl = (
|
export const getRoomAvatarUrl = (
|
||||||
|
|||||||
Reference in New Issue
Block a user