-
Notifications
You must be signed in to change notification settings - Fork 17
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
feature: view pages #71
base: master
Are you sure you want to change the base?
Conversation
…er file view (e.g., they can be dragged into the sidebar)
…iguration page's select element
This reverts commit bebb430.
…n the `src/pages` directory
aec0149
to
e5f2b58
Compare
… UX when editing scripts
2b2d212
to
43d4de5
Compare
…y nothing by default
@@ -56,5 +60,6 @@ | |||
"sorted-btree": "^1.8.1", | |||
"sucrase": "3.35.0", | |||
"yaml": "^2.3.3" | |||
} | |||
}, | |||
"packageManager": "[email protected]+sha1.4ba7fc5c6e704fce2066ecbfb0b0d8976fe62447" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GamerGirlandCo - did you mean to leave this here? It's a VERY specific version of yarn so I just wanted to be sure. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, this is to ensure other package managers can't accidentally be used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense.
if (editorRef.current && !viewRef.current) { | ||
viewRef.current = new EditorView({ | ||
parent: editorRef.current, | ||
extensions: [viewContext.app.vault.getConfig("vimMode") && vim()].concat( | ||
...EDITOR_EXTS.concat( | ||
...[ | ||
LANG_COMPARTMENT.of(javascript()), | ||
ViewPlugin.fromClass( | ||
class { | ||
constructor(public view: EditorView) {} | ||
update(update: ViewUpdate) { | ||
if (update.docChanged) { | ||
setState({ script: this.view.state.sliceDoc() || "" }); | ||
} | ||
} | ||
} | ||
), | ||
EDITOR_HL, | ||
viewContext.app.vault.getConfig("vimMode") && vim(), | ||
...(viewContext.app.plugins.plugins["datacore-addon-autocomplete"]?.extensions || []), | ||
].filter((a) => !!a) | ||
) | ||
), | ||
doc: script || "", | ||
}); | ||
} | ||
return () => viewRef.current?.destroy(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a big fan of short circuiting patterns when possible. :) I've not verified it, but something like below makes a lot of sense to my brain and helps prevent getting if statments too nested as the code grows.
if (editorRef.current && !viewRef.current) { | |
viewRef.current = new EditorView({ | |
parent: editorRef.current, | |
extensions: [viewContext.app.vault.getConfig("vimMode") && vim()].concat( | |
...EDITOR_EXTS.concat( | |
...[ | |
LANG_COMPARTMENT.of(javascript()), | |
ViewPlugin.fromClass( | |
class { | |
constructor(public view: EditorView) {} | |
update(update: ViewUpdate) { | |
if (update.docChanged) { | |
setState({ script: this.view.state.sliceDoc() || "" }); | |
} | |
} | |
} | |
), | |
EDITOR_HL, | |
viewContext.app.vault.getConfig("vimMode") && vim(), | |
...(viewContext.app.plugins.plugins["datacore-addon-autocomplete"]?.extensions || []), | |
].filter((a) => !!a) | |
) | |
), | |
doc: script || "", | |
}); | |
} | |
return () => viewRef.current?.destroy(); | |
if (!editorRef.current || viewRef.current) { | |
return () => viewRef.current?.destroy(); | |
} | |
viewRef.current = new EditorView({ | |
parent: editorRef.current, | |
extensions: [viewContext.app.vault.getConfig("vimMode") && vim()].concat( | |
...EDITOR_EXTS.concat( | |
...[ | |
LANG_COMPARTMENT.of(javascript()), | |
ViewPlugin.fromClass( | |
class { | |
constructor(public view: EditorView) {} | |
update(update: ViewUpdate) { | |
if (update.docChanged) { | |
setState({ script: this.view.state.sliceDoc() || "" }); | |
} | |
} | |
} | |
), | |
EDITOR_HL, | |
viewContext.app.vault.getConfig("vimMode") && vim(), | |
...(viewContext.app.plugins.plugins["datacore-addon-autocomplete"]?.extensions || []), | |
].filter((a) => !!a) | |
) | |
), | |
doc: script || "", | |
}); | |
return () => viewRef.current?.destroy(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are you returning the useEffect cleanup early?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could be missing a nuance for how useEffect clean up functions work, but my main goal here was to early exit
or short circuit
the if statement. Since the current function always returned the clean up code, I wanted my modified suggestion also to return it. This article does a pretty good job describing it: https://medium.com/swlh/return-early-pattern-3d18a41bba8
Arguably since there is only one if
statement, it might not be truly necessary yet, but I like to start the pattern early so that you don't end up with a bunch of nested if
statements as the code base invariably grows. But some people might argue that's over engineering
. Just thought I'd bring it up for discussion. 🙂
Please of course feel free to reject the suggestion if it seems like overkill to you or my thinking is flawed. 🙂
{ label: "Javascript", value: "js" }, | ||
{ label: "Typescript", value: "ts" }, | ||
{ label: "Javascript (JSX)", value: "jsx" }, | ||
{ label: "Typescript JSX", value: "tsx" }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ label: "Typescript JSX", value: "tsx" }, | |
{ label: "Typescript TSX", value: "tsx" }, |
to quote the roadmap:
each view page has its own state consisting of the following properties:
sourceType
: the type of script this view will contain (ex:ts
,js
,jsx
,tsx
...)script
: the actual source code for the scripttitle
: the title, as displayed in the tab/view headercurrentFile
: the configurable path to the current file, so that functions and hooks such asuseCurrentPath
don't chokeall of these are configurable via the view's settings page, which can be accessed via going into the three-dot menu and clicking "View configuration".
a command to create a view page has also been added to the command palette for ease of use.
as always, let me know if i should add or change anything! :)