File tree Expand file tree Collapse file tree 1 file changed +18
-4
lines changed
_project/frontend-nuxt/pages/blog Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change 11<script setup lang="ts">
2- import { BlogRsc } from " @effect-app-boilerplate/resources"
2+ import { BlogRsc , GraphRsc } from " @effect-app-boilerplate/resources"
33
44const blogClient = clientFor (BlogRsc )
5+ const graphClient = clientFor (GraphRsc )
56
6- const [, createPost_] = useMutation (blogClient .createPost )
7- const [, latestPosts, reloadPosts] = useSafeQuery (blogClient .getPosts )
7+ const [, mutate] = useMutation (graphClient .mutation )
8+ const [, latestPosts, reloadPosts, { mutate : mutatePosts }] = useSafeQuery (
9+ blogClient .getPosts
10+ )
811
9- const createPost = flow (createPost_ , _ => _ .then (_ => reloadPosts ()))
12+ const createPost = (input : BlogRsc .CreatePost .CreatePostRequest ) =>
13+ pipe (mutate ({ CreatePost: { input , query: { result: true } } }), _ =>
14+ _ .then (_ => {
15+ const r = _ [" |>" ](Either .flatMap (_ => _ .body .CreatePost ! ))[" |>" ](
16+ Either .map (_ => _ .query ! .result ! )
17+ )
18+ if (r ._tag === " Right" ) {
19+ const items = latestPosts .value ! .items
20+ mutatePosts (() => Promise .resolve ({ items: [... items , r .right ] }))
21+ }
22+ })
23+ )
1024 </script >
1125
1226<template >
You can’t perform that action at this time.
0 commit comments