Skip to content

Commit

Permalink
More suggestions addressed
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin Koval committed Dec 14, 2024
1 parent 5c3c094 commit af02cf8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
4 changes: 2 additions & 2 deletions ui/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect } from 'react'
import { Helmet } from 'react-helmet'
import Routes from './components/routes/Routes'
import Messages from './components/messages/Messages'
import MessagesWithProvider from './components/messages/Messages'
import { useTranslation } from 'react-i18next'
import { loadTranslations } from './localization'
import { useLocation } from 'react-router'
Expand Down Expand Up @@ -30,7 +30,7 @@ const App = () => {
/>
</Helmet>
<Routes />
<Messages />
<MessagesWithProvider />
</>
)
}
Expand Down
10 changes: 6 additions & 4 deletions ui/src/components/messages/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ const Message = forwardRef(
{ onDismiss, header, children, content, negative, positive }: MessageProps,
ref: React.ForwardedRef<HTMLDivElement>
) => {
let backgroundColor = 'bg-white dark:bg-dark-bg2'
if (negative) backgroundColor = 'bg-red-100 dark:bg-red-900'
if (positive) backgroundColor = 'bg-green-100 dark:bg-green-900'
const backgroundColorClass = negative
? 'bg-red-100 dark:bg-red-900'
: positive
? 'bg-green-100 dark:bg-green-900'
: 'bg-white dark:bg-dark-bg2'

return (
<div
ref={ref}
className={`${backgroundColor} shadow-md border rounded p-2 relative`}
className={`${backgroundColorClass} shadow-md border rounded p-2 relative`}
>
<button type="button" onClick={onDismiss} className="absolute top-3 right-2">
<DismissIcon className="w-[10px] h-[10px] text-gray-700 dark:text-gray-200" />
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/messages/MessageState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type MessageContextType = {

const MessageContext = createContext<MessageContextType | undefined>(undefined)

export const useMessageState = () => {
export const useMessageState = (): MessageContextType => {
const context = useContext(MessageContext)
if (context === undefined) {
throw new Error('useMessageState must be used within a MessageProvider')
Expand Down
8 changes: 7 additions & 1 deletion ui/src/components/messages/Messages.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ import { NotificationType } from '../../__generated__/globalTypes'
import { MessageProvider } from './MessageState'
import MessagePlain from './Message'
import MessageProgress from './MessageProgress'
import { Message } from './SubscriptionsHook'

interface MockSubscriptionsHookProps {
messages: Message[]
setMessages: React.Dispatch<React.SetStateAction<Message[]>>
}

// Define the mock for SubscriptionsHook before using it
const MockSubscriptionsHook = ({ messages, setMessages }: any) => {
const MockSubscriptionsHook = ({ messages, setMessages }: MockSubscriptionsHookProps) => {
return (
<div>
<button
Expand Down
5 changes: 3 additions & 2 deletions ui/src/components/sidebar/SidebarDownloadMedia.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ const downloadMediaShowProgress =
const totalBytes = Number(response.headers.get('content-length'))
const reader = response.body?.getReader()
const data = new Uint8Array(totalBytes)
const DOWNLOAD_COMPLETE_NOTIFICATION_DURATION = 2000

if (reader == null) {
throw new Error('Download reader is null')
Expand All @@ -112,7 +113,7 @@ const downloadMediaShowProgress =
reader.cancel('Download canceled by user')
}

const notifyKey = Math.random().toString(26)
const notifyKey = `download-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`
const { add, removeKey } = useMessageState()

add({
Expand Down Expand Up @@ -168,7 +169,7 @@ const downloadMediaShowProgress =

setTimeout(() => {
removeKey(notifyKey)
}, 2000)
}, DOWNLOAD_COMPLETE_NOTIFICATION_DURATION)

return new Blob([data.buffer], {
type: response.headers.get('content-type') || 'application/octet-stream',
Expand Down

0 comments on commit af02cf8

Please sign in to comment.