refactor(cleint/textui): cancel showTextUI if text is unchanged

Because people continue to excessively call it in a loop.
This commit is contained in:
Linden
2023-05-19 21:41:58 +10:00
parent 21c835b78d
commit dbfb0227aa

View File

@@ -5,16 +5,23 @@
---@field style? string | table; ---@field style? string | table;
local isOpen = false local isOpen = false
local currentText
---@param text string ---@param text string
---@param options? TextUIOptions ---@param options? TextUIOptions
function lib.showTextUI(text, options) function lib.showTextUI(text, options)
if currentText == text then return end
if not options then options = {} end if not options then options = {} end
options.text = text options.text = text
currentText = text
SendNUIMessage({ SendNUIMessage({
action = 'textUi', action = 'textUi',
data = options data = options
}) })
isOpen = true isOpen = true
end end
@@ -22,7 +29,9 @@ function lib.hideTextUI()
SendNUIMessage({ SendNUIMessage({
action = 'textUiHide' action = 'textUiHide'
}) })
isOpen = false isOpen = false
currentText = nil
end end
---@return boolean ---@return boolean