app is working again. new structure for blocks. new useWaveObjectValueWithSuspense hook

This commit is contained in:
sawka
2024-05-27 15:44:57 -07:00
parent abedca2364
commit e6d7a4e674
14 changed files with 193 additions and 144 deletions
+25 -2
View File
@@ -168,7 +168,8 @@ func (update WaveObjUpdate) MarshalJSON() ([]byte, error) {
}
type UIContext struct {
WindowId string `json:"windowid"`
WindowId string `json:"windowid"`
ActiveTabId string `json:"activetabid"`
}
type Client struct {
@@ -239,7 +240,7 @@ type FileDef struct {
}
type BlockDef struct {
Controller string `json:"controller"`
Controller string `json:"controller,omitempty"`
View string `json:"view,omitempty"`
Files map[string]*FileDef `json:"files,omitempty"`
Meta map[string]any `json:"meta,omitempty"`
@@ -317,6 +318,28 @@ func SetActiveTab(ctx context.Context, windowId string, tabId string) error {
})
}
func CreateBlock(ctx context.Context, tabId string, blockDef *BlockDef, rtOpts *RuntimeOpts) (*Block, error) {
return WithTxRtn(ctx, func(tx *TxWrap) (*Block, error) {
tab, _ := DBGet[*Tab](tx.Context(), tabId)
if tab == nil {
return nil, fmt.Errorf("tab not found: %q", tabId)
}
blockId := uuid.New().String()
blockData := &Block{
OID: blockId,
BlockDef: blockDef,
Controller: blockDef.Controller,
View: blockDef.View,
RuntimeOpts: rtOpts,
Meta: blockDef.Meta,
}
DBInsert(tx.Context(), blockData)
tab.BlockIds = append(tab.BlockIds, blockId)
DBUpdate(tx.Context(), tab)
return blockData, nil
})
}
func EnsureInitialData() error {
// does not need to run in a transaction since it is called on startup
ctx, cancelFn := context.WithTimeout(context.Background(), 2*time.Second)