@@ -2,7 +2,11 @@ import { Toolbar } from "../../components/ui/Toolbar";
22import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator" ;
33import { useAtomRefresh } from "@effect/atom-react" ;
44import { useNavigation , type StaticScreenProps } from "@react-navigation/native" ;
5- import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime" ;
5+ import {
6+ type AtomCommandResult ,
7+ squashAtomCommandFailure ,
8+ } from "@t3tools/client-runtime/state/runtime" ;
9+ import { AsyncResult } from "effect/reactivity" ;
610import type { PullRequestThreadComment } from "@t3tools/contracts" ;
711import { useRef , useState } from "react" ;
812import { Platform , ScrollView , View } from "react-native" ;
@@ -59,59 +63,58 @@ function Discussion({ params }: { params: PullRequestParams & { readonly discuss
5963 const [ error , setError ] = useState < string | null > ( null ) ;
6064 const [ notice , setNotice ] = useState < string | null > ( null ) ;
6165 const [ composerHeight , setComposerHeight ] = useState ( 64 ) ;
62- const operation = async ( run : ( ) => Promise < void > ) => {
66+ const operation = async ( run : ( ) => Promise < AtomCommandResult < unknown , unknown > | undefined > ) => {
6367 if ( pending . current ) return ;
6468 pending . current = true ;
6569 setBusy ( true ) ;
6670 setError ( null ) ;
6771 setNotice ( null ) ;
68- await ( async ( ) => {
69- await run ( ) ;
70- } ) ( )
71- . catch ( ( cause : unknown ) => {
72- setError (
73- cause instanceof Error ? cause . message : "The provider could not complete this action." ,
74- ) ;
75- } )
76- . finally ( ( ) => {
77- pending . current = false ;
78- setBusy ( false ) ;
79- } ) ;
72+ const result = await run ( ) ;
73+ pending . current = false ;
74+ setBusy ( false ) ;
75+ if ( result && AsyncResult . isFailure ( result ) ) {
76+ const cause = squashAtomCommandFailure ( result ) ;
77+ setError (
78+ cause instanceof Error ? cause . message : "The provider could not complete this action." ,
79+ ) ;
80+ }
8081 } ;
8182 const post = ( ) =>
8283 operation ( async ( ) => {
83- if ( ! permissions . canReply || ! body . trim ( ) || ! thread ) return ;
84+ if ( ! permissions . canReply || ! body . trim ( ) || ! thread ) return undefined ;
8485 const submitted = body ;
8586 const response = await reply ( {
8687 ...target ,
8788 input : { ...target . input , threadId : thread . id , body : submitted } ,
8889 } ) ;
89- if ( response . _tag === "Failure" ) throw squashAtomCommandFailure ( response ) ;
90+ if ( AsyncResult . isFailure ( response ) ) return response ;
9091 setBody ( ( current ) => ( current === submitted ? "" : current ) ) ;
9192 setNotice ( "Reply posted." ) ;
9293 refresh ( ) ;
94+ return response ;
9395 } ) ;
9496 const toggleResolved = ( ) =>
9597 operation ( async ( ) => {
96- if ( ! thread || ! permissions . canResolve ) return ;
98+ if ( ! thread || ! permissions . canResolve ) return undefined ;
9799 const response = await resolve ( {
98100 ...target ,
99101 input : { ...target . input , threadId : thread . id , resolved : ! thread . isResolved } ,
100102 } ) ;
101- if ( response . _tag === "Failure" ) throw squashAtomCommandFailure ( response ) ;
102- refresh ( ) ;
103+ if ( AsyncResult . isSuccess ( response ) ) refresh ( ) ;
104+ return response ;
103105 } ) ;
104106 const nextCursor = cursor === undefined ? thread ?. nextCommentsCursor : cursor ;
105107 const more = ( ) =>
106108 operation ( async ( ) => {
107- if ( ! thread || ! nextCursor ) return ;
109+ if ( ! thread || ! nextCursor ) return undefined ;
108110 const response = await loadMore ( {
109111 ...target ,
110112 input : { ...target . input , threadId : thread . id , cursor : nextCursor } ,
111113 } ) ;
112- if ( response . _tag === "Failure" ) throw squashAtomCommandFailure ( response ) ;
114+ if ( AsyncResult . isFailure ( response ) ) return response ;
113115 setExtra ( ( comments ) => [ ...comments , ...response . value . comments ] ) ;
114116 setCursor ( response . value . nextCursor ) ;
117+ return response ;
115118 } ) ;
116119 const comments = [
117120 ...new Map (
0 commit comments