Posts
Some checks failed
Lint / lint (push) Failing after 9s

This commit is contained in:
Julien Valverdé
2025-01-14 22:11:13 +01:00
parent 4f091ae221
commit 18d94c77e2
11 changed files with 104 additions and 24 deletions

View File

@@ -1,7 +1,34 @@
import { Post } from "@/domain"
import { Chunk, Effect, Ref } from "effect"
import { PostsState } from "../posts/services"
import { Reffuse } from "./reffuse"
export function VPost() {
export interface VPostProps {
readonly index: number
readonly post: Post.Post
}
export function VPost({ post, index }: VPostProps) {
const runSync = Reffuse.useRunSync()
return (
<div className="flex-col gap-1 items-stretch">
<p>{post.title}</p>
<p>{post.content}</p>
<button
onClick={() => PostsState.PostsState.pipe(
Effect.flatMap(({ posts }) => Ref.update(posts, Chunk.remove(index))),
runSync,
)}
>
X
</button>
</div>
)
}

View File

@@ -1,5 +1 @@
import { Reffuse as RootReffuse } from "@/reffuse"
import { PostState } from "@/services"
export const Reffuse = RootReffuse.extend<PostState.PostState>()
export { Reffuse } from "../posts/reffuse"

View File

@@ -0,0 +1,25 @@
import { Chunk } from "effect"
import { VPost } from "../post/VPost"
import { Reffuse } from "./reffuse"
import { PostsState } from "./services"
export function VPosts() {
const state = Reffuse.useMemo(PostsState.PostsState)
const [posts] = Reffuse.useRefState(state.posts)
return (
<div className="flex-col gap-2 items-stretch">
{Chunk.map(posts, (post, index) => (
<VPost
key={`${ index }-${ post.id }`}
index={index}
post={post}
/>
))}
</div>
)
}

View File

@@ -0,0 +1,5 @@
import { Reffuse as RootReffuse } from "@/reffuse"
import { PostsState } from "./services"
export const Reffuse = RootReffuse.extend<PostsState.PostsState>()

View File

@@ -0,0 +1,7 @@
import { Post } from "@/domain"
import { Chunk, Context, SubscriptionRef } from "effect"
export class PostsState extends Context.Tag("PostsState")<PostsState, {
readonly posts: SubscriptionRef.SubscriptionRef<Chunk.Chunk<Post.Post>>
}>() {}

View File

@@ -0,0 +1 @@
export * as PostsState from "./PostsState"