Skip to content

Commit

Permalink
feat: allow sending toast notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
celeriev committed Jan 17, 2025
1 parent 32d7fd8 commit 6eb4f4f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
3 changes: 2 additions & 1 deletion frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ export default defineConfig({
plugins: [react(), tsconfigPaths(), svgr()],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
'@': path.resolve(__dirname, './src'),
// To prevent conflicts with packages in @chainlit/react-client, we need to specify the resolution paths for these dependencies.
react: path.resolve(__dirname, './node_modules/react'),
'usehooks-ts': path.resolve(__dirname, './node_modules/usehooks-ts'),
sonner: path.resolve(__dirname, './node_modules/sonner'),
lodash: path.resolve(__dirname, './node_modules/lodash'),
recoil: path.resolve(__dirname, './node_modules/recoil')
}
Expand Down
1 change: 1 addition & 0 deletions libs/react-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"jwt-decode": "^3.1.2",
"lodash": "^4.17.21",
"socket.io-client": "^4.7.2",
"sonner": "^1.7.1",
"swr": "^2.2.2",
"uuid": "^9.0.0"
},
Expand Down
14 changes: 14 additions & 0 deletions libs/react-client/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions libs/react-client/src/useChatSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
useSetRecoilState
} from 'recoil';
import io from 'socket.io-client';
import { toast } from 'sonner';
import {
actionState,
askUserState,
Expand Down Expand Up @@ -333,6 +334,31 @@ const useChatSession = () => {
window.parent.postMessage(data, '*');
}
});

socket.on('toast', (data: { type: string; message: string }) => {
if (!data.message) {
console.warn('No message received for toast.');
return;
}

switch (data.type) {
case 'info':
toast.info(data.message);
break;
case 'error':
toast.error(data.message);
break;
case 'success':
toast.success(data.message);
break;
case 'warning':
toast.warning(data.message);
break;
default:
toast(data.message);
break;
}
});
},
[setSession, sessionId, idToResume, chatProfile]
);
Expand Down

0 comments on commit 6eb4f4f

Please sign in to comment.