Skip to content

Commit d503556

Browse files
v0.0.10
1 parent 5e09b7c commit d503556

File tree

4 files changed

+115
-0
lines changed

4 files changed

+115
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Version History
44

5+
### v0.0.10
6+
7+
- Added the `<GibberishChat/>` island.
8+
59
### v0.0.9
610

711
- Added the `<RandomQuote/>` island.

deno.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
"imports": {
2121
"@/": "./",
2222
"@carcajada/teclas": "jsr:@carcajada/teclas@^1.0.8",
23+
"@egamagz/time-ago": "jsr:@egamagz/time-ago@^2025.4.9",
2324
"@lunchbox/ui": "jsr:@lunchbox/ui@3.0.0",
25+
"@vyn/cn": "jsr:@vyn/cn@^0.1.2",
2426
"lunchbox-css": "npm:lunchbox-css@^0.1.4",
2527
"@tailwindcss/typography": "npm:@tailwindcss/typography@^0.5.16",
2628
"daisyui": "npm:daisyui@^5.0.37",

islands/GibberishChat.tsx

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import { cn } from "@vyn/cn";
2+
import { useEffect, useState } from "preact/hooks";
3+
4+
interface Message {
5+
user: 0 | 1 | 2;
6+
content: string;
7+
}
8+
9+
function generateRandomWord(length: number): string {
10+
const alphabet = "abcdefghijklmnopqrstuvwxyz";
11+
let result = "";
12+
for (let i = 0; i < length; i++) {
13+
result += alphabet.charAt(Math.floor(Math.random() * alphabet.length));
14+
}
15+
return result;
16+
}
17+
18+
function generateGibberish(words: number): string {
19+
const parts: string[] = [];
20+
for (let i = 0; i < words; i++) {
21+
const len = Math.floor(Math.random() * 7) + 2;
22+
parts.push(generateRandomWord(len));
23+
}
24+
return parts.join(" ");
25+
}
26+
27+
function transformSentence(str: string): string {
28+
if (str.length === 0) return "";
29+
return str.charAt(0).toUpperCase() + str.slice(1) + ".";
30+
}
31+
32+
const users = [
33+
generateRandomWord(2).toUpperCase(),
34+
generateRandomWord(2).toUpperCase(),
35+
"ME",
36+
];
37+
38+
export default function () {
39+
const [messages, setMessages] = useState<Message[]>([]);
40+
41+
useEffect(() => {
42+
const intervalId = setInterval(() => {
43+
const seed = Math.random();
44+
if (seed >= 0.1) return;
45+
46+
const simpleSeed = Math.trunc(seed * 100);
47+
48+
setMessages([{
49+
user: simpleSeed % 2 === 0 ? 0 : 1,
50+
content: transformSentence(generateGibberish((simpleSeed + 1) * 2)),
51+
}, ...messages]);
52+
}, 500);
53+
54+
return () => clearInterval(intervalId);
55+
}, [messages]);
56+
57+
return (
58+
<div class="col-span-full md:col-span-3 lg:col-span-4">
59+
<div class="p-1-2 bg-base-200">
60+
Gibberish Chat
61+
</div>
62+
<div class="p-1-2 dotted h-96 overflow-y-scroll flex flex-col-reverse">
63+
{messages.map((message) => (
64+
<div
65+
class={cn("chat", message.user === 2 ? "chat-end" : "chat-start")}
66+
>
67+
<div class="chat-image avatar avatar-placeholder">
68+
<div class="bg-neutral text-neutral-content w-8 rounded-full">
69+
<span class="text-xs">{users[message.user]}</span>
70+
</div>
71+
</div>
72+
<div
73+
class={cn(
74+
"chat-bubble",
75+
message.user === 2 ? "chat-bubble-primary" : null,
76+
)}
77+
>
78+
{message.content}
79+
</div>
80+
</div>
81+
))}
82+
</div>
83+
<div class="p-1-2 bg-base-200">
84+
<div class="join">
85+
<input
86+
id="gibberish-input"
87+
class="join-item input input-sm"
88+
type="text"
89+
/>
90+
<button
91+
type="button"
92+
class="join-item btn btn-sm"
93+
onClick={() =>
94+
setMessages([{
95+
user: 2,
96+
content: (document.getElementById(
97+
"gibberish-input",
98+
) as HTMLInputElement).value,
99+
}, ...messages])}
100+
>
101+
Send
102+
</button>
103+
</div>
104+
</div>
105+
</div>
106+
);
107+
}

routes/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { define } from "@/utils.ts";
22
import Logo from "@/components/Logo.tsx";
33
import RandomQuote from "@/islands/RandomQuote.tsx";
4+
import GibberishChat from "../islands/GibberishChat.tsx";
45

56
export default define.page(function Home() {
67
return (
@@ -16,6 +17,7 @@ export default define.page(function Home() {
1617
</div>
1718
</div>
1819
<RandomQuote />
20+
<GibberishChat />
1921
</main>
2022
);
2123
});

0 commit comments

Comments
 (0)