Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prepare recs starter for haiku 0.0.1 #1

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions clients/react-recs-app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getEntityIdFromKeys } from "@dojoengine/utils";
import { useDojo } from "./dojo/useDojo";
import { Button } from "./components/ui/button";
import * as torii from "@dojoengine/torii-client";
import { HaikuMessages } from "./components/HaikuMessages";

function App() {
const {
Expand Down Expand Up @@ -139,6 +140,9 @@ function App() {
<div>Role: {dungeon?.role}</div>
</div>
</div>
<div className="absolute bottom-0 left-0 p-4" id="haiku-messages-container">
<HaikuMessages />
</div>
</div>
</>
);
Expand Down
70 changes: 70 additions & 0 deletions clients/react-recs-app/src/components/HaikuMessages.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { defineComponentSystem } from "@dojoengine/recs";
import { useEffect, useRef, useState } from "react";
import { useDojo } from "../dojo/useDojo";

export const HaikuMessages = () => {
const dojo = useDojo();
const messagesEndRef = useRef<HTMLDivElement>(null);

const [promptMessages, setPromptMessages] = useState<
Array<{ message: string; timestamp: Date }>
>([]);

useEffect(() => {
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
}, [promptMessages]);

useEffect(() => {
defineComponentSystem(
dojo.world,
dojo.setup.contractComponents.PromptMessage,
(update) => {
const newMessage = {
message: update.value[0]?.prompt,
timestamp: new Date((update.value[0]?.timestamp || 0) * 1000),
};
console.log(newMessage);
setPromptMessages((prevMessages) => {
const updatedMessages = [...prevMessages, newMessage];
return updatedMessages.sort(
(a, b) => b.timestamp.getTime() - a.timestamp.getTime()
);
});
}
);
}, []);

return (
<div
className="border-4 border-red-800 rounded-2xl p-7 w-[800px] mx-auto my-5 bg-white"
>
<h2
className="mb-7 pb-4 border-b-2 border-[#B22222] text-[#B22222] text-center text-3xl tracking-wider"
>
Haiku Messages 🖌️
</h2>
<div
className="max-h-[200px] overflow-y-auto pr-2.5 flex flex-col-reverse"
>
<div ref={messagesEndRef} />
{promptMessages.map((messageObj, index) => (
<div
key={index}
className="my-2.5 p-4 bg-white bg-opacity-70 border border-[#D2B48C] shadow-md rounded-lg relative"
>
<div
className="whitespace-pre-wrap font-normal text-gray-700 leading-relaxed text-center"
>
{messageObj.message}
</div>
<div
className="text-xs text-[#B22222] mt-3 text-right italic"
>
{messageObj.timestamp.toLocaleString()}
</div>
</div>
))}
</div>
</div>
);
};
Loading