From 9ad8b004544e9edcf5141f536bb6be99b49dba51 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 3 May 2026 13:51:20 -0500 Subject: memoize history Co-authored-by: Copilot --- src/web/src/components/Chat/Chat.jsx | 58 ++++++++++++++++++++++------------ src/web/src/components/Rooms/Rooms.jsx | 58 ++++++++++++++++++++-------------- 2 files changed, 73 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/web/src/components/Chat/Chat.jsx b/src/web/src/components/Chat/Chat.jsx index 086d2cd8..39dd1a44 100644 --- a/src/web/src/components/Chat/Chat.jsx +++ b/src/web/src/components/Chat/Chat.jsx @@ -23,6 +23,32 @@ const initialState = { message: '', }; +const ChatMessageHistory = React.memo( + ({ formatTimestamp, messages, selfUsername }) => { + return ( + <> + {messages.map((message) => ( + + + {formatTimestamp(message.timestamp)} + + + {message.direction === 'Out' ? selfUsername : message.username}: + + {message.message} + + ))} + + + ); + }, +); + +ChatMessageHistory.displayName = 'ChatMessageHistory'; + class Chat extends Component { constructor(props) { super(props); @@ -63,6 +89,13 @@ class Chat extends Component { // fetch all of the active conversations (but no messages) let conversations = await chat.getAll(); + // the username '..' breaks nearly everything in slskd because it's a path traversal + // sequence and no API endpoints that expect usernames in the path work + // rather than letting this sit broken, i'm making the choice to filter it out + // eslint-disable-next-line no-warning-comments + // todo: remove this filter when the API can handle '..' + conversations = conversations.filter((f) => f.username !== '..'); + // turn into a map, keyed by username // if there are no active conversations, set to an empty map if (conversations.length === 0) { @@ -257,26 +290,11 @@ class Chat extends Component { - {messages.map((message) => ( - - - {this.formatTimestamp(message.timestamp)} - - - {message.direction === 'Out' - ? user.username - : message.username} - :{' '} - - - {message.message} - - - ))} - + diff --git a/src/web/src/components/Rooms/Rooms.jsx b/src/web/src/components/Rooms/Rooms.jsx index 3d29242b..f6bdb685 100644 --- a/src/web/src/components/Rooms/Rooms.jsx +++ b/src/web/src/components/Rooms/Rooms.jsx @@ -39,6 +39,36 @@ const initialState = { }, }; +const RoomMessageHistory = React.memo( + ({ formatTimestamp, messages, onHandleContextMenu }) => { + return ( + <> + {messages.map((message) => ( +
+ onHandleContextMenu(clickEvent, message) + } + > + + + {formatTimestamp(message.timestamp)} + + {message.username}: + {message.message} + +
+ ))} + + + ); + }, +); + +RoomMessageHistory.displayName = 'RoomMessageHistory'; + class Rooms extends Component { constructor(props) { super(props); @@ -325,29 +355,11 @@ class Rooms extends Component { - {room.messages.map((message) => ( -
- this.handleContextMenu(clickEvent, message) - } - > - - - {this.formatTimestamp(message.timestamp)} - - - {message.username}:{' '} - - - {message.message} - - -
- ))} - +
-- cgit v1.2.3