-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lua UI improvements #68887
Lua UI improvements #68887
Conversation
padding is surprisingly useful to deal with stupid tgui jank
const jumpButtonCondition = | ||
activeTab === 'log' && | ||
this.sectionRef.current?.scrollableRef.current.scrollHeight > | ||
this.sectionRef.current?.scrollableRef.current.clientHeight; |
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.
you should hook onto onScroll instead and make this a state var, otherwise it'll fail to update if you scroll up
super(props); | ||
this.sectionRef = createRef(); | ||
|
||
window.addEventListener('resize', () => this.setState({})); |
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.
use this.forceUpdate() instead
still gotta do log pagination, DNM until next commit |
drafting because I wanna do some more work on this tomorrow |
eh I decided to make those changes anyways |
const [modal, setModal] = useLocalState( | ||
this.context, | ||
'modal', | ||
noStateYet ? 'states' : null | ||
); | ||
const [activeTab, setActiveTab] = useLocalState( | ||
this.context, | ||
'activeTab', | ||
showGlobalTable ? 'globals' : 'tasks' | ||
); | ||
const [input, setInput] = useLocalState(this.context, 'scriptInput', ''); | ||
const [shouldUpdateScroll, setShouldUpdateScroll] = useLocalState( | ||
this.context, | ||
'shouldUpdateScroll', | ||
false | ||
); |
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.
no reason for local state if you have a class object.
You can just store the state directly on the class
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.
for some of these local state variables, yes, but others are used in more than one function component.
shouldUpdateScroll is also set from DM code using the tgui_shared_states
var.
current_state.get_globals() | ||
data["globals"] = kvpify_list(refify_list(current_state.globals)) | ||
data["states"] = SSlua.states | ||
data["callArguments"] = kvpify_list(refify_list(arguments)) | ||
LAZYSET(tgui_shared_states, "shouldUpdateScroll", "true") |
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.
You can not use this private tgui API. Expose the variable via ui_data instead if you need this much control.
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 was in the process of doing this as you were making this comment, so good to know I shouldn't use it.
if (shouldUpdateScroll) { | ||
setShouldUpdateScroll(false); | ||
shouldUpdateScroll = 0; | ||
setTimeout(this.handleSectionScroll, 0); | ||
} |
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 think the way of dealing with scroll is way too overcomplicated, since you can write this entire effect in componentDidMount()
to run once without dependency on any external dm data or extra re-renders.
componentDidMount() {
setTimeout(this.handleSectionScroll, 0);
}
Also setting it to 0 achieves nothing, because next UI update sends TRUE again. Refactor this once more.
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 didn't quite get the behavior I was looking for putting the code in componentDidMount
, but I did in componentDidUpdate
if (forceModal || forceViewChunk) { | ||
const [newModal, newViewChunk] = [forceModal, forceViewChunk]; | ||
forceModal = null; | ||
forceViewChunk = null; | ||
setModal(newModal); | ||
setViewedChunk(newViewChunk); | ||
} |
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.
Another thing you probably haven't realized is that you can insert a default value into useLocalState
, and that default value can be forceModal
. And this entire chunk of code goes away.
Better yet, since you're using a class-based component, you can use this.state
instead for better performance, and again, implement this effect in componentDidMount
to run only once.
componentDidMount() {
if (props.forceModal) {
this.setState({ showModal: true })
}
}
In general, setting state inside render()
is forbidden because it is inefficient, can cause endless update cycles and there are better ways of doing it. In modern React, this would've been a compilation error.
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.
in the context of this PR, modal
is used both by the class-based root component and several function-based child components. Would you suggest I do something different, such as making all the child components take a function to be called when clicking the "close" button, and give all those child components a function that includes the this.setState
for the root component?
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.
modal is used both by the class-based root component and several function-based child components
I guess this is OK.
Overall readability has improved.
This PR has been inactive for long enough to be automatically marked as stale. This means it is at risk of being auto closed in ~ 7 days, please address any outstanding review items and ensure your PR is finished, if these are all true and you are auto-staled anyway, you need to actively ask maintainers if your PR will be merged. Once you have done any of the previous actions then you should request a maintainer remove the stale label on your PR, to reset the stale timer. If you feel no maintainer will respond in that time, you may wish to close this PR youself, while you seek maintainer comment, as you will then be able to reopen the PR yourself |
* tgui input hotfix tgstation/tgstation#64698 * changes how tgui handles static data tgstation/tgstation#64757 * tgstation/tgstation#64885 * tgstation/tgstation#65008 * cooldown check * read preferences doenst exist here * tgstation/tgstation#65378 * Adds support for embedding react components in tgui chat * tgstation/tgstation#65686 * tgstation/tgstation#65943 * previous part 2 * oops forgot * tgstation/tgstation#66220 * tgstation/tgstation#66299 * FUCk forgot 1 * tgstation/tgstation#59914 * tgstation/tgstation#66304 * tgstation/tgstation#66309 * tgstation/tgstation#66317 * tgstation/tgstation#66691 * tgstation/tgstation#66757 * small changes from 66933 * tgstation/tgstation#67137 * tgui part of tgstation/tgstation#67691 and tgstation/tgstation#66971 * forgot public html * tgstation/tgstation#67935 prewritepackages * after write packages * tgstation/tgstation#67937 * oops * tgstation/tgstation#68216 * tgstation/tgstation#68356 * tgstation/tgstation#68679 * tgstation/tgstation#68887 * prettier ignore outside * tgstation/tgstation#69219 * tgstation/tgstation#69459 * tgstation/tgstation#69527 * tgstation/tgstation#69735 * tgstation/tgstation#69786 * tgstation/tgstation#70779 * boop * Update code/modules/mob/living/silicon/ai/examine.dm * fix ? * io * yo * prettier * prettier + other stuff + tgui say etc * okay ? * webpack tguisay * ntoswindow * tguialert move * tgui say work ? * tgstation/tgstation#71037 * rollback tguisay * comment out tgui say * remove tguisay dm files * updates tgui folder * whytflinter * rerun * fixes stack trace on fullupdate * woops, removes \n from join() * balloon alert * timeleft shenanigan solve stack_trace * check if fix linter * add it back * woo linter
About The Pull Request
Atomized from #68816, with a little addition. Fixes some dumb formatting issues with the lua editor, adds a "jump to bottom" button when viewing the state log, and paginates the state logs.
Why It's Good For The Game
UI fixes and qol are good.
Changelog
馃啈
fix: Fixes the formatting of the admin lua editor
qol: In the admin lua editor, there will be a "jump to bottom" button in the log viewer if the log is longer than can be shown in the window.
qol: The lua editor log viewer is now split into pages of at most 50 log entries.
/:cl: