@@ -222,67 +222,40 @@ var WorkflowRunItem = app.DefineComponent("WorkflowRunItem",
222222var App = app .DefineComponent ("App" ,
223223 func (_ struct {}) any {
224224 app .UseSetAppTitle ("GitHub Actions Monitor" )
225- _ , _ , setTickerFn := app .UseState (0 )
226225
227- app .UseEffect (func () func () {
228- ticker := time .NewTicker (time .Duration (pollIntervalAtom .Get ()) * time .Second )
229- done := make (chan bool )
230-
231- fetchData := func () {
232- currentMaxRuns := maxWorkflowRunsAtom .Get ()
233- runs , err := fetchWorkflowRuns (repositoryAtom .Get (), workflowAtom .Get (), currentMaxRuns )
234- if err != nil {
235- log .Printf ("Error fetching workflow runs: %v" , err )
236- lastErrorAtom .Set (err .Error ())
237- } else {
238- sort .Slice (runs , func (i , j int ) bool {
239- return runs [i ].CreatedAt .After (runs [j ].CreatedAt )
240- })
241- workflowRunsAtom .Set (runs )
242- lastErrorAtom .Set ("" )
243- }
244- lastRefreshTimeAtom .Set (time .Now ())
245- isLoadingAtom .Set (false )
226+ fetchData := func () {
227+ currentMaxRuns := maxWorkflowRunsAtom .Get ()
228+ runs , err := fetchWorkflowRuns (repositoryAtom .Get (), workflowAtom .Get (), currentMaxRuns )
229+ if err != nil {
230+ log .Printf ("Error fetching workflow runs: %v" , err )
231+ lastErrorAtom .Set (err .Error ())
232+ } else {
233+ sort .Slice (runs , func (i , j int ) bool {
234+ return runs [i ].CreatedAt .After (runs [j ].CreatedAt )
235+ })
236+ workflowRunsAtom .Set (runs )
237+ lastErrorAtom .Set ("" )
246238 }
239+ lastRefreshTimeAtom .Set (time .Now ())
240+ isLoadingAtom .Set (false )
241+ }
247242
243+ // Initial fetch on mount
244+ app .UseEffect (func () func () {
248245 fetchData ()
246+ return nil
247+ }, []any {})
249248
250- go func () {
251- for {
252- select {
253- case <- done :
254- return
255- case <- ticker .C :
256- fetchData ()
257- setTickerFn (func (t int ) int { return t + 1 })
258- app .SendAsyncInitiation ()
259- }
260- }
261- }()
262-
263- return func () {
264- ticker .Stop ()
265- close (done )
266- }
249+ // Automatic polling with UseTicker - automatically cleaned up on unmount
250+ app .UseTicker (time .Duration (pollIntervalAtom .Get ())* time .Second , func () {
251+ fetchData ()
252+ app .SendAsyncInitiation ()
267253 }, []any {pollIntervalAtom .Get ()})
268254
269255 handleRefresh := func () {
270256 isLoadingAtom .Set (true )
271257 go func () {
272- currentMaxRuns := maxWorkflowRunsAtom .Get ()
273- runs , err := fetchWorkflowRuns (repositoryAtom .Get (), workflowAtom .Get (), currentMaxRuns )
274- if err != nil {
275- log .Printf ("Error fetching workflow runs: %v" , err )
276- lastErrorAtom .Set (err .Error ())
277- } else {
278- sort .Slice (runs , func (i , j int ) bool {
279- return runs [i ].CreatedAt .After (runs [j ].CreatedAt )
280- })
281- workflowRunsAtom .Set (runs )
282- lastErrorAtom .Set ("" )
283- }
284- lastRefreshTimeAtom .Set (time .Now ())
285- isLoadingAtom .Set (false )
258+ fetchData ()
286259 app .SendAsyncInitiation ()
287260 }()
288261 }
0 commit comments