11package main
22
33import (
4- "context"
54 "encoding/json"
65 "fmt"
76 "io"
@@ -137,7 +136,7 @@ func postConfig(baseURL, jsonContent string) error {
137136}
138137
139138var URLInput = app .DefineComponent ("URLInput" ,
140- func (ctx context. Context , props URLInputProps ) any {
139+ func (props URLInputProps ) any {
141140 keyHandler := & vdom.VDomFunc {
142141 Type : "func" ,
143142 Fn : func (event vdom.VDomEvent ) {
@@ -179,7 +178,7 @@ var URLInput = app.DefineComponent("URLInput",
179178)
180179
181180var JSONEditor = app .DefineComponent ("JSONEditor" ,
182- func (ctx context. Context , props JSONEditorProps ) any {
181+ func (props JSONEditorProps ) any {
183182 if props .Value == "" && props .Placeholder == "" {
184183 return vdom .H ("div" , map [string ]any {
185184 "className" : "text-slate-400 text-center py-8" ,
@@ -216,7 +215,7 @@ var JSONEditor = app.DefineComponent("JSONEditor",
216215)
217216
218217var ErrorDisplay = app .DefineComponent ("ErrorDisplay" ,
219- func (ctx context. Context , props ErrorDisplayProps ) any {
218+ func (props ErrorDisplayProps ) any {
220219 if props .Message == "" {
221220 return nil
222221 }
@@ -235,7 +234,7 @@ var ErrorDisplay = app.DefineComponent("ErrorDisplay",
235234)
236235
237236var SuccessDisplay = app .DefineComponent ("SuccessDisplay" ,
238- func (ctx context. Context , props SuccessDisplayProps ) any {
237+ func (props SuccessDisplayProps ) any {
239238 if props .Message == "" {
240239 return nil
241240 }
@@ -254,75 +253,75 @@ var SuccessDisplay = app.DefineComponent("SuccessDisplay",
254253)
255254
256255var App = app .DefineComponent ("App" ,
257- func (ctx context. Context , _ any ) any {
256+ func (_ struct {} ) any {
258257 app .UseSetAppTitle ("Tsunami Config Manager" )
259258
260259 // Get atom value once at the top
261260 urlInput := serverURLAtom .Get ()
262- jsonContent , setJSONContent , _ := app .UseState ("" )
263- errorMessage , setErrorMessage , _ := app .UseState ("" )
264- successMessage , setSuccessMessage , _ := app .UseState ("" )
265- isLoading , setIsLoading , _ := app .UseState (false )
266- lastFetch , setLastFetch , _ := app .UseState ("" )
267- currentBaseURL , setCurrentBaseURL , _ := app .UseState ("" )
261+ jsonContent := app .UseLocal ("" )
262+ errorMessage := app .UseLocal ("" )
263+ successMessage := app .UseLocal ("" )
264+ isLoading := app .UseLocal (false )
265+ lastFetch := app .UseLocal ("" )
266+ currentBaseURL := app .UseLocal ("" )
268267
269268 clearMessages := func () {
270- setErrorMessage ("" )
271- setSuccessMessage ("" )
269+ errorMessage . Set ("" )
270+ successMessage . Set ("" )
272271 }
273272
274273 fetchConfigData := func () {
275274 clearMessages ()
276275
277- baseURL , err := parseURL (urlInput )
276+ baseURL , err := parseURL (serverURLAtom . Get () )
278277 if err != nil {
279- setErrorMessage (err .Error ())
278+ errorMessage . Set (err .Error ())
280279 return
281280 }
282281
283- setIsLoading (true )
284- setCurrentBaseURL (baseURL )
282+ isLoading . Set (true )
283+ currentBaseURL . Set (baseURL )
285284
286285 go func () {
287286 defer func () {
288- setIsLoading (false )
287+ isLoading . Set (false )
289288 app .SendAsyncInitiation ()
290289 }()
291290
292291 content , err := fetchConfig (baseURL )
293292 if err != nil {
294- setErrorMessage (err .Error ())
293+ errorMessage . Set (err .Error ())
295294 return
296295 }
297296
298- setJSONContent (content )
299- setLastFetch (time .Now ().Format ("2006-01-02 15:04:05" ))
300- setSuccessMessage (fmt .Sprintf ("Successfully fetched config from %s" , baseURL ))
297+ jsonContent . Set (content )
298+ lastFetch . Set (time .Now ().Format ("2006-01-02 15:04:05" ))
299+ successMessage . Set (fmt .Sprintf ("Successfully fetched config from %s" , baseURL ))
301300 }()
302301 }
303302
304303 submitConfigData := func () {
305- if currentBaseURL == "" {
306- setErrorMessage ("No base URL available. Please fetch config first." )
304+ if currentBaseURL . Get () == "" {
305+ errorMessage . Set ("No base URL available. Please fetch config first." )
307306 return
308307 }
309308
310309 clearMessages ()
311- setIsLoading (true )
310+ isLoading . Set (true )
312311
313312 go func () {
314313 defer func () {
315- setIsLoading (false )
314+ isLoading . Set (false )
316315 app .SendAsyncInitiation ()
317316 }()
318317
319- err := postConfig (currentBaseURL , jsonContent )
318+ err := postConfig (currentBaseURL . Get () , jsonContent . Get () )
320319 if err != nil {
321- setErrorMessage (fmt .Sprintf ("Failed to submit config: %v" , err ))
320+ errorMessage . Set (fmt .Sprintf ("Failed to submit config: %v" , err ))
322321 return
323322 }
324323
325- setSuccessMessage (fmt .Sprintf ("Successfully submitted config to %s" , currentBaseURL ))
324+ successMessage . Set (fmt .Sprintf ("Successfully submitted config to %s" , currentBaseURL . Get () ))
326325 }()
327326 }
328327
@@ -344,28 +343,28 @@ var App = app.DefineComponent("App",
344343 Value : urlInput ,
345344 OnChange : serverURLAtom .Set ,
346345 OnSubmit : fetchConfigData ,
347- IsLoading : isLoading ,
346+ IsLoading : isLoading . Get () ,
348347 }),
349348
350349 ErrorDisplay (ErrorDisplayProps {
351- Message : errorMessage ,
350+ Message : errorMessage . Get () ,
352351 }),
353352
354353 SuccessDisplay (SuccessDisplayProps {
355- Message : successMessage ,
354+ Message : successMessage . Get () ,
356355 }),
357356
358- vdom .If (lastFetch != "" ,
357+ vdom .If (lastFetch . Get () != "" ,
359358 vdom .H ("div" , map [string ]any {
360359 "className" : "text-sm text-slate-400 mb-4" ,
361- }, fmt .Sprintf ("Last fetched: %s from %s" , lastFetch , currentBaseURL )),
360+ }, fmt .Sprintf ("Last fetched: %s from %s" , lastFetch . Get () , currentBaseURL . Get () )),
362361 ),
363362
364363 JSONEditor (JSONEditorProps {
365- Value : jsonContent ,
366- OnChange : setJSONContent ,
364+ Value : jsonContent . Get () ,
365+ OnChange : jsonContent . Set ,
367366 OnSubmit : submitConfigData ,
368- IsLoading : isLoading ,
367+ IsLoading : isLoading . Get () ,
369368 Placeholder : "JSON configuration will appear here after fetching..." ,
370369 }),
371370 )
0 commit comments