Bugfix: PluginAction spam causing errors (#541)

* Use session's state instead of existence to determine action

* Retain host/port text

* Use bindings instead of text/ref tunneling

Co-authored-by: Lucien Greathouse <me@lpghatguy.com>
This commit is contained in:
boatbomber
2022-05-22 15:47:11 -07:00
committed by GitHub
parent 83492d7495
commit f1d0f1c1c9
3 changed files with 47 additions and 30 deletions

View File

@@ -14,8 +14,6 @@ local PORT_WIDTH = 74
local DIVIDER_WIDTH = 1
local HOST_OFFSET = 12
local lastHost, lastPort
local e = Roact.createElement
local function AddressEntry(props)
@@ -26,7 +24,7 @@ local function AddressEntry(props)
layoutOrder = props.layoutOrder,
}, {
Host = e("TextBox", {
Text = lastHost or "",
Text = props.host or "",
Font = Enum.Font.Code,
TextSize = 18,
TextColor3 = theme.AddressEntry.TextColor,
@@ -34,6 +32,7 @@ local function AddressEntry(props)
TextTransparency = props.transparency,
PlaceholderText = Config.defaultHost,
PlaceholderColor3 = theme.AddressEntry.PlaceholderColor,
ClearTextOnFocus = false,
Size = UDim2.new(1, -(HOST_OFFSET + DIVIDER_WIDTH + PORT_WIDTH), 1, 0),
Position = UDim2.new(0, HOST_OFFSET, 0, 0),
@@ -41,17 +40,22 @@ local function AddressEntry(props)
ClipsDescendants = true,
BackgroundTransparency = 1,
[Roact.Ref] = props.hostRef,
[Roact.Change.Text] = function(object)
if props.onHostChange ~= nil then
props.onHostChange(object.Text)
end
end
}),
Port = e("TextBox", {
Text = lastPort or "",
Text = props.port or "",
Font = Enum.Font.Code,
TextSize = 18,
TextColor3 = theme.AddressEntry.TextColor,
TextTransparency = props.transparency,
PlaceholderText = Config.defaultPort,
PlaceholderColor3 = theme.AddressEntry.PlaceholderColor,
ClearTextOnFocus = false,
Size = UDim2.new(0, PORT_WIDTH, 1, 0),
Position = UDim2.new(1, 0, 0, 0),
@@ -60,12 +64,14 @@ local function AddressEntry(props)
ClipsDescendants = true,
BackgroundTransparency = 1,
[Roact.Ref] = props.portRef,
[Roact.Change.Text] = function(object)
local text = object.Text
text = text:gsub("%D", "")
object.Text = text
if props.onPortChange ~= nil then
props.onPortChange(text)
end
end,
}, {
Divider = e("Frame", {
@@ -90,8 +96,10 @@ function NotConnectedPage:render()
}),
AddressEntry = e(AddressEntry, {
hostRef = self.props.hostRef,
portRef = self.props.portRef,
host = self.props.host,
port = self.props.port,
onHostChange = self.props.onHostChange,
onPortChange = self.props.onPortChange,
transparency = self.props.transparency,
layoutOrder = 2,
}),
@@ -140,4 +148,4 @@ function NotConnectedPage:render()
})
end
return NotConnectedPage
return NotConnectedPage