@powerhousedao/academy 5.1.0-staging.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -1148
- package/blog/BeyondCommunication-ABlueprintForDevelopment.md +1 -2
- package/blog/TheChallengeOfChange.md +0 -1
- package/docs/academy/00-EthereumArgentinaHackathon.md +207 -0
- package/docs/academy/01-GetStarted/00-ExploreDemoPackage.mdx +27 -24
- package/docs/academy/01-GetStarted/01-CreateNewPowerhouseProject.md +10 -155
- package/docs/academy/01-GetStarted/02-DefineToDoListDocumentModel.md +35 -122
- package/docs/academy/01-GetStarted/03-ImplementOperationReducers.md +155 -178
- package/docs/academy/01-GetStarted/04-BuildToDoListEditor.md +218 -0
- package/docs/academy/{02-MasteryTrack/01-BuilderEnvironment → 01-GetStarted}/05-VetraStudio.md +22 -62
- package/docs/academy/01-GetStarted/06-ReactorMCP.md +58 -0
- package/docs/academy/01-GetStarted/_04-BuildToDoListEditor +1 -1
- package/docs/academy/02-MasteryTrack/01-BuilderEnvironment/03-BuilderTools.md +2 -2
- package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/02-SpecifyTheStateSchema.md +44 -75
- package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/03-SpecifyDocumentOperations.md +22 -28
- package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/04-UseTheDocumentModelGenerator.md +31 -28
- package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/05-ImplementDocumentReducers.md +206 -211
- package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/06-ImplementDocumentModelTests.md +62 -176
- package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/07-ExampleToDoListRepository.md +0 -21
- package/docs/academy/02-MasteryTrack/03-BuildingUserExperiences/01-BuildingDocumentEditors.md +319 -309
- package/docs/academy/02-MasteryTrack/03-BuildingUserExperiences/06-DocumentTools/00-DocumentToolbar.mdx +0 -4
- package/docs/academy/02-MasteryTrack/03-BuildingUserExperiences/06-DocumentTools/01-OperationHistory.md +0 -4
- package/docs/academy/02-MasteryTrack/05-Launch/04-ConfigureEnvironment.md +1 -1
- package/docs/academy/03-ExampleUsecases/Chatroom/02-CreateNewPowerhouseProject.md +35 -111
- package/docs/academy/03-ExampleUsecases/Chatroom/03-DefineChatroomDocumentModel.md +79 -195
- package/docs/academy/03-ExampleUsecases/Chatroom/04-ImplementOperationReducers.md +241 -435
- package/docs/academy/03-ExampleUsecases/Chatroom/05-ImplementChatroomEditor.md +27 -388
- package/docs/academy/03-ExampleUsecases/Chatroom/06-LaunchALocalReactor.md +7 -95
- package/docs/academy/03-ExampleUsecases/Chatroom/_category_.json +1 -1
- package/docs/academy/04-APIReferences/00-PowerhouseCLI.md +2 -6
- package/docs/academy/04-APIReferences/01-ReactHooks.md +501 -291
- package/docs/academy/05-Architecture/00-PowerhouseArchitecture.md +39 -7
- package/docs/academy/05-Architecture/02-ReferencingMonorepoPackages +65 -0
- package/docs/academy/05-Architecture/04-MovingBeyondCRUD +61 -0
- package/docs/academy/06-ComponentLibrary/00-DocumentEngineering.md +24 -72
- package/docs/academy/08-Glossary.md +0 -7
- package/docusaurus.config.ts +3 -28
- package/package.json +1 -1
- package/sidebars.ts +13 -49
- package/src/css/custom.css +18 -26
- package/docs/academy/01-GetStarted/04-WriteDocumentModelTests.md +0 -425
- package/docs/academy/01-GetStarted/05-BuildToDoListEditor.md +0 -557
- package/docs/academy/02-MasteryTrack/01-BuilderEnvironment/images/Modules.png +0 -0
- package/docs/academy/02-MasteryTrack/01-BuilderEnvironment/images/VetraStudioDrive.png +0 -0
- package/docs/academy/02-MasteryTrack/05-Launch/05-DockerDeployment.md +0 -384
- package/docs/academy/03-ExampleUsecases/TodoList/00-GetTheStarterCode.md +0 -24
- package/docs/academy/03-ExampleUsecases/TodoList/01-GenerateTodoListDocumentModel.md +0 -211
- package/docs/academy/03-ExampleUsecases/TodoList/02-ImplementTodoListDocumentModelReducerOperationHandlers.md +0 -171
- package/docs/academy/03-ExampleUsecases/TodoList/03-AddTestsForTodoListActions.md +0 -462
- package/docs/academy/03-ExampleUsecases/TodoList/04-GenerateTodoListDocumentEditor.md +0 -45
- package/docs/academy/03-ExampleUsecases/TodoList/05-ImplementTodoListDocumentEditorUIComponents.md +0 -422
- package/docs/academy/03-ExampleUsecases/TodoList/06-GenerateTodoDriveExplorer.md +0 -61
- package/docs/academy/03-ExampleUsecases/TodoList/07-AddSharedComponentForShowingTodoListStats.md +0 -384
- package/docs/academy/03-ExampleUsecases/TodoList/_category_.json +0 -8
- package/docs/academy/03-ExampleUsecases/VetraPackageLibrary/VetraPackageLibrary.md +0 -7
- package/docs/academy/03-ExampleUsecases/VetraPackageLibrary/_category_.json +0 -9
- package/docs/academy/04-APIReferences/06-VetraRemoteDrive.md +0 -160
- package/docs/academy/04-APIReferences/renown-sdk/00-Overview.md +0 -316
- package/docs/academy/04-APIReferences/renown-sdk/01-Authentication.md +0 -672
- package/docs/academy/04-APIReferences/renown-sdk/02-APIReference.md +0 -957
- package/docs/academy/04-APIReferences/renown-sdk/_category_.json +0 -8
- package/docs/academy/10-TodoListTutorial/02-ImplementTodoListDocumentModelReducerOperationHandlers.md +0 -171
- package/docs/academy/10-TodoListTutorial/03-AddTestsForTodoListActions.md +0 -462
- package/docs/academy/10-TodoListTutorial/05-ImplementTodoListDocumentEditorUIComponents.md +0 -422
- package/docs/academy/10-TodoListTutorial/07-AddSharedComponentForShowingTodoListStats.md +0 -370
- package/static/img/Vetra-logo-dark.svg +0 -11
- package/static/img/vetra-logo-light.svg +0 -11
- /package/docs/academy/02-MasteryTrack/03-BuildingUserExperiences/06-DocumentTools/{02-RevisionHistoryTimeline/360/237/232/247" → 02-RevisionHistoryTimeline} +0 -0
- /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /01-WhatIsADocumentModel" → 01-WhatIsADocumentModel} +0 -0
- /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /02-DAOandDocumentsModelsQ+A" → 02-DAOandDocumentsModelsQ+A} +0 -0
- /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /02-domain-modeling" → 02-domain-modeling} +0 -0
- /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /03-BenefitsOfDocumentModels" → 03-BenefitsOfDocumentModels} +0 -0
- /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /04-UtilitiesAndTips" → 04-UtilitiesAndTips} +0 -0
- /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /05-best-practices" → 05-best-practices} +0 -0
- /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /_category_.json" → _category_.json} +0 -0
- /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /three-data-layers.png" → three-data-layers.png} +0 -0
|
@@ -1,257 +1,40 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Implement Chatroom Editor
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
📦 **Reference Code**: [chatroom-demo](https://github.com/powerhouse-inc/chatroom-demo)
|
|
5
|
-
|
|
6
|
-
This tutorial covers building the ChatRoom editor:
|
|
7
|
-
1. **Editor Scaffolding**: Generating the editor template with `ph generate --editor`
|
|
8
|
-
2. **Component Implementation**: Building a complete, interactive chat UI with components
|
|
9
|
-
|
|
10
|
-
Explore the complete implementation in the `editors/chat-room-editor/` directory.
|
|
11
|
-
:::
|
|
12
|
-
|
|
13
|
-
<details>
|
|
14
|
-
<summary>📖 How to use this tutorial</summary>
|
|
15
|
-
|
|
16
|
-
This tutorial shows building from **generated scaffolding** to a **complete chat UI**.
|
|
17
|
-
|
|
18
|
-
### Compare your generated editor
|
|
19
|
-
|
|
20
|
-
After running `pnpm generate --editor`:
|
|
21
|
-
|
|
22
|
-
```bash
|
|
23
|
-
# Compare generated scaffolding with the reference
|
|
24
|
-
git diff tutorial/main -- editors/chat-room-editor/
|
|
25
|
-
|
|
26
|
-
# View the generated editor template
|
|
27
|
-
git show tutorial/main:editors/chat-room-editor/editor.tsx
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
### Browse the complete implementation
|
|
31
|
-
|
|
32
|
-
Explore the production-ready component structure:
|
|
33
|
-
|
|
34
|
-
```bash
|
|
35
|
-
# List all components in the reference
|
|
36
|
-
git ls-tree -r --name-only tutorial/main editors/chat-room-editor/components/
|
|
37
|
-
|
|
38
|
-
# View a specific component
|
|
39
|
-
git show tutorial/main:editors/chat-room-editor/components/ChatRoom/ChatRoom.tsx
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
### Visual comparison with GitHub Desktop
|
|
43
|
-
|
|
44
|
-
After committing your editor code:
|
|
45
|
-
1. **Branch** menu → **"Compare to Branch..."**
|
|
46
|
-
2. Select `tutorial/main`
|
|
47
|
-
3. See all your custom components vs. the reference implementation
|
|
48
|
-
|
|
49
|
-
See step 1 for detailed GitHub Desktop instructions.
|
|
50
|
-
|
|
51
|
-
</details>
|
|
52
|
-
|
|
53
|
-
In this chapter we will continue with the interface or editor implementation of the **ChatRoom** document model. This means you will create a user interface for the **ChatRoom** document model which will be used inside the Connect app to visualize your chatroom, send messages, and react with emojis.
|
|
3
|
+
In this section you will implement the `Chatroom` document model editor. This means you will create a simple user interface for the `Chatroom` document model which will be used inside the Connect app to visualise our chatroom, send messages and emoji reactions.
|
|
54
4
|
|
|
55
5
|
## Generate the editor template
|
|
56
6
|
|
|
57
|
-
Run
|
|
58
|
-
This command reads the **ChatRoom** document model definition from the `document-models` folder and generates the editor template in the `editors/chat-room-editor` folder.
|
|
59
|
-
|
|
60
|
-
```bash
|
|
61
|
-
pnpm generate --editor chat-room-editor --document-types powerhouse/chat-room
|
|
62
|
-
```
|
|
7
|
+
Run below command to generate the editor template for the `Chatroom` document model. This command reads the `Chatroom` document model definition from the `document-models` folder and generates the editor template in the `editors/chat-room/editor.tsx` folder.
|
|
63
8
|
|
|
64
|
-
Notice the `--editor` flag which
|
|
9
|
+
Notice the `--editor` flag which defines the `chatroom` document model editor. And the `--document-types` flag which defines the document type `powerhouse/chatroom`.
|
|
65
10
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
```
|
|
69
|
-
editors/chat-room-editor/
|
|
70
|
-
├── components/
|
|
71
|
-
│ └── EditName.tsx # Auto-generated component for editing document name
|
|
72
|
-
├── editor.tsx # Main editor component (to be customized)
|
|
73
|
-
└── module.ts # Editor module configuration
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
Navigate to the `editors/chat-room-editor/editor.tsx` file and open it in your editor. You'll see a basic template ready for customization.
|
|
77
|
-
|
|
78
|
-
### Editor implementation options
|
|
79
|
-
|
|
80
|
-
When building your editor component within the Powerhouse ecosystem, you have several options for styling:
|
|
81
|
-
|
|
82
|
-
1. **Default HTML Styling:** Standard HTML tags will render with default styles offered through the boilerplate.
|
|
83
|
-
2. **Tailwind CSS:** Connect Studio comes with Tailwind CSS integrated. You can directly use Tailwind utility classes.
|
|
84
|
-
3. **Custom CSS Files:** You can import traditional CSS files to apply custom styles.
|
|
85
|
-
|
|
86
|
-
Connect Studio provides a dynamic local environment. By running `ph connect`, you can visualize your components instantly as you build them.
|
|
87
|
-
|
|
88
|
-
## Build the editor with components
|
|
89
|
-
|
|
90
|
-
We'll build the editor using a component-based approach for better organization and reusability.
|
|
91
|
-
|
|
92
|
-
### Component-based architecture
|
|
93
|
-
|
|
94
|
-
The ChatRoom editor uses a modular component structure. Each component has its own folder with an `index.ts` file for clean exports:
|
|
95
|
-
|
|
96
|
-
```
|
|
97
|
-
editors/chat-room-editor/
|
|
98
|
-
├── components/
|
|
99
|
-
│ ├── Avatar/ # User avatar display
|
|
100
|
-
│ │ ├── Avatar.tsx
|
|
101
|
-
│ │ └── index.ts
|
|
102
|
-
│ ├── ChatRoom/ # Main chat container
|
|
103
|
-
│ │ ├── ChatRoom.tsx
|
|
104
|
-
│ │ └── index.ts
|
|
105
|
-
│ ├── Header/ # Chat header with editable title/description
|
|
106
|
-
│ │ ├── EditableLabel.tsx
|
|
107
|
-
│ │ ├── Header.tsx
|
|
108
|
-
│ │ └── index.ts
|
|
109
|
-
│ ├── Message/ # Individual message bubble
|
|
110
|
-
│ │ ├── Message.tsx
|
|
111
|
-
│ │ └── index.ts
|
|
112
|
-
│ ├── MessageItem/ # Message with avatar and reaction dropdown
|
|
113
|
-
│ │ ├── MessageItem.tsx
|
|
114
|
-
│ │ └── index.ts
|
|
115
|
-
│ ├── Reaction/ # Emoji reaction display
|
|
116
|
-
│ │ ├── Reaction.tsx
|
|
117
|
-
│ │ └── index.ts
|
|
118
|
-
│ ├── TextInput/ # Message input field
|
|
119
|
-
│ │ ├── SendIcon.tsx
|
|
120
|
-
│ │ ├── TextInput.tsx
|
|
121
|
-
│ │ └── index.ts
|
|
122
|
-
│ └── index.ts # Central exports
|
|
123
|
-
├── editor.tsx # Main editor component
|
|
124
|
-
├── utils.ts # Utility functions for data mapping
|
|
125
|
-
└── module.ts # Editor module configuration
|
|
11
|
+
```bash
|
|
12
|
+
ph generate --editor ChatRoomEditor --document-types powerhouse/chat-room
|
|
126
13
|
```
|
|
127
14
|
|
|
128
|
-
|
|
15
|
+
Once complete, navigate to the `editors/chat-room/editor.tsx` file and open it in your editor.
|
|
129
16
|
|
|
130
|
-
|
|
17
|
+
As you'll see you will need to add more complex logic to make the chatroom functional and interact with our document model.
|
|
131
18
|
|
|
132
|
-
|
|
133
|
-
2. **The `utils.ts` file** - Contains utility functions for emoji mapping
|
|
19
|
+
## Add the necessary components for your editor first
|
|
134
20
|
|
|
135
|
-
|
|
21
|
+
Download the repository of the chatroom-demo as a zip file https://github.com/powerhouse-inc/chatroom-demo
|
|
22
|
+
and navigate to .../chatroom-demo-main/editors/chat-room-editor to copy both the components folder & utils function. In this repository you will also find all of the other code snippets we've been using in this tutorial.
|
|
136
23
|
|
|
137
|
-
|
|
138
|
-
|-----------|---------|
|
|
139
|
-
| `Avatar` | Displays a user avatar image or a deterministic emoji based on the username |
|
|
140
|
-
| `ChatRoom` | Main container that orchestrates the header, messages list, and input field |
|
|
141
|
-
| `Header` | Shows the chat title and description with inline editing capability |
|
|
142
|
-
| `EditableLabel` | Reusable component for inline text editing with edit/cancel icons |
|
|
143
|
-
| `Message` | Renders a single message bubble with styling based on the sender |
|
|
144
|
-
| `MessageItem` | Wraps `Message` with `Avatar` and adds a reaction dropdown menu |
|
|
145
|
-
| `Reaction` | Displays an emoji reaction with a count of users who reacted |
|
|
146
|
-
| `TextInput` | Input field for composing and sending new messages |
|
|
24
|
+
Drag the folder with react components & utils functions into your VSCode of your chat-room-editor.
|
|
147
25
|
|
|
148
|
-
|
|
26
|
+
In this folder you'll find:
|
|
149
27
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
} from "./components/Message/Message.js";
|
|
157
|
-
import type {
|
|
158
|
-
Message,
|
|
159
|
-
ReactionType,
|
|
160
|
-
} from "../../document-models/chat-room/gen/schema/types.js";
|
|
161
|
-
|
|
162
|
-
const emojis = [
|
|
163
|
-
"😀", "😂", "🤣", "😍", "😎", "😊", "🙃", "😇", "🤔", "🥳",
|
|
164
|
-
"🤯", "🤗", "😱", "👻", "🎃", "🐱", "🐶", "🐹", "🦊", "🐻",
|
|
165
|
-
"🐼", "🐨", "🐯", "🦁", "🐸", "🐵", "🐔", "🐧", "🐦", "🐤",
|
|
166
|
-
"🐝", "🐞", "🐟", "🐬", "🐳", "🦋", "🌺", "🌸", "🌼", "🍀",
|
|
167
|
-
];
|
|
168
|
-
|
|
169
|
-
export function getEmojiFromString(input: string): string {
|
|
170
|
-
function hashString(str: string): number {
|
|
171
|
-
let hash = 0;
|
|
172
|
-
for (let i = 0; i < str.length; i++) {
|
|
173
|
-
const char = str.charCodeAt(i);
|
|
174
|
-
hash = (hash << 5) - hash + char;
|
|
175
|
-
hash |= 0;
|
|
176
|
-
}
|
|
177
|
-
return Math.abs(hash);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
const hash = hashString(input);
|
|
181
|
-
return emojis[hash % emojis.length];
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
export const reactionTypeToEmoji = (reactionType: ReactionType): string => {
|
|
185
|
-
switch (reactionType) {
|
|
186
|
-
case "HEART":
|
|
187
|
-
return "❤️";
|
|
188
|
-
case "THUMBS_UP":
|
|
189
|
-
return "👍";
|
|
190
|
-
case "THUMBS_DOWN":
|
|
191
|
-
return "👎";
|
|
192
|
-
case "LAUGH":
|
|
193
|
-
return "😂";
|
|
194
|
-
case "CRY":
|
|
195
|
-
return "😢";
|
|
196
|
-
default:
|
|
197
|
-
return "❤️";
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
export const reactionTypeToReactionKey = (
|
|
202
|
-
reactionType: ReactionType,
|
|
203
|
-
): keyof ReactionMap => {
|
|
204
|
-
switch (reactionType) {
|
|
205
|
-
case "HEART":
|
|
206
|
-
return "heart";
|
|
207
|
-
case "THUMBS_UP":
|
|
208
|
-
return "thumbsUp";
|
|
209
|
-
case "THUMBS_DOWN":
|
|
210
|
-
return "thumbsDown";
|
|
211
|
-
case "LAUGH":
|
|
212
|
-
return "laughing";
|
|
213
|
-
case "CRY":
|
|
214
|
-
return "cry";
|
|
215
|
-
default:
|
|
216
|
-
return "heart";
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
export const reactionKeyToReactionType = (
|
|
221
|
-
reactionKey: string,
|
|
222
|
-
): ReactionType => {
|
|
223
|
-
switch (reactionKey) {
|
|
224
|
-
case "heart":
|
|
225
|
-
return "HEART";
|
|
226
|
-
case "thumbsUp":
|
|
227
|
-
return "THUMBS_UP";
|
|
228
|
-
case "thumbsDown":
|
|
229
|
-
return "THUMBS_DOWN";
|
|
230
|
-
case "laughing":
|
|
231
|
-
return "LAUGH";
|
|
232
|
-
case "cry":
|
|
233
|
-
return "CRY";
|
|
234
|
-
default:
|
|
235
|
-
return "HEART";
|
|
236
|
-
}
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
export const mapReactions = (
|
|
240
|
-
reactions: Message["reactions"],
|
|
241
|
-
): MessageProps["reactions"] => {
|
|
242
|
-
return (reactions || [])
|
|
243
|
-
.map((reaction) => ({
|
|
244
|
-
emoji: reactionTypeToEmoji(reaction.type),
|
|
245
|
-
reactedBy: reaction.reactedBy,
|
|
246
|
-
type: reactionTypeToReactionKey(reaction.type),
|
|
247
|
-
}))
|
|
248
|
-
.filter((reaction) => reaction.reactedBy.length > 0);
|
|
249
|
-
};
|
|
250
|
-
```
|
|
28
|
+
- An avatar to be set for each chat room participant
|
|
29
|
+
- The chatroom environment itself
|
|
30
|
+
- A header for the chatroom
|
|
31
|
+
- The UI for rendering the message, username and reaction popup.
|
|
32
|
+
- The emoji reaction interface
|
|
33
|
+
- A UI for a text input field
|
|
251
34
|
|
|
252
|
-
|
|
35
|
+
The utils function will help you with mapping information from the document model to your chatroom components. Such as your emoji values to the relevant emoji to be displayed.
|
|
253
36
|
|
|
254
|
-
|
|
37
|
+
Now, let's copy & paste the code below into the `editor.tsx` file located at `editors/chat-room-editor`and save the file.
|
|
255
38
|
|
|
256
39
|
```typescript
|
|
257
40
|
import { generateId } from "document-model/core";
|
|
@@ -400,162 +183,18 @@ export default function Editor() {
|
|
|
400
183
|
}
|
|
401
184
|
```
|
|
402
185
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
- We use `useSelectedChatRoomDocument` hook to get the document state and dispatch function
|
|
406
|
-
- We use `useUser` to get the current user information (for authentication)
|
|
407
|
-
- We map the document's messages to props that our ChatRoom component expects
|
|
408
|
-
- We create handlers for sending messages, adding/removing reactions, and editing metadata
|
|
409
|
-
- We dispatch operations (`addMessage`, `addEmojiReaction`, etc.) from our generated creators
|
|
410
|
-
|
|
411
|
-
:::info Key Concept: useSelectedChatRoomDocument hook
|
|
412
|
-
The `useSelectedChatRoomDocument` hook is generated by the Powerhouse CLI. It provides:
|
|
413
|
-
1. The current document state (`document`)
|
|
414
|
-
2. A dispatch function to send actions to the reducer
|
|
415
|
-
|
|
416
|
-
This hook connects your React components to the document model's state and operations.
|
|
417
|
-
:::
|
|
418
|
-
|
|
419
|
-
## Key components explained
|
|
420
|
-
|
|
421
|
-
### MessageItem component
|
|
422
|
-
|
|
423
|
-
The `MessageItem` component wraps the `Message` component with an avatar and a reaction dropdown menu. It uses the `@powerhousedao/design-system` package for the dropdown:
|
|
424
|
-
|
|
425
|
-
```typescript
|
|
426
|
-
import { Message, type MessageProps } from "../Message/Message.js";
|
|
427
|
-
import { Avatar, type AvatarProps } from "../Avatar/Avatar.js";
|
|
428
|
-
import { useState } from "react";
|
|
429
|
-
import {
|
|
430
|
-
DropdownMenu,
|
|
431
|
-
DropdownMenuContent,
|
|
432
|
-
DropdownMenuTrigger,
|
|
433
|
-
DropdownMenuItem,
|
|
434
|
-
} from "@powerhousedao/design-system";
|
|
435
|
-
|
|
436
|
-
export type MessageItemProps = MessageProps & AvatarProps;
|
|
437
|
-
|
|
438
|
-
export const reactionMap = {
|
|
439
|
-
cry: "😢",
|
|
440
|
-
laughing: "😂",
|
|
441
|
-
heart: "❤️",
|
|
442
|
-
thumbsDown: "👎",
|
|
443
|
-
thumbsUp: "👍",
|
|
444
|
-
};
|
|
445
|
-
|
|
446
|
-
export const MessageItem: React.FC<MessageItemProps> = (props) => {
|
|
447
|
-
const { imgUrl, userName, isCurrentUser, ...messageProps } = props;
|
|
448
|
-
const { disabled = false } = messageProps;
|
|
449
|
-
|
|
450
|
-
const [isHovered, setIsHovered] = useState(false);
|
|
451
|
-
const [open, setOpen] = useState(false);
|
|
452
|
-
|
|
453
|
-
// ... hover and dropdown logic
|
|
454
|
-
|
|
455
|
-
return (
|
|
456
|
-
<div style={{ display: "flex", gap: "2px", alignItems: "flex-end" }}>
|
|
457
|
-
<Avatar imgUrl={imgUrl} userName={userName} />
|
|
458
|
-
<DropdownMenu>
|
|
459
|
-
<Message isCurrentUser={isCurrentUser} userName={userName} {...messageProps} />
|
|
460
|
-
<DropdownMenuTrigger>🫥</DropdownMenuTrigger>
|
|
461
|
-
<DropdownMenuContent>
|
|
462
|
-
{Object.entries(reactionMap).map(([key, emoji]) => (
|
|
463
|
-
<DropdownMenuItem key={key} onClick={() => /* handle reaction */}>
|
|
464
|
-
{emoji}
|
|
465
|
-
</DropdownMenuItem>
|
|
466
|
-
))}
|
|
467
|
-
</DropdownMenuContent>
|
|
468
|
-
</DropdownMenu>
|
|
469
|
-
</div>
|
|
470
|
-
);
|
|
471
|
-
};
|
|
472
|
-
```
|
|
473
|
-
|
|
474
|
-
### EditableLabel component
|
|
475
|
-
|
|
476
|
-
The `EditableLabel` component enables inline editing of text fields (like the chat title and description):
|
|
477
|
-
|
|
478
|
-
```typescript
|
|
479
|
-
export const EditableLabel: React.FC<EditableLabelProps> = ({
|
|
480
|
-
label: initialLabel,
|
|
481
|
-
onSubmit,
|
|
482
|
-
style,
|
|
483
|
-
}) => {
|
|
484
|
-
const [hover, setHover] = useState(false);
|
|
485
|
-
const [isEditing, setIsEditing] = useState(false);
|
|
486
|
-
const [label, setLabel] = useState(initialLabel);
|
|
487
|
-
|
|
488
|
-
// Toggle between read mode (displaying text) and write mode (input field)
|
|
489
|
-
// Press Enter to submit, Escape to cancel
|
|
490
|
-
|
|
491
|
-
return (
|
|
492
|
-
<div onMouseEnter={() => setHover(true)} onMouseLeave={() => setHover(false)}>
|
|
493
|
-
{isEditing ? (
|
|
494
|
-
<input value={label} onChange={(e) => setLabel(e.target.value)} />
|
|
495
|
-
) : (
|
|
496
|
-
<h1>{label}</h1>
|
|
497
|
-
)}
|
|
498
|
-
{(hover || isEditing) && <EditIcon onClick={() => setIsEditing(true)} />}
|
|
499
|
-
</div>
|
|
500
|
-
);
|
|
501
|
-
};
|
|
502
|
-
```
|
|
503
|
-
|
|
504
|
-
## Test your editor
|
|
505
|
-
|
|
506
|
-
Now you can run the Connect app and see the **ChatRoom** editor in action:
|
|
186
|
+
Now you can run the Connect app and see the `Chatroom` editor in action.
|
|
507
187
|
|
|
508
188
|
```bash
|
|
509
189
|
ph connect
|
|
510
190
|
```
|
|
511
191
|
|
|
512
|
-
In
|
|
513
|
-
|
|
514
|
-
:::warning Authentication Required
|
|
515
|
-
A warning will prompt you to login before you can send messages. Login with an Ethereum address via Renown to start sending messages.
|
|
516
|
-
:::
|
|
517
|
-
|
|
518
|
-

|
|
519
|
-
|
|
520
|
-
**Try it out:**
|
|
521
|
-
1. Create a new ChatRoom document
|
|
522
|
-
2. Login with your Ethereum wallet
|
|
523
|
-
3. Send messages using the input field
|
|
524
|
-
4. React to messages with emoji reactions
|
|
525
|
-
5. Click the chat name or description to edit them
|
|
192
|
+
In connect, in the bottom right corner you'll find a new Document Model that you can create: `ChatRoom`. Click on it to create a new Chat Room document. A warning will prompt you to login before you are able to send messages.
|
|
526
193
|
|
|
527
|
-
|
|
528
|
-
If you managed to follow this tutorial until this point, you have successfully implemented the **ChatRoom** document model with its reducer operations and editor.
|
|
194
|
+
Login with an ethereum address via Renown to start sending messages.
|
|
529
195
|
|
|
530
|
-
|
|
196
|
+
Below GIF shows the `Chatroom` editor in action.
|
|
531
197
|
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
```bash
|
|
535
|
-
# See the ChatRoom component implementation
|
|
536
|
-
git show tutorial/main:editors/chat-room-editor/components/ChatRoom/ChatRoom.tsx
|
|
537
|
-
|
|
538
|
-
# Explore the MessageItem component
|
|
539
|
-
git show tutorial/main:editors/chat-room-editor/components/MessageItem/MessageItem.tsx
|
|
540
|
-
|
|
541
|
-
# View the EditableLabel component
|
|
542
|
-
git show tutorial/main:editors/chat-room-editor/components/Header/EditableLabel.tsx
|
|
543
|
-
|
|
544
|
-
# Compare your implementation with the reference
|
|
545
|
-
git diff tutorial/main -- editors/chat-room-editor/
|
|
546
|
-
```
|
|
547
|
-
|
|
548
|
-
## Key concepts learned
|
|
549
|
-
|
|
550
|
-
In this tutorial you've learned:
|
|
551
|
-
|
|
552
|
-
✅ **Component-based architecture** - Breaking down complex UIs into reusable components
|
|
553
|
-
✅ **Document model hooks** - Using `useSelectedChatRoomDocument` to connect React to your document state
|
|
554
|
-
✅ **User authentication** - Using `useUser` hook for wallet-based authentication
|
|
555
|
-
✅ **Action dispatching** - How to dispatch operations from your UI
|
|
556
|
-
✅ **Type-safe development** - Leveraging TypeScript with generated types from your SDL
|
|
557
|
-
✅ **Real-time collaboration** - Building features that work across multiple users
|
|
558
|
-
|
|
559
|
-
## Up next: Local Reactor
|
|
198
|
+

|
|
560
199
|
|
|
561
|
-
|
|
200
|
+
If you managed to follow this tutorial until this point, you have successfully implemented the `ChatRoom` document model with its reducer operations and editor.
|
|
@@ -1,103 +1,15 @@
|
|
|
1
1
|
# Launch a local Reactor
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
📦 **Reference Code**: [chatroom-demo](https://github.com/powerhouse-inc/chatroom-demo)
|
|
3
|
+
Now we'll create a local Reactor instance to simulate the behaviour of the chatroom synchronising messages between two nodes or users in the network.
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
:::
|
|
5
|
+
Wind down connect and run the following command in your terminal.
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
`ph reactor`
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
This spins up a reactor, which represents a node that is usally hosted as a remote server, but in our case we run it locally on our machine. The reactor you've created will become available as a public drive in your left hand side bar.
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
- Hosts and synchronizes documents across multiple clients
|
|
15
|
-
- Manages document state and operations
|
|
16
|
-
- Enables real-time collaboration between users
|
|
11
|
+
If you would now open up two different browser windows you will be able to login into two version of connect, with two different ethereum addresses to start validating the functionality of your chatroom.
|
|
17
12
|
|
|
18
|
-
|
|
13
|
+
Please go ahead now and send a message to yourself, give yourself a thumbs up or try to make your ENS name appear as your profile when logging in. Also remind yourself that you are able to see the revision history of your document and all it's operation history in the top right corner.
|
|
19
14
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
First, stop the Connect application if it's running. Then start the Reactor:
|
|
23
|
-
|
|
24
|
-
```bash
|
|
25
|
-
ph reactor
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
This spins up a Reactor that:
|
|
29
|
-
- Runs locally on your machine
|
|
30
|
-
- Creates a public drive accessible from your Connect sidebar
|
|
31
|
-
- Enables synchronization between multiple browser sessions
|
|
32
|
-
|
|
33
|
-
## Test real-time collaboration
|
|
34
|
-
|
|
35
|
-
To validate the real-time functionality of your ChatRoom:
|
|
36
|
-
|
|
37
|
-
1. **Open two browser windows** with the Connect application
|
|
38
|
-
2. **Navigate to the Reactor drive** in the left sidebar (it will appear as a public drive)
|
|
39
|
-
3. **Login with different Ethereum addresses** in each window
|
|
40
|
-
4. **Create a ChatRoom document** in one window
|
|
41
|
-
5. **Open the same document** in the other window
|
|
42
|
-
|
|
43
|
-
Now you can:
|
|
44
|
-
- Send messages from one window and see them appear in the other
|
|
45
|
-
- React to messages with emojis and watch the reactions sync
|
|
46
|
-
- Edit the chat name or description and see updates propagate
|
|
47
|
-
|
|
48
|
-
:::info Real-time Sync
|
|
49
|
-
The Reactor ensures that all operations are synchronized across connected clients. Each message and reaction is recorded as an operation, maintaining a complete history that can be replayed to reconstruct the document state.
|
|
50
|
-
:::
|
|
51
|
-
|
|
52
|
-
## Additional features to explore
|
|
53
|
-
|
|
54
|
-
While testing your ChatRoom, try these features:
|
|
55
|
-
|
|
56
|
-
1. **Operation History**: Click on the revision history in the top right corner to see all operations performed on the document
|
|
57
|
-
|
|
58
|
-
2. **ENS Integration**: If you login with an Ethereum address that has an ENS name, your name and avatar will appear in your messages
|
|
59
|
-
|
|
60
|
-
3. **Reaction Toggling**: Click on an existing reaction to toggle it on/off for your user
|
|
61
|
-
|
|
62
|
-
## Running Connect alongside Reactor
|
|
63
|
-
|
|
64
|
-
You can also run Connect and Reactor together. In separate terminal windows:
|
|
65
|
-
|
|
66
|
-
```bash
|
|
67
|
-
# Terminal 1: Start the Reactor
|
|
68
|
-
ph reactor
|
|
69
|
-
|
|
70
|
-
# Terminal 2: Start Connect (in a separate terminal)
|
|
71
|
-
ph connect
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
This allows you to:
|
|
75
|
-
- Use Connect's local drive for development
|
|
76
|
-
- Access the Reactor's public drive for collaboration testing
|
|
77
|
-
- Switch between local and synchronized documents
|
|
78
|
-
|
|
79
|
-
## What you've accomplished
|
|
80
|
-
|
|
81
|
-
Congratulations! 🎉 You've now completed the ChatRoom tutorial and learned how to:
|
|
82
|
-
|
|
83
|
-
✅ **Create a Powerhouse project** - Initialize and configure a new project
|
|
84
|
-
✅ **Define a document model** - Design schemas using GraphQL SDL
|
|
85
|
-
✅ **Implement reducers** - Write the business logic for state transitions
|
|
86
|
-
✅ **Build an editor** - Create a React-based UI for your document
|
|
87
|
-
✅ **Test with a Reactor** - Validate real-time collaboration features
|
|
88
|
-
|
|
89
|
-
## Next steps
|
|
90
|
-
|
|
91
|
-
Now that you've completed this tutorial, you can:
|
|
92
|
-
|
|
93
|
-
1. **Explore the Mastery Track** - Dive deeper into [Document Model Creation](/academy/MasteryTrack/DocumentModelCreation/WhatIsADocumentModel) for advanced concepts
|
|
94
|
-
|
|
95
|
-
2. **Try Vetra Studio** - Use AI-assisted development with [Vetra Studio](/academy/GetStarted/VetraStudio) for faster iteration
|
|
96
|
-
|
|
97
|
-
3. **Build your own project** - Apply what you've learned to create your own document models and editors
|
|
98
|
-
|
|
99
|
-
4. **Join the community** - Connect with other Powerhouse builders and share your creations
|
|
100
|
-
|
|
101
|
-
---
|
|
102
|
-
|
|
103
|
-
*This tutorial demonstrated one of the many ways to use document models within the Powerhouse ecosystem. The patterns you've learned here apply to any collaborative application you want to build.*
|
|
15
|
+
Congratulations! You've now explored one of the many ways to use document models within the powerhouse ecosystem.
|
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
"position": 2,
|
|
4
4
|
"link": {
|
|
5
5
|
"type": "generated-index",
|
|
6
|
-
"description": "
|
|
6
|
+
"description": "Get started with the Chatroom tutoria: Jump into creating a new Powerhouse project if you have NodeJs, VSCode, and Git installed. Whe are going to create a new document model that represents a chat. So you as a user can post messages into that chat room, react to the messages. This chatroom will be synchronized between different connect instances. Let's explore the potential of the tools available in the powerhouse toolkit"
|
|
7
7
|
}
|
|
8
8
|
}
|
|
@@ -8,7 +8,7 @@ The **Powerhouse CLI tool** is the only essential tool to install on this page.
|
|
|
8
8
|
You can find all of the commands on this page, similar to what would displayed when using ph --help or ph _command_ --help.
|
|
9
9
|
Use the table of content or the search function to find what you are looking for.
|
|
10
10
|
|
|
11
|
-
The Powerhouse CLI (`ph-cmd`) is a command-line interface tool that provides essential commands for managing Powerhouse
|
|
11
|
+
The Powerhouse CLI (`ph-cmd`) is a command-line interface tool that provides essential commands for managing Powerhouse projects. You can get access to the Powerhouse ecosystem tools by installing them globally.
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
14
|
pnpm install -g ph-cmd
|
|
@@ -16,11 +16,7 @@ pnpm install -g ph-cmd
|
|
|
16
16
|
|
|
17
17
|
:::
|
|
18
18
|
|
|
19
|
-
<!-- AUTO-GENERATED-CLI-COMMANDS-START -->\n<!-- This content is automatically generated. Do not edit directly. -->\n
|
|
20
|
-
|
|
21
|
-
### ph-cmd Commands
|
|
22
|
-
|
|
23
|
-
- [Checkout](#checkout)
|
|
19
|
+
<!-- AUTO-GENERATED-CLI-COMMANDS-START -->\n<!-- This content is automatically generated. Do not edit directly. -->\n### ph-cmd Commands\n\n- [Checkout](#checkout)
|
|
24
20
|
- [Init](#init)
|
|
25
21
|
- [Setup Globals](#setup-globals)
|
|
26
22
|
- [Update](#update)
|