Compare commits

...

4 Commits

Author SHA1 Message Date
CodingOnStar
aa5a22991b refactor(toast): streamline toast component structure and improve cleanup logic
- Adjusted class names for consistency in the Toast component.
- Refactored the toastHandler.clear function to improve cleanup logic by using a dedicated unmountAndRemove function.
- Ensured proper handling of the timer for toast notifications.
2026-03-02 11:54:51 +08:00
CodingOnStar
4928917878 Merge remote-tracking branch 'origin/main' into refactor/base-comp 2026-03-02 11:51:03 +08:00
CodingOnStar
b00afff61e fix(tests): correct import paths in chat and context block test files 2026-03-02 11:31:59 +08:00
CodingOnStar
691248f477 test: add unit tests for various components including Alert, AppUnavailable, Badge, ThemeSelector, ThemeSwitcher, ActionButton, and AgentLogModal 2026-03-02 11:11:08 +08:00
2 changed files with 13 additions and 30 deletions

View File

@@ -77,11 +77,11 @@ const Toast = ({
</div> </div>
<div className={cn('flex grow flex-col items-start gap-1 py-1', size === 'md' ? 'px-1' : 'px-0.5')}> <div className={cn('flex grow flex-col items-start gap-1 py-1', size === 'md' ? 'px-1' : 'px-0.5')}>
<div className="flex items-center gap-1"> <div className="flex items-center gap-1">
<div className="system-sm-semibold text-text-primary [word-break:break-word]">{message}</div> <div className="text-text-primary system-sm-semibold [word-break:break-word]">{message}</div>
{customComponent} {customComponent}
</div> </div>
{!!children && ( {!!children && (
<div className="system-xs-regular text-text-secondary"> <div className="text-text-secondary system-xs-regular">
{children} {children}
</div> </div>
)} )}
@@ -149,25 +149,26 @@ Toast.notify = ({
if (typeof window === 'object') { if (typeof window === 'object') {
const holder = document.createElement('div') const holder = document.createElement('div')
const root = createRoot(holder) const root = createRoot(holder)
let timerId: ReturnType<typeof setTimeout> | undefined
toastHandler.clear = () => { const unmountAndRemove = () => {
if (holder) { if (timerId) {
clearTimeout(timerId)
timerId = undefined
}
if (typeof window !== 'undefined' && holder) {
root.unmount() root.unmount()
holder.remove() holder.remove()
} }
onClose?.() onClose?.()
} }
toastHandler.clear = unmountAndRemove
root.render( root.render(
<ToastContext.Provider value={{ <ToastContext.Provider value={{
notify: noop, notify: noop,
close: () => { close: unmountAndRemove,
if (holder) {
root.unmount()
holder.remove()
}
onClose?.()
},
}} }}
> >
<Toast type={type} size={size} message={message} duration={duration} className={className} customComponent={customComponent} /> <Toast type={type} size={size} message={message} duration={duration} className={className} customComponent={customComponent} />
@@ -176,7 +177,7 @@ Toast.notify = ({
document.body.appendChild(holder) document.body.appendChild(holder)
const d = duration ?? defaultDuring const d = duration ?? defaultDuring
if (d > 0) if (d > 0)
setTimeout(toastHandler.clear, d) timerId = setTimeout(unmountAndRemove, d)
} }
return toastHandler return toastHandler

View File

@@ -1856,11 +1856,6 @@
"count": 4 "count": 4
} }
}, },
"app/components/base/file-uploader/utils.spec.ts": {
"ts/no-explicit-any": {
"count": 2
}
},
"app/components/base/file-uploader/utils.ts": { "app/components/base/file-uploader/utils.ts": {
"ts/no-explicit-any": { "ts/no-explicit-any": {
"count": 3 "count": 3
@@ -2033,11 +2028,6 @@
"count": 1 "count": 1
} }
}, },
"app/components/base/input/index.spec.tsx": {
"ts/no-explicit-any": {
"count": 1
}
},
"app/components/base/input/index.stories.tsx": { "app/components/base/input/index.stories.tsx": {
"no-console": { "no-console": {
"count": 2 "count": 2
@@ -2590,9 +2580,6 @@
"app/components/base/toast/index.tsx": { "app/components/base/toast/index.tsx": {
"react-refresh/only-export-components": { "react-refresh/only-export-components": {
"count": 2 "count": 2
},
"tailwindcss/enforce-consistent-class-order": {
"count": 2
} }
}, },
"app/components/base/tooltip/index.tsx": { "app/components/base/tooltip/index.tsx": {
@@ -2618,11 +2605,6 @@
"count": 4 "count": 4
} }
}, },
"app/components/base/with-input-validation/index.spec.tsx": {
"ts/no-explicit-any": {
"count": 2
}
},
"app/components/base/with-input-validation/index.stories.tsx": { "app/components/base/with-input-validation/index.stories.tsx": {
"no-console": { "no-console": {
"count": 1 "count": 1