Sync proclamations when entering proclamation list

This commit is contained in:
NeilClack
2026-04-23 17:29:20 -05:00
parent 32648377ce
commit b6bf0f1873
3 changed files with 14 additions and 8 deletions
+2 -2
View File
@@ -154,8 +154,8 @@ func Run() {
}) })
// Sync the proclamations from the API to the Database // Sync the proclamations from the API to the Database
sync.SyncProclamations(apiURL, DB) sync.SyncProclamations(DB)
sync.SyncCategories(apiURL, DB) sync.SyncCategories(DB)
app.runEventLoop() app.runEventLoop()
} }
+4 -1
View File
@@ -15,6 +15,7 @@ import (
"rhemawavetech.com/rhemawave/internal/fontManager" "rhemawavetech.com/rhemawave/internal/fontManager"
"rhemawavetech.com/rhemawave/internal/logger" "rhemawavetech.com/rhemawave/internal/logger"
"rhemawavetech.com/rhemawave/internal/shaderManager" "rhemawavetech.com/rhemawave/internal/shaderManager"
"rhemawavetech.com/rhemawave/internal/sync"
) )
// Scrollbar Visuals // Scrollbar Visuals
@@ -78,10 +79,12 @@ func (p *ProclamationOptions) Init(ctx *PageCtx) error {
p.allItems = []*FlatItem{} p.allItems = []*FlatItem{}
p.scrollOffset = 0 p.scrollOffset = 0
p.isSearchActive = false p.isSearchActive = false
p.scrollTrackWidth = 30 p.scrollTrackWidth = 30
p.scrollTrackX = p.ScreenWidth - p.scrollTrackWidth p.scrollTrackX = p.ScreenWidth - p.scrollTrackWidth
// Syncronize proclamations first
sync.SyncProclamations(ctx.DbPtr)
fm := fontManager.Get() fm := fontManager.Get()
font, _ := fm.GetFont("Roboto-Regular") font, _ := fm.GetFont("Roboto-Regular")
p.font = font p.font = font
+8 -5
View File
@@ -1,7 +1,6 @@
package sync package sync
import ( import (
"fmt"
"regexp" "regexp"
"gorm.io/gorm" "gorm.io/gorm"
@@ -14,8 +13,9 @@ var htmlRegex = regexp.MustCompile(`<[^>]*>`)
// SyncProclamations fetches data from the API, cleans it, and updates the local DB. // SyncProclamations fetches data from the API, cleans it, and updates the local DB.
// It returns the slice of proclamations so the UI can update immediately. // It returns the slice of proclamations so the UI can update immediately.
func SyncProclamations(apiURL string, database *gorm.DB) ([]db.Proclamation, error) { func SyncProclamations(database *gorm.DB) ([]db.Proclamation, error) {
fullURL := fmt.Sprintf("%s/proclamations", apiURL) fullURL := "https://portal.rhemawavetech.com/api/v1/proclamations"
logger.Debug("Syncronizing proclamations. URL: %s", fullURL)
// 1. Fetch from API // 1. Fetch from API
proclamations, err := netreq.GetJSON[db.Proclamation](fullURL) proclamations, err := netreq.GetJSON[db.Proclamation](fullURL)
@@ -25,6 +25,7 @@ func SyncProclamations(apiURL string, database *gorm.DB) ([]db.Proclamation, err
logger.Error("Proclamation sync failed, skipping update: %v", err) logger.Error("Proclamation sync failed, skipping update: %v", err)
return nil, err return nil, err
} }
logger.Debug("Request Granted")
// 2. Data Transformation (Cleaning) // 2. Data Transformation (Cleaning)
for i := range proclamations { for i := range proclamations {
@@ -40,6 +41,8 @@ func SyncProclamations(apiURL string, database *gorm.DB) ([]db.Proclamation, err
return nil return nil
}) })
logger.Debug("Proclamations stored to database")
if err != nil { if err != nil {
logger.Error("Failed to save synced proclamations: %v", err) logger.Error("Failed to save synced proclamations: %v", err)
return nil, err return nil, err
@@ -49,8 +52,8 @@ func SyncProclamations(apiURL string, database *gorm.DB) ([]db.Proclamation, err
return proclamations, nil return proclamations, nil
} }
func SyncCategories(apiURL string, database *gorm.DB) ([]db.ProclamationCategory, error) { func SyncCategories(database *gorm.DB) ([]db.ProclamationCategory, error) {
fullURL := fmt.Sprintf("%s/categories", apiURL) fullURL := "https://portal.rhemawavetech.com/api/v1/categories"
categories, err := netreq.GetJSON[db.ProclamationCategory](fullURL) categories, err := netreq.GetJSON[db.ProclamationCategory](fullURL)
if err != nil { if err != nil {
logger.Error("Category sync failed, skipping update: %v", err) logger.Error("Category sync failed, skipping update: %v", err)