add: added mentions

This commit is contained in:
Lukian 2025-04-05 17:33:23 +02:00
parent dfb6639ecf
commit 6c8f354bf6
9 changed files with 208 additions and 9 deletions

View file

@ -27,7 +27,7 @@ export default function Home() {
axios
.get("/api/activechannels")
.then((res) => {
.then((res) => {channels
setChannels(res.data)
})
.catch((err) => {
@ -123,7 +123,16 @@ export default function Home() {
<ul>
{messages?.map((message) => (
<li key={message.id}>
<p><Link to={`/u/${message.username}`}>{message.username}</Link>: {message.content}</p>
<Link to={`/u/${message.username}`}>{message.username}</Link>:{" "}
{message.content.split(" ").map((word, index) => {
if (word.startsWith("@")) {
const mention = message.mentions.find((mention) => `@${mention.username}` === word);
if (mention) {
return <Link key={index} to={`/u/${mention.username}`}>{word}</Link>;
}
}
return <span key={index}>{word} </span>;
})}
<p>In <Link to={`/c/${message.channel_name}`}>{message.channel_name}</Link></p>
<p>{new Date(message.date * 1000).toLocaleString()}</p>
</li>