Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add checkbox with live reload when opening sketches of other users #352

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions client/src/Note.re
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ let make = (~noteInfo: Route.noteRouteConfig) => {
let noteQuery = GetNoteById.make(~noteId, ());

<GetNoteByIdComponent variables=noteQuery##variables>
...{({result}) =>
...{({refetch, result}) => {
switch (result) {
| Loading => <Editor_NotePlaceholder />
| Error(error) => error.message->str
Expand Down Expand Up @@ -69,6 +69,7 @@ let make = (~noteInfo: Route.noteRouteConfig) => {
blocks
forkFrom=?{note##fork_from}
hasSavePermission
refetch
/>
</RedirectSketchURL>;
}}
Expand All @@ -77,6 +78,6 @@ let make = (~noteInfo: Route.noteRouteConfig) => {
)
);
}
}
}}
</GetNoteByIdComponent>;
};
42 changes: 41 additions & 1 deletion client/src_editor/Editor_Note.re
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ module Editor_Note = {
~initialNoteOwnerId: id,
~initialNoteLastEdited: option(Js.Json.t),
~registerShortcut: Shortcut.subscribeFun,
~refetch=?,
) => {
let ({editorContentStatus, lang} as state, dispatch) =
React.useReducer(
Expand Down Expand Up @@ -191,6 +192,32 @@ module Editor_Note = {
[|state.noteId|],
);

React.useEffect1(
() => {
switch (refetch) {
| None => None
| Some(refetch) =>
let intervalId =
Js.Global.setInterval(
() => {
refetch(None)
->Js.Promise.then_(
value => {
Js.log(value);
Js.Promise.resolve();
},
_,
)
->ignore
},
5000,
);
Some(() => Js.Global.clearInterval(intervalId));
}
},
[|refetch|],
);

<>
<UI_Topbar.Actions>
{(~buttonClassName) =>
Expand Down Expand Up @@ -289,6 +316,17 @@ module Editor_Note = {
</span>
</fieldset>
</UI_Balloon>
<div>
{React.string("foo")}
<input
name="isGoing"
type_="checkbox"
checked=true
onChange={event => {
Webapi.Dom.(event->ReactEvent.Form.preventDefault)
}}
/>
</div>
</>}
</UI_Topbar.Actions>
<Helmet>
Expand All @@ -311,7 +349,7 @@ module Editor_Note = {
<Editor_Note_GetUserInfo userId={state.noteOwnerId}>
{fun
| None => React.null
| Some((user: Js.t('a))) =>
| Some(user: Js.t('a)) =>
<UI_SketchOwnerInfo
owner=user
noteLastEdited=?{state.noteLastEdited}
Expand Down Expand Up @@ -398,6 +436,7 @@ module WithShortcut = {
~noteOwnerId,
~noteLastEdited,
~forkFrom=?,
~refetch=?,
) =>
ReactCompat.useRecordApi({
...ReactCompat.component,
Expand All @@ -417,6 +456,7 @@ module WithShortcut = {
initialNoteLastEdited=noteLastEdited
initialForkFrom=?forkFrom
registerShortcut
?refetch
/>}
</Shortcut.Consumer>,
});
Expand Down