Skip to content

Commit

Permalink
refactor: separate "loading" message components
Browse files Browse the repository at this point in the history
This is a preparation for adding `useRovingTabindex()` to them.
  • Loading branch information
WofWca committed Jan 10, 2025
1 parent c247d87 commit f365874
Showing 1 changed file with 44 additions and 23 deletions.
67 changes: 44 additions & 23 deletions packages/frontend/src/components/message/MessageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -829,35 +829,17 @@ export const MessageListInner = React.memo(
} else if (message?.kind === 'loadingError') {
// TODO shall we add `useRovingTabindex` here as well?
return (
<div className='info-message' id={String(messageId.msg_id)}>
<div
className='bubble'
style={{
backgroundColor: 'rgba(55,0,0,0.5)',
}}
>
loading message {messageId.msg_id} failed:{' '}
{message.error}
</div>
</div>
<MessageLoadingError
messageId={messageId}
message={message}
/>
)
} else {
// setTimeout tells it to call method in next event loop iteration, so after rendering
// it is debounced later so we can call it here multiple times and it's ok
setTimeout(loadMissingMessages)
// TODO shall we add `useRovingTabindex` here as well?
return (
<div className='info-message' id={String(messageId.msg_id)}>
<div
className='bubble'
style={{
backgroundColor: 'rgba(55,0,0,0.5)',
}}
>
Loading Message {messageId.msg_id}
</div>
</div>
)
return <MessageLoading messageId={messageId} />
}
}
})}
Expand All @@ -877,6 +859,45 @@ export const MessageListInner = React.memo(
}
)

function MessageLoadingError({
messageId,
message,
}: {
messageId: T.MessageListItem & { kind: 'message' }
message: T.MessageLoadResult
}) {
return (
<div className='info-message' id={String(messageId.msg_id)}>
<div
className='bubble'
style={{
backgroundColor: 'rgba(55,0,0,0.5)',
}}
>
loading message {messageId.msg_id} failed: {message.error}
</div>
</div>
)
}
function MessageLoading({
messageId,
}: {
messageId: T.MessageListItem & { kind: 'message' }
}) {
return (
<div className='info-message' id={String(messageId.msg_id)}>
<div
className='bubble'
style={{
backgroundColor: 'rgba(55,0,0,0.5)',
}}
>
Loading Message {messageId.msg_id}
</div>
</div>
)
}

function JumpDownButton({
countUnreadMessages,
jumpToMessage,
Expand Down

0 comments on commit f365874

Please sign in to comment.