delete block and close tab working

This commit is contained in:
sawka
2024-05-27 16:33:31 -07:00
parent e6d7a4e674
commit 3f45945cb4
8 changed files with 165 additions and 24 deletions
@@ -132,3 +132,50 @@ func (svc *ObjectService) CreateBlock(uiContext wstore.UIContext, blockDef *wsto
rtn["blockid"] = blockData.OID
return updatesRtn(ctx, rtn)
}
func (svc *ObjectService) DeleteBlock(uiContext wstore.UIContext, blockId string) (any, error) {
ctx, cancelFn := context.WithTimeout(context.Background(), DefaultTimeout)
defer cancelFn()
ctx = wstore.ContextWithUpdates(ctx)
err := wstore.DeleteBlock(ctx, uiContext.ActiveTabId, blockId)
if err != nil {
return nil, fmt.Errorf("error deleting block: %w", err)
}
blockcontroller.StopBlockController(blockId)
return updatesRtn(ctx, nil)
}
func (svc *ObjectService) CloseTab(uiContext wstore.UIContext, tabId string) (any, error) {
ctx, cancelFn := context.WithTimeout(context.Background(), DefaultTimeout)
defer cancelFn()
ctx = wstore.ContextWithUpdates(ctx)
window, err := wstore.DBMustGet[*wstore.Window](ctx, uiContext.WindowId)
if err != nil {
return nil, fmt.Errorf("error getting window: %w", err)
}
tab, err := wstore.DBMustGet[*wstore.Tab](ctx, tabId)
if err != nil {
return nil, fmt.Errorf("error getting tab: %w", err)
}
for _, blockId := range tab.BlockIds {
blockcontroller.StopBlockController(blockId)
}
err = wstore.CloseTab(ctx, window.WorkspaceId, tabId)
if err != nil {
return nil, fmt.Errorf("error closing tab: %w", err)
}
if window.ActiveTabId == tabId {
ws, err := wstore.DBMustGet[*wstore.Workspace](ctx, window.WorkspaceId)
if err != nil {
return nil, fmt.Errorf("error getting workspace: %w", err)
}
var newActiveTabId string
if len(ws.TabIds) > 0 {
newActiveTabId = ws.TabIds[0]
} else {
newActiveTabId = ""
}
wstore.SetActiveTab(ctx, uiContext.WindowId, newActiveTabId)
}
return updatesRtn(ctx, nil)
}