feat: add timestamp beside message
parent
e9aa844d29
commit
9a79f124f2
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -21,7 +21,7 @@ const useStyles = createStyles((theme) => ({
|
||||||
display: "flex",
|
display: "flex",
|
||||||
flexDirection: "row-reverse",
|
flexDirection: "row-reverse",
|
||||||
flexWrap: "nowrap",
|
flexWrap: "nowrap",
|
||||||
alignItems: "center",
|
// alignItems: "center",
|
||||||
width: "100%",
|
width: "100%",
|
||||||
marginTop: theme.spacing.xs,
|
marginTop: theme.spacing.xs,
|
||||||
marginBottom: theme.spacing.xs,
|
marginBottom: theme.spacing.xs,
|
||||||
|
@ -36,7 +36,7 @@ const useStyles = createStyles((theme) => ({
|
||||||
display: "flex",
|
display: "flex",
|
||||||
flexDirection: "row",
|
flexDirection: "row",
|
||||||
flexWrap: "nowrap",
|
flexWrap: "nowrap",
|
||||||
alignItems: "center",
|
// alignItems: "center",
|
||||||
width: "100%",
|
width: "100%",
|
||||||
marginTop: theme.spacing.xs,
|
marginTop: theme.spacing.xs,
|
||||||
marginBottom: theme.spacing.xs,
|
marginBottom: theme.spacing.xs,
|
||||||
|
@ -47,13 +47,21 @@ const useStyles = createStyles((theme) => ({
|
||||||
borderRadius: theme.radius.md,
|
borderRadius: theme.radius.md,
|
||||||
backgroundColor: theme.colors.gray[2],
|
backgroundColor: theme.colors.gray[2],
|
||||||
},
|
},
|
||||||
|
timestamp: {
|
||||||
|
display: "flex",
|
||||||
|
fontSize: theme.fontSizes.xs,
|
||||||
|
color: theme.colors.gray[5],
|
||||||
|
marginLeft: theme.spacing.xs,
|
||||||
|
marginRight: theme.spacing.xs,
|
||||||
|
alignItems: "flex-end",
|
||||||
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
const { socket, connect, emit } = useSocketStore((state) => state); // deconstructing socket and its method from socket store
|
const { socket, connect, emit } = useSocketStore((state) => state); // deconstructing socket and its method from socket store
|
||||||
|
|
||||||
const chatViewportRef = useRef<HTMLDivElement>(null); // binding chat viewport ref
|
const chatViewportRef = useRef<HTMLDivElement>(null); // binding chat viewport ref to scroll to bottom
|
||||||
const messageInputRef = useRef<HTMLInputElement>(null); // binding message input ref
|
const messageInputRef = useRef<HTMLInputElement>(null); // binding message input ref to focus
|
||||||
|
|
||||||
const [targetSocketId, setTargetSocketId] = useState<string>(""); // target socket id input value
|
const [targetSocketId, setTargetSocketId] = useState<string>(""); // target socket id input value
|
||||||
const [message, setMessage] = useState(""); // message input value
|
const [message, setMessage] = useState(""); // message input value
|
||||||
|
@ -102,7 +110,7 @@ export default function Home() {
|
||||||
<Card shadow="sm" padding="sm" radius="md" withBorder>
|
<Card shadow="sm" padding="sm" radius="md" withBorder>
|
||||||
<ChatroomTitle
|
<ChatroomTitle
|
||||||
targetSocketId={targetSocketId}
|
targetSocketId={targetSocketId}
|
||||||
handleTargetSocketIdChange={(e) => setTargetSocketId(e.target.value)}
|
setTargetSocketId={setTargetSocketId}
|
||||||
/>
|
/>
|
||||||
<Divider />
|
<Divider />
|
||||||
<ScrollArea h={"80vh"} offsetScrollbars viewportRef={chatViewportRef}>
|
<ScrollArea h={"80vh"} offsetScrollbars viewportRef={chatViewportRef}>
|
||||||
|
@ -123,6 +131,9 @@ export default function Home() {
|
||||||
>
|
>
|
||||||
{message.message}
|
{message.message}
|
||||||
</Text>
|
</Text>
|
||||||
|
<Text size="xs" className={classes.timestamp}>
|
||||||
|
{new Date(message.timestamp).toLocaleTimeString()}
|
||||||
|
</Text>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
export const SOCKET_URL = process.env.NEXT_PUBLIC_SOCKET_URL;
|
export const SOCKET_URL = process.env.NEXT_PUBLIC_SOCKET_URL;
|
||||||
|
export const environment = process.env.NODE_ENV;
|
Loading…
Reference in New Issue