Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

feat: shift-clicking opens in full view (#3554)

Jiraliteeed04cfe3b52
diff --git a/fluxer_app/src/features/forum/components/ForumPostCard.tsx b/fluxer_app/src/features/forum/components/ForumPostCard.tsx
index f9fe611cb..34e212398 100644
--- a/fluxer_app/src/features/forum/components/ForumPostCard.tsx
+++ b/fluxer_app/src/features/forum/components/ForumPostCard.tsx
@@ -19,7 +19,7 @@ import {buildMessageNotificationBody} from '@app/features/notification/utils/Mes
import Permission from '@app/features/permissions/state/Permission';
import ReadStates from '@app/features/read_state/state/ReadStates';
import {remFromPx} from '@app/features/theme/layout/RemFromPx';
-import {openThread} from '@app/features/threads/commands/ThreadNavigation';
+import {openThreadFromEvent, type ThreadOpenEvent} from '@app/features/threads/commands/ThreadNavigation';
import {lastActivityId} from '@app/features/threads/state/ChannelThreads';
import ThreadMemberships from '@app/features/threads/state/ThreadMemberships';
import FocusRing from '@app/features/ui/focus_ring/FocusRing';
@@ -140,7 +140,7 @@ export const ForumPostCard = observer(({forum, post, grid}: ForumPostCardProps)
const pinned = isPinnedPost(post);
const open = Navigation.threadId === post.id;
const lastActivity = new Date(SnowflakeUtils.extractTimestamp(lastActivityId(post)));
- const handleOpen = useCallback(() => openThread(post), [post]);
+ const handleOpen = useCallback((event: ThreadOpenEvent) => openThreadFromEvent(post, event), [post]);
const handleContextMenu = useCallback(
(event: React.MouseEvent) => {
if (MobileLayout.enabled) {
@@ -171,7 +171,7 @@ export const ForumPostCard = observer(({forum, post, grid}: ForumPostCardProps)
onKeyDown={(event) => {
if (event.key === 'Enter' || event.key === ' ') {
event.preventDefault();
- handleOpen();
+ handleOpen(event);
}
}}
onContextMenu={handleContextMenu}
diff --git a/fluxer_app/src/features/messaging/components/markdown/renderers/MentionRenderer.tsx b/fluxer_app/src/features/messaging/components/markdown/renderers/MentionRenderer.tsx
index 361488a9f..58a73c8d6 100644
--- a/fluxer_app/src/features/messaging/components/markdown/renderers/MentionRenderer.tsx
+++ b/fluxer_app/src/features/messaging/components/markdown/renderers/MentionRenderer.tsx
@@ -16,7 +16,7 @@ import SelectedGuild from '@app/features/navigation/state/SelectedGuild';
import markupStyles from '@app/features/theme/styles/Markup.module.css';
import mentionRendererStyles from '@app/features/theme/styles/MentionRenderer.module.css';
import * as ColorUtils from '@app/features/theme/utils/ColorUtils';
-import {openThread} from '@app/features/threads/commands/ThreadNavigation';
+import {openThreadFromEvent, type ThreadOpenEvent} from '@app/features/threads/commands/ThreadNavigation';
import {ThreadContextMenu} from '@app/features/threads/components/ThreadContextMenu';
import ChannelThreads from '@app/features/threads/state/ChannelThreads';
import ThreadGuilds from '@app/features/threads/state/ThreadGuilds';
@@ -59,7 +59,7 @@ interface InteractiveChannelMentionProps {
function InteractiveChannelMention({channel, roleDescription}: InteractiveChannelMentionProps): React.ReactElement {
const {isOpen, withTracking} = useContextMenuTrigger();
- const activate = () => {
+ const activate = (event: ThreadOpenEvent) => {
if (LinkChannelCommands.openLinkChannel(channel)) {
return;
}
@@ -68,7 +68,7 @@ function InteractiveChannelMention({channel, roleDescription}: InteractiveChanne
throw new Error('Interactive channel mentions must belong to a guild');
}
if (channel.isThread()) {
- openThread(channel);
+ openThreadFromEvent(channel, event);
return;
}
NavigationCommands.selectChannel(guildId, channel.id);
@@ -84,13 +84,13 @@ function InteractiveChannelMention({channel, roleDescription}: InteractiveChanne
aria-roledescription={roleDescription}
onClick={(event) => {
event.stopPropagation();
- activate();
+ activate(event);
}}
onKeyDown={(event) => {
if (!isKeyboardActivationKey(event.key)) return;
event.preventDefault();
event.stopPropagation();
- activate();
+ activate(event);
}}
onContextMenu={(event) => {
event.preventDefault();
diff --git a/fluxer_app/src/features/threads/commands/ThreadNavigation.ts b/fluxer_app/src/features/threads/commands/ThreadNavigation.ts
index cbb4b1191..7201dae50 100644
--- a/fluxer_app/src/features/threads/commands/ThreadNavigation.ts
+++ b/fluxer_app/src/features/threads/commands/ThreadNavigation.ts
@@ -8,6 +8,10 @@ import * as RouterUtils from '@app/features/navigation/utils/RouterUtils';
import ThreadPanel from '@app/features/threads/state/ThreadPanel';
import MobileLayout from '@app/features/ui/state/MobileLayout';
+export interface ThreadOpenEvent {
+ readonly shiftKey: boolean;
+}
+
export function openThread(thread: Channel, messageId?: string): void {
const guildId = thread.guildId;
if (!guildId || !thread.parentId) return;
@@ -30,6 +34,14 @@ export function openThreadFullView(thread: Channel, messageId?: string): void {
NavigationCommands.selectChannel(thread.guildId, thread.id, messageId);
}
+export function openThreadFromEvent(thread: Channel, event: ThreadOpenEvent): void {
+ if (event.shiftKey) {
+ openThreadFullView(thread);
+ return;
+ }
+ openThread(thread);
+}
+
export function closeThreadPanel(): void {
ThreadPanel.closeCreate();
const guildId = Navigation.guildId;
diff --git a/fluxer_app/src/features/threads/components/MessageThreadChip.tsx b/fluxer_app/src/features/threads/components/MessageThreadChip.tsx
index 30ca1aa50..39dbb0e75 100644
--- a/fluxer_app/src/features/threads/components/MessageThreadChip.tsx
+++ b/fluxer_app/src/features/threads/components/MessageThreadChip.tsx
@@ -4,7 +4,7 @@ import {MESSAGE_COUNT_DESCRIPTOR as D_MESSAGE_COUNT_DESCRIPTOR} from '@app/featu
import type {Message} from '@app/features/messaging/models/MessagingMessage';
import Messages from '@app/features/messaging/state/MessagingMessages';
import {buildMessageNotificationBody} from '@app/features/notification/utils/MessageNotificationPreview';
-import {openThread} from '@app/features/threads/commands/ThreadNavigation';
+import {openThreadFromEvent} from '@app/features/threads/commands/ThreadNavigation';
import styles from '@app/features/threads/components/MessageThreadChip.module.css';
import {ThreadContextMenu} from '@app/features/threads/components/ThreadContextMenu';
import ChannelThreads from '@app/features/threads/state/ChannelThreads';
@@ -33,7 +33,7 @@ export const MessageThreadChip = observer(({message}: {message: Message}) => {
<button
type="button"
className={styles.chip}
- onClick={() => openThread(thread)}
+ onClick={(event) => openThreadFromEvent(thread, event)}
onContextMenu={(event) =>
ContextMenuCommands.openFromEvent(event, ({onClose}) => (
<ThreadContextMenu
diff --git a/fluxer_app/src/features/threads/components/ThreadBrowser.tsx b/fluxer_app/src/features/threads/components/ThreadBrowser.tsx
index b489cf86e..3f21bd97d 100644
--- a/fluxer_app/src/features/threads/components/ThreadBrowser.tsx
+++ b/fluxer_app/src/features/threads/components/ThreadBrowser.tsx
@@ -10,7 +10,11 @@ import {
} from '@app/features/i18n/utils/CommonMessageDescriptors';
import {remFromPx} from '@app/features/theme/layout/RemFromPx';
import * as ThreadCommands from '@app/features/threads/commands/ThreadCommands';
-import {openCreateThread, openThread} from '@app/features/threads/commands/ThreadNavigation';
+import {
+ openCreateThread,
+ openThreadFromEvent,
+ type ThreadOpenEvent,
+} from '@app/features/threads/commands/ThreadNavigation';
import styles from '@app/features/threads/components/ThreadBrowser.module.css';
import {ThreadContextMenu} from '@app/features/threads/components/ThreadContextMenu';
import {reportThreadActionError} from '@app/features/threads/hooks/useThreadMenuData';
@@ -37,12 +41,13 @@ import {observer} from 'mobx-react-lite';
import {useCallback, useEffect, useState} from 'react';
type BrowserTab = 'active' | 'archived' | 'archivedPrivate';
+type ThreadOpenHandler = (thread: Channel, event: ThreadOpenEvent) => void;
function byLastActivity(a: Channel, b: Channel): number {
return SnowflakeUtils.compare(lastActivityId(b), lastActivityId(a));
}
-const ThreadBrowserItem = observer(({thread, onOpen}: {thread: Channel; onOpen: (thread: Channel) => void}) => {
+const ThreadBrowserItem = observer(({thread, onOpen}: {thread: Channel; onOpen: ThreadOpenHandler}) => {
const {i18n} = useLingui();
const lastActivity = new Date(SnowflakeUtils.extractTimestamp(lastActivityId(thread)));
return (
@@ -50,7 +55,7 @@ const ThreadBrowserItem = observer(({thread, onOpen}: {thread: Channel; onOpen:
<button
type="button"
className={styles.item}
- onClick={() => onOpen(thread)}
+ onClick={(event) => onOpen(thread, event)}
onContextMenu={(event) =>
ContextMenuCommands.openFromEvent(event, ({onClose}) => (
<ThreadContextMenu
@@ -103,17 +108,7 @@ function matchesTab(thread: Channel, tab: BrowserTab): boolean {
}
const SearchResults = observer(
- ({
- parent,
- query,
- tab,
- onOpen,
- }: {
- parent: Channel;
- query: string;
- tab: BrowserTab;
- onOpen: (thread: Channel) => void;
- }) => {
+ ({parent, query, tab, onOpen}: {parent: Channel; query: string; tab: BrowserTab; onOpen: ThreadOpenHandler}) => {
const {i18n} = useLingui();
const {state, retry} = useThreadSearch(parent.id, query, tab !== 'active');
const threads =
@@ -210,7 +205,7 @@ const ThreadSearchInput = ({value, onChange}: {value: string; onChange: (value:
);
};
-const ActiveThreads = observer(({parent, onOpen}: {parent: Channel; onOpen: (thread: Channel) => void}) => {
+const ActiveThreads = observer(({parent, onOpen}: {parent: Channel; onOpen: ThreadOpenHandler}) => {
const {i18n} = useLingui();
const threads = [...ChannelThreads.getActiveThreadsForParent(parent.id)].sort(byLastActivity);
if (threads.length === 0) return <EmptyState data-flx="threads.thread-browser.active-threads.empty-state" />;
@@ -249,7 +244,7 @@ const ActiveThreads = observer(({parent, onOpen}: {parent: Channel; onOpen: (thr
});
const ArchivedThreads = observer(
- ({parent, privateOnly, onOpen}: {parent: Channel; privateOnly: boolean; onOpen: (thread: Channel) => void}) => {
+ ({parent, privateOnly, onOpen}: {parent: Channel; privateOnly: boolean; onOpen: ThreadOpenHandler}) => {
const {i18n} = useLingui();
const moderator = isModeratorOfParent(parent);
const [threadIds, setThreadIds] = useState<ReadonlyArray<string>>([]);
@@ -358,9 +353,9 @@ export const ThreadBrowser = observer(
const searching = query.trim().length > 0;
const current = Channels.getChannel(parent.id) ?? parent;
const handleOpen = useCallback(
- (thread: Channel) => {
+ (thread: Channel, event: ThreadOpenEvent) => {
onClose?.();
- openThread(thread);
+ openThreadFromEvent(thread, event);
},
[onClose],
);
diff --git a/fluxer_app/src/features/threads/components/ThreadSystemMessages.tsx b/fluxer_app/src/features/threads/components/ThreadSystemMessages.tsx
index 158578da9..aabbd4fd5 100644
--- a/fluxer_app/src/features/threads/components/ThreadSystemMessages.tsx
+++ b/fluxer_app/src/features/threads/components/ThreadSystemMessages.tsx
@@ -10,7 +10,7 @@ import type {Message} from '@app/features/messaging/models/MessagingMessage';
import MessageReferences, {MessageReferenceState} from '@app/features/messaging/state/MessageReferences';
import {ComponentBus} from '@app/features/platform/utils/ComponentBus';
import messageStyles from '@app/features/theme/styles/Message.module.css';
-import {openThread} from '@app/features/threads/commands/ThreadNavigation';
+import {openThreadFromEvent} from '@app/features/threads/commands/ThreadNavigation';
import styles from '@app/features/threads/components/ThreadSystemMessages.module.css';
import ChannelThreads from '@app/features/threads/state/ChannelThreads';
import * as D from '@app/features/threads/utils/ThreadMessageDescriptors';
@@ -26,9 +26,6 @@ export const ThreadCreatedMessage = observer(({message}: {message: Message}) =>
const threadId = message.messageReference?.channel_id ?? null;
const thread = threadId ? ChannelThreads.getThread(threadId) : undefined;
const threadName = thread?.name ?? message.content;
- const handleOpen = useCallback(() => {
- if (thread) openThread(thread);
- }, [thread]);
const handleSeeAll = useCallback(() => {
ComponentBus.dispatch('THREAD_BROWSER_OPEN');
}, []);
@@ -47,7 +44,7 @@ export const ThreadCreatedMessage = observer(({message}: {message: Message}) =>
<button
type="button"
className={messageStyles.systemMessageLink}
- onClick={handleOpen}
+ onClick={(event) => openThreadFromEvent(thread, event)}
data-flx="threads.thread-created-message.system-message-link.open"
>
{threadName}