-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf52b25
commit 5631a96
Showing
7 changed files
with
55 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,37 @@ | ||
import { App } from "elp/app" | ||
import { App, Window } from "elp/app" | ||
import { Form, Label, Input, Button } from "elp/app/elements" | ||
import { Message, User } from "$types/chat" | ||
import { Message as MessageView } from "$components/message" | ||
|
||
export fn Chat: App { | ||
export object ChatAppState implements Contextual { | ||
.name: *string | ||
.messages: []Message | ||
.members: []User | ||
.messages: [Message] | ||
.members: [User] | ||
.loggedIn: bool = false | ||
} | ||
|
||
if name not Empty { | ||
ForEach(messages) { message in | ||
MessageView(user = message.user, body = message.body) | ||
// The Contextual type here actually transforms Chat into a context provider which | ||
// along with the implements on ChatAppState gives all child components writeable | ||
// state if it is passed down and the property is not marked as const. | ||
// So when we pass message down by reference we can actually do .message.reactions.push(newReaction) | ||
// and it will cause reactivity all the way up the view chain where that property is read. | ||
export fn Chat(name: *string) implements App, Contextual<ChatAppState> -> Window { | ||
Window { | ||
if .name not Empty or not .loggedIn { | ||
ForEach(.messages) { message in | ||
// We borrow the message to pass down which extends it's lifetime | ||
// and allows for mutation and avoids copying. | ||
MessageView( message = &message) | ||
} | ||
} else { | ||
Form(preventDefault, onSubmit={fn { .loggedIn = true }}) { | ||
Label("Enter your display name") { | ||
Input(name="display-name", type="text", value={.name}) | ||
Button { | ||
Text("Log in") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import { App, Router } from "ellipsis" | ||
import { App, Window } from "ellipsis" | ||
import { Home } from "$screens/home" | ||
import Styles from "$app/styles" | ||
|
||
export fn HelloWorld: App(globalStyles = Styles()) { | ||
Home() | ||
export fn HelloWorld implements App(globalStyles = Styles()) -> Window { | ||
Window { | ||
Home() | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters