From fd0ebc3f42b1d9ba31b797c36b10e96aeca21ad1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Ch=C3=A1varri?= Date: Fri, 7 Oct 2022 16:33:21 +0200 Subject: [PATCH 1/3] use refetch --- client/src/Note.re | 9 +++++-- client/src_editor/Editor_Note.re | 42 +++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/client/src/Note.re b/client/src/Note.re index 0c3d5bf6..d471ac84 100644 --- a/client/src/Note.re +++ b/client/src/Note.re @@ -24,7 +24,11 @@ let make = (~noteInfo: Route.noteRouteConfig) => { let noteQuery = GetNoteById.make(~noteId, ()); - ...{({result}) => + ...{({refetch, result}) => { + let refetch: option(unit => Js.Promise.t('g)), "title": option(string) = Some( + () => + refetch(Some(noteQuery##variables)), + ); switch (result) { | Loading => | Error(error) => error.message->str @@ -69,6 +73,7 @@ let make = (~noteInfo: Route.noteRouteConfig) => { blocks forkFrom=?{note##fork_from} hasSavePermission + refetch=refetch /> ; }} @@ -76,7 +81,7 @@ let make = (~noteInfo: Route.noteRouteConfig) => { }, ) ); - } + }} } ; }; diff --git a/client/src_editor/Editor_Note.re b/client/src_editor/Editor_Note.re index 33cd2208..3624cf87 100644 --- a/client/src_editor/Editor_Note.re +++ b/client/src_editor/Editor_Note.re @@ -118,6 +118,7 @@ module Editor_Note = { ~initialNoteOwnerId: id, ~initialNoteLastEdited: option(Js.Json.t), ~registerShortcut: Shortcut.subscribeFun, + ~refetch=None, ) => { let ({editorContentStatus, lang} as state, dispatch) = React.useReducer( @@ -191,6 +192,32 @@ module Editor_Note = { [|state.noteId|], ); + React.useEffect1( + () => { + switch (refetch) { + | None => None + | Some(refetch) => + let intervalId = + Js.Global.setInterval( + () => { + refetch() + ->Js.Promise.then_( + value => { + Js.log(value); + Js.Promise.resolve(); + }, + _, + ) + ->ignore + }, + 5000, + ); + Some(() => Js.Global.clearInterval(intervalId)); + } + }, + [|refetch|], + ); + <> {(~buttonClassName) => @@ -289,6 +316,17 @@ module Editor_Note = { +
+ {React.string("foo")} + { + Webapi.Dom.(event->ReactEvent.Form.preventDefault) + }} + /> +
}
@@ -311,7 +349,7 @@ module Editor_Note = { {fun | None => React.null - | Some((user: Js.t('a))) => + | Some(user: Js.t('a)) => ReactCompat.useRecordApi({ ...ReactCompat.component, @@ -417,6 +456,7 @@ module WithShortcut = { initialNoteLastEdited=noteLastEdited initialForkFrom=?forkFrom registerShortcut + refetch />} , }); From dd7a360643204b0ba3241937e74025d8c0fc43f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Ch=C3=A1varri?= Date: Fri, 7 Oct 2022 16:42:08 +0200 Subject: [PATCH 2/3] pass refetch directly --- client/src/Note.re | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/client/src/Note.re b/client/src/Note.re index d471ac84..aed003f9 100644 --- a/client/src/Note.re +++ b/client/src/Note.re @@ -25,10 +25,6 @@ let make = (~noteInfo: Route.noteRouteConfig) => { ...{({refetch, result}) => { - let refetch: option(unit => Js.Promise.t('g)), "title": option(string) = Some( - () => - refetch(Some(noteQuery##variables)), - ); switch (result) { | Loading => | Error(error) => error.message->str @@ -73,7 +69,7 @@ let make = (~noteInfo: Route.noteRouteConfig) => { blocks forkFrom=?{note##fork_from} hasSavePermission - refetch=refetch + refetch /> ; }} @@ -81,7 +77,7 @@ let make = (~noteInfo: Route.noteRouteConfig) => { }, ) ); - }} - } + } + }} ; }; From 73a04451703a8a8b4f8bc54bd0dff4cc77101265 Mon Sep 17 00:00:00 2001 From: Rusty Key Date: Fri, 7 Oct 2022 18:54:20 +0400 Subject: [PATCH 3/3] fix refetch type --- client/src_editor/Editor_Note.re | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/client/src_editor/Editor_Note.re b/client/src_editor/Editor_Note.re index 3624cf87..1539f068 100644 --- a/client/src_editor/Editor_Note.re +++ b/client/src_editor/Editor_Note.re @@ -118,7 +118,7 @@ module Editor_Note = { ~initialNoteOwnerId: id, ~initialNoteLastEdited: option(Js.Json.t), ~registerShortcut: Shortcut.subscribeFun, - ~refetch=None, + ~refetch=?, ) => { let ({editorContentStatus, lang} as state, dispatch) = React.useReducer( @@ -200,7 +200,7 @@ module Editor_Note = { let intervalId = Js.Global.setInterval( () => { - refetch() + refetch(None) ->Js.Promise.then_( value => { Js.log(value); @@ -436,7 +436,7 @@ module WithShortcut = { ~noteOwnerId, ~noteLastEdited, ~forkFrom=?, - ~refetch, + ~refetch=?, ) => ReactCompat.useRecordApi({ ...ReactCompat.component, @@ -456,7 +456,7 @@ module WithShortcut = { initialNoteLastEdited=noteLastEdited initialForkFrom=?forkFrom registerShortcut - refetch + ?refetch />} , });