Skip to content

Commit 6abaaa3

Browse files
committed
Add chat functionality: Integrate socket.io for real-time messaging, implement EmbedChat and EmbedChatMessage components, and enhance message handling with new message types. Update sidebar to include chat navigation and improve localization for chat features.
1 parent d086112 commit 6abaaa3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+5229
-82
lines changed

package-lock.json

Lines changed: 87 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"react-tag-input": "^6.10.3",
4242
"react-toastify": "^10.0.5",
4343
"recharts": "^2.12.7",
44+
"socket.io-client": "^4.8.1",
4445
"tailwind-merge": "^2.4.0",
4546
"tailwindcss-animate": "^1.0.7",
4647
"uuid": "^10.0.0",

src/components/sidebar.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ function Sidebar() {
3636
icon: LayoutDashboard,
3737
path: "dashboard",
3838
},
39+
{
40+
id: "chat",
41+
title: t("sidebar.chat"),
42+
icon: MessageCircle,
43+
path: "chat",
44+
},
3945
{
4046
navLabel: true,
4147
title: t("sidebar.configurations"),
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
import React, { createContext, useContext } from "react";
2+
import { useSearchParams } from "react-router-dom";
3+
4+
import { useTheme } from "@/components/theme-provider";
5+
6+
interface EmbedColorsContextType {
7+
backgroundColor: string;
8+
textForegroundColor: string;
9+
primaryColor: string;
10+
fromMeBubbleColor: string;
11+
fromMeForegroundColor: string;
12+
fromOtherBubbleColor: string;
13+
fromOtherForegroundColor: string;
14+
fromMeQuotedBubbleColor: string;
15+
fromOtherQuotedBubbleColor: string;
16+
inputBackgroundColor: string;
17+
inputTextForegroundColor: string;
18+
inputIconsMainColor: string;
19+
}
20+
21+
const EmbedColorsContext = createContext<EmbedColorsContextType>({
22+
backgroundColor: "",
23+
textForegroundColor: "",
24+
primaryColor: "",
25+
fromMeBubbleColor: "",
26+
fromMeForegroundColor: "",
27+
fromOtherBubbleColor: "",
28+
fromOtherForegroundColor: "",
29+
fromMeQuotedBubbleColor: "",
30+
fromOtherQuotedBubbleColor: "",
31+
inputBackgroundColor: "",
32+
inputTextForegroundColor: "",
33+
inputIconsMainColor: "",
34+
});
35+
36+
export function EmbedColorsProvider({
37+
children,
38+
}: {
39+
children: React.ReactNode;
40+
}) {
41+
const [searchParams] = useSearchParams();
42+
const { theme } = useTheme();
43+
const backgroundColor = searchParams.get("backgroundColor");
44+
const textForegroundColor = searchParams.get("textForegroundColor");
45+
const primaryColor = searchParams.get("primaryColor");
46+
const fromMeBubbleColor = searchParams.get("fromMeBubbleColor");
47+
const fromMeForegroundColor = searchParams.get("fromMeForegroundColor");
48+
const fromOtherBubbleColor = searchParams.get("fromOtherBubbleColor");
49+
const fromOtherForegroundColor = searchParams.get("fromOtherForegroundColor");
50+
const fromMeQuotedBubbleColor = searchParams.get("fromMeQuotedBubbleColor");
51+
const fromOtherQuotedBubbleColor = searchParams.get(
52+
"fromOtherQuotedBubbleColor",
53+
);
54+
const inputBackgroundColor = searchParams.get("inputBackgroundColor");
55+
const inputTextForegroundColor = searchParams.get("inputTextForegroundColor");
56+
const inputIconsMainColor = searchParams.get("inputIconsMainColor");
57+
const getDefaultBackgroundColor = () => {
58+
if (theme === "dark") {
59+
return "#0f0f0f";
60+
}
61+
return "#faf9fa";
62+
};
63+
64+
const getDefaultTextForegroundColor = () => {
65+
if (theme === "dark") {
66+
return "#faf9fa";
67+
}
68+
return "#020202";
69+
};
70+
71+
const getDefaultPrimaryColor = () => {
72+
if (theme === "dark") {
73+
return "#0b332a";
74+
}
75+
return "#e0f0f0";
76+
};
77+
78+
const getDefaultFromMeBubbleColor = () => {
79+
if (theme === "dark") {
80+
return "#0b332a";
81+
}
82+
return "#c8fff2";
83+
};
84+
85+
const getDefaultFromMeForegroundColor = () => {
86+
if (theme === "dark") {
87+
return "#ffffff";
88+
}
89+
return "#020202";
90+
};
91+
92+
const getDefaultFromOtherBubbleColor = () => {
93+
if (theme === "dark") {
94+
return "#1d2724";
95+
}
96+
return "#e0f0f0";
97+
};
98+
99+
const getDefaultFromOtherForegroundColor = () => {
100+
if (theme === "dark") {
101+
return "#ffffff";
102+
}
103+
return "#020202";
104+
};
105+
106+
const getDefaultInputBackgroundColor = () => {
107+
if (theme === "dark") {
108+
return "#161616";
109+
}
110+
return "#e0f0f0";
111+
};
112+
113+
const getDefaultInputTextForegroundColor = () => {
114+
if (theme === "dark") {
115+
return "#faf9fa";
116+
}
117+
return "#020202";
118+
};
119+
120+
const getDefaultFromMeQuotedBubbleColor = () => {
121+
if (theme === "dark") {
122+
return "#1f463d";
123+
}
124+
return "#aff7e6";
125+
};
126+
127+
const getDefaultFromOtherQuotedBubbleColor = () => {
128+
if (theme === "dark") {
129+
return "#0f1413";
130+
}
131+
return "#d2e2e2";
132+
};
133+
134+
const getDefaultInputIconsMainColor = () => {
135+
if (theme === "dark") {
136+
return "#0e6451";
137+
}
138+
return "#0b332a";
139+
};
140+
141+
return (
142+
<EmbedColorsContext.Provider
143+
value={{
144+
backgroundColor: backgroundColor || getDefaultBackgroundColor(),
145+
textForegroundColor:
146+
textForegroundColor || getDefaultTextForegroundColor(),
147+
primaryColor: primaryColor || getDefaultPrimaryColor(),
148+
fromMeBubbleColor: fromMeBubbleColor || getDefaultFromMeBubbleColor(),
149+
fromMeForegroundColor:
150+
fromMeForegroundColor || getDefaultFromMeForegroundColor(),
151+
fromOtherBubbleColor:
152+
fromOtherBubbleColor || getDefaultFromOtherBubbleColor(),
153+
fromOtherForegroundColor:
154+
fromOtherForegroundColor || getDefaultFromOtherForegroundColor(),
155+
fromMeQuotedBubbleColor:
156+
fromMeQuotedBubbleColor || getDefaultFromMeQuotedBubbleColor(),
157+
fromOtherQuotedBubbleColor:
158+
fromOtherQuotedBubbleColor || getDefaultFromOtherQuotedBubbleColor(),
159+
inputBackgroundColor:
160+
inputBackgroundColor || getDefaultInputBackgroundColor(),
161+
inputTextForegroundColor:
162+
inputTextForegroundColor || getDefaultInputTextForegroundColor(),
163+
inputIconsMainColor:
164+
inputIconsMainColor || getDefaultInputIconsMainColor(),
165+
}}
166+
>
167+
{children}
168+
</EmbedColorsContext.Provider>
169+
);
170+
}
171+
172+
export const useEmbedColors = () => useContext(EmbedColorsContext);

0 commit comments

Comments
 (0)