Squash some leftover bugs (#1495)

Only create new tab in `CheckAndFixWindow` if no tabs or pinned tabs
exist

Update `resolvers.resolveTabNum` to account for pinned tabs

Remove obsolete and unused `wstore.DeleteTab`

Only show accelerators for first 9 workspaces in workspace app menu to
be consistent with other keybindings

Fix tabbar spacing to remove min size for drag right spacer, account for
workspace switcher button size

Fix updatebanner size calculations
This commit is contained in:
Evan Simkowitz 2024-12-11 12:52:15 -08:00 committed by GitHub
parent 87ebbdd2f9
commit 4070abadde
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 72 additions and 70 deletions

BIN
build/icons/48x48.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
build/icons/64x64.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -49,13 +49,8 @@ async function getWorkspaceMenu(ww?: WaveBrowserWindow): Promise<Electron.MenuIt
}, },
]; ];
function getWorkspaceSwitchAccelerator(i: number): string { function getWorkspaceSwitchAccelerator(i: number): string {
if (i < 10) { if (i < 9) {
if (i == 9) { return unamePlatform == "darwin" ? `Command+Control+${i}` : `Alt+Control+${i + 1}`;
i = 0;
} else {
i++;
}
return unamePlatform == "darwin" ? `Command+Control+${i}` : `Alt+Control+${i}`;
} }
} }
workspaceList?.length && workspaceList?.length &&

View File

@ -27,7 +27,7 @@
user-select: none; user-select: none;
display: flex; display: flex;
flex-direction: row; flex-direction: row;
width: env(titlebar-area-width); width: 100vw;
-webkit-app-region: drag; -webkit-app-region: drag;
* { * {
@ -61,7 +61,7 @@
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
margin: 6px 6px 0 0; padding: 6px 6px 0 0;
} }
.app-menu-button { .app-menu-button {

View File

@ -19,7 +19,6 @@ import { WorkspaceSwitcher } from "./workspaceswitcher";
const TAB_DEFAULT_WIDTH = 130; const TAB_DEFAULT_WIDTH = 130;
const TAB_MIN_WIDTH = 100; const TAB_MIN_WIDTH = 100;
const DRAGGER_RIGHT_MIN_WIDTH = 74;
const OS_OPTIONS = { const OS_OPTIONS = {
overflow: { overflow: {
x: "scroll", x: "scroll",
@ -168,7 +167,7 @@ const TabBar = memo(({ workspace }: TabBarProps) => {
const appMenuButtonRef = useRef<HTMLDivElement>(null); const appMenuButtonRef = useRef<HTMLDivElement>(null);
const tabWidthRef = useRef<number>(TAB_DEFAULT_WIDTH); const tabWidthRef = useRef<number>(TAB_DEFAULT_WIDTH);
const scrollableRef = useRef<boolean>(false); const scrollableRef = useRef<boolean>(false);
const updateStatusButtonRef = useRef<HTMLButtonElement>(null); const updateStatusBannerRef = useRef<HTMLDivElement>(null);
const configErrorButtonRef = useRef<HTMLElement>(null); const configErrorButtonRef = useRef<HTMLElement>(null);
const prevAllLoadedRef = useRef<boolean>(false); const prevAllLoadedRef = useRef<boolean>(false);
const activeTabId = useAtomValue(atoms.staticTabId); const activeTabId = useAtomValue(atoms.staticTabId);
@ -227,8 +226,9 @@ const TabBar = memo(({ workspace }: TabBarProps) => {
const tabbarWrapperWidth = tabbarWrapperRef.current.getBoundingClientRect().width; const tabbarWrapperWidth = tabbarWrapperRef.current.getBoundingClientRect().width;
const windowDragLeftWidth = draggerLeftRef.current.getBoundingClientRect().width; const windowDragLeftWidth = draggerLeftRef.current.getBoundingClientRect().width;
const windowDragRightWidth = draggerRightRef.current.getBoundingClientRect().width;
const addBtnWidth = addBtnRef.current.getBoundingClientRect().width; const addBtnWidth = addBtnRef.current.getBoundingClientRect().width;
const updateStatusLabelWidth = updateStatusButtonRef.current?.getBoundingClientRect().width ?? 0; const updateStatusLabelWidth = updateStatusBannerRef.current?.getBoundingClientRect().width ?? 0;
const configErrorWidth = configErrorButtonRef.current?.getBoundingClientRect().width ?? 0; const configErrorWidth = configErrorButtonRef.current?.getBoundingClientRect().width ?? 0;
const appMenuButtonWidth = appMenuButtonRef.current?.getBoundingClientRect().width ?? 0; const appMenuButtonWidth = appMenuButtonRef.current?.getBoundingClientRect().width ?? 0;
const workspaceSwitcherWidth = workspaceSwitcherRef.current?.getBoundingClientRect().width ?? 0; const workspaceSwitcherWidth = workspaceSwitcherRef.current?.getBoundingClientRect().width ?? 0;
@ -236,7 +236,7 @@ const TabBar = memo(({ workspace }: TabBarProps) => {
const nonTabElementsWidth = const nonTabElementsWidth =
windowDragLeftWidth + windowDragLeftWidth +
DRAGGER_RIGHT_MIN_WIDTH + windowDragRightWidth +
addBtnWidth + addBtnWidth +
updateStatusLabelWidth + updateStatusLabelWidth +
configErrorWidth + configErrorWidth +
@ -256,6 +256,21 @@ const TabBar = memo(({ workspace }: TabBarProps) => {
// Determine if the tab bar needs to be scrollable // Determine if the tab bar needs to be scrollable
const newScrollable = idealTabWidth * numberOfTabs > spaceForTabs; const newScrollable = idealTabWidth * numberOfTabs > spaceForTabs;
console.log(
"tabbarWrapperWidth",
tabbarWrapperWidth,
"nonTabElementsWidth",
nonTabElementsWidth,
"idealTabWidth",
idealTabWidth,
"spaceForTabs",
spaceForTabs,
"newScrollable",
newScrollable,
"devLabelWidth",
devLabelWidth
);
// Apply the calculated width and position to all tabs // Apply the calculated width and position to all tabs
tabRefs.current.forEach((ref, index) => { tabRefs.current.forEach((ref, index) => {
if (ref.current) { if (ref.current) {
@ -653,7 +668,7 @@ const TabBar = memo(({ workspace }: TabBarProps) => {
<WindowDrag ref={draggerLeftRef} className="left" /> <WindowDrag ref={draggerLeftRef} className="left" />
{appMenuButton} {appMenuButton}
{devLabel} {devLabel}
<WorkspaceSwitcher /> <WorkspaceSwitcher ref={workspaceSwitcherRef} />
<div className="tab-bar" ref={tabBarRef} data-overlayscrollbars-initialize> <div className="tab-bar" ref={tabBarRef} data-overlayscrollbars-initialize>
<div className="tabs-wrapper" ref={tabsWrapperRef} style={{ width: `${tabsWrapperWidth}px` }}> <div className="tabs-wrapper" ref={tabsWrapperRef} style={{ width: `${tabsWrapperWidth}px` }}>
{tabIds.map((tabId, index) => { {tabIds.map((tabId, index) => {
@ -683,8 +698,8 @@ const TabBar = memo(({ workspace }: TabBarProps) => {
<div ref={addBtnRef} className="add-tab-btn" onClick={handleAddTab}> <div ref={addBtnRef} className="add-tab-btn" onClick={handleAddTab}>
<i className="fa fa-solid fa-plus fa-fw" /> <i className="fa fa-solid fa-plus fa-fw" />
</div> </div>
<WindowDrag ref={draggerRightRef} className="right" style={{ minWidth: DRAGGER_RIGHT_MIN_WIDTH }} /> <WindowDrag ref={draggerRightRef} className="right" />
<UpdateStatusBanner buttonRef={updateStatusButtonRef} /> <UpdateStatusBanner ref={updateStatusBannerRef} />
<ConfigErrorIcon buttonRef={configErrorButtonRef} /> <ConfigErrorIcon buttonRef={configErrorButtonRef} />
</div> </div>
); );

View File

@ -1,7 +1,10 @@
.update-available-button { .update-available-banner {
display: flex;
height: 100%;
.button {
color: black;
height: 80%; height: 80%;
margin: auto 4px; margin: auto 4px;
color: black;
background-color: var(--accent-color); background-color: var(--accent-color);
flex: 0 0 fit-content; flex: 0 0 fit-content;
@ -9,3 +12,4 @@
opacity: unset !important; opacity: unset !important;
} }
} }
}

View File

@ -1,10 +1,10 @@
import { Button } from "@/element/button"; import { Button } from "@/element/button";
import { atoms, getApi } from "@/store/global"; import { atoms, getApi } from "@/store/global";
import { useAtomValue } from "jotai"; import { useAtomValue } from "jotai";
import { memo, useEffect, useState } from "react"; import { forwardRef, memo, useEffect, useState } from "react";
import "./updatebanner.scss"; import "./updatebanner.scss";
const UpdateStatusBannerComponent = ({ buttonRef }: { buttonRef: React.RefObject<HTMLButtonElement> }) => { const UpdateStatusBannerComponent = forwardRef<HTMLDivElement>((_, ref) => {
const appUpdateStatus = useAtomValue(atoms.updaterStatusAtom); const appUpdateStatus = useAtomValue(atoms.updaterStatusAtom);
let [updateStatusMessage, setUpdateStatusMessage] = useState<string>(); let [updateStatusMessage, setUpdateStatusMessage] = useState<string>();
const [dismissBannerTimeout, setDismissBannerTimeout] = useState<NodeJS.Timeout>(); const [dismissBannerTimeout, setDismissBannerTimeout] = useState<NodeJS.Timeout>();
@ -54,8 +54,8 @@ const UpdateStatusBannerComponent = ({ buttonRef }: { buttonRef: React.RefObject
} }
if (updateStatusMessage) { if (updateStatusMessage) {
return ( return (
<div className="update-available-banner" ref={ref}>
<Button <Button
ref={buttonRef}
className="update-available-button" className="update-available-button"
title={appUpdateStatus === "ready" ? "Click to Install Update" : updateStatusMessage} title={appUpdateStatus === "ready" ? "Click to Install Update" : updateStatusMessage}
onClick={onClick} onClick={onClick}
@ -63,8 +63,9 @@ const UpdateStatusBannerComponent = ({ buttonRef }: { buttonRef: React.RefObject
> >
{updateStatusMessage} {updateStatusMessage}
</Button> </Button>
</div>
); );
} }
}; });
export const UpdateStatusBanner = memo(UpdateStatusBannerComponent) as typeof UpdateStatusBannerComponent; export const UpdateStatusBanner = memo(UpdateStatusBannerComponent) as typeof UpdateStatusBannerComponent;

View File

@ -17,7 +17,7 @@ import clsx from "clsx";
import { atom, PrimitiveAtom, useAtom, useAtomValue, useSetAtom } from "jotai"; import { atom, PrimitiveAtom, useAtom, useAtomValue, useSetAtom } from "jotai";
import { splitAtom } from "jotai/utils"; import { splitAtom } from "jotai/utils";
import { OverlayScrollbarsComponent } from "overlayscrollbars-react"; import { OverlayScrollbarsComponent } from "overlayscrollbars-react";
import { CSSProperties, memo, useCallback, useEffect, useRef } from "react"; import { CSSProperties, forwardRef, memo, useCallback, useEffect, useRef } from "react";
import WorkspaceSVG from "../asset/workspace.svg"; import WorkspaceSVG from "../asset/workspace.svg";
import { IconButton } from "../element/iconbutton"; import { IconButton } from "../element/iconbutton";
import { atoms, getApi } from "../store/global"; import { atoms, getApi } from "../store/global";
@ -167,7 +167,7 @@ type WorkspaceList = WorkspaceListEntry[];
const workspaceMapAtom = atom<WorkspaceList>([]); const workspaceMapAtom = atom<WorkspaceList>([]);
const workspaceSplitAtom = splitAtom(workspaceMapAtom); const workspaceSplitAtom = splitAtom(workspaceMapAtom);
const editingWorkspaceAtom = atom<string>(); const editingWorkspaceAtom = atom<string>();
const WorkspaceSwitcher = () => { const WorkspaceSwitcher = forwardRef<HTMLDivElement>((_, ref) => {
const setWorkspaceList = useSetAtom(workspaceMapAtom); const setWorkspaceList = useSetAtom(workspaceMapAtom);
const activeWorkspace = useAtomValueSafe(atoms.workspace); const activeWorkspace = useAtomValueSafe(atoms.workspace);
const workspaceList = useAtomValue(workspaceSplitAtom); const workspaceList = useAtomValue(workspaceSplitAtom);
@ -231,6 +231,7 @@ const WorkspaceSwitcher = () => {
className="workspace-switcher-popover" className="workspace-switcher-popover"
placement="bottom-start" placement="bottom-start"
onDismiss={() => setEditingWorkspace(null)} onDismiss={() => setEditingWorkspace(null)}
ref={ref}
> >
<PopoverButton <PopoverButton
className="workspace-switcher-button grey" className="workspace-switcher-button grey"
@ -271,7 +272,7 @@ const WorkspaceSwitcher = () => {
</PopoverContent> </PopoverContent>
</Popover> </Popover>
); );
}; });
const WorkspaceSwitcherItem = ({ const WorkspaceSwitcherItem = ({
entryAtom, entryAtom,

View File

@ -177,7 +177,7 @@ func CheckAndFixWindow(ctx context.Context, windowId string) *waveobj.Window {
CloseWindow(ctx, windowId, false) CloseWindow(ctx, windowId, false)
return nil return nil
} }
if len(ws.TabIds) == 0 { if len(ws.TabIds) == 0 && len(ws.PinnedTabIds) == 0 {
log.Printf("fixing workspace with no tabs %q (in checkAndFixWindow)\n", ws.OID) log.Printf("fixing workspace with no tabs %q (in checkAndFixWindow)\n", ws.OID)
_, err = CreateTab(ctx, ws.OID, "", true, false, false) _, err = CreateTab(ctx, ws.OID, "", true, false, false)
if err != nil { if err != nil {

View File

@ -156,11 +156,19 @@ func resolveTabNum(ctx context.Context, data wshrpc.CommandResolveIdsData, value
return nil, fmt.Errorf("error getting workspace: %v", err) return nil, fmt.Errorf("error getting workspace: %v", err)
} }
if tabNum < 1 || tabNum > len(ws.TabIds) { numPinnedTabs := len(ws.PinnedTabIds)
return nil, fmt.Errorf("tab num out of range, workspace has %d tabs", len(ws.TabIds)) numTabs := len(ws.TabIds) + numPinnedTabs
if tabNum < 1 || tabNum > numTabs {
return nil, fmt.Errorf("tab num out of range, workspace has %d tabs", numTabs)
} }
resolvedTabId := ws.TabIds[tabNum-1] tabIdx := tabNum - 1
var resolvedTabId string
if tabIdx < numPinnedTabs {
resolvedTabId = ws.PinnedTabIds[tabIdx]
} else {
resolvedTabId = ws.TabIds[tabIdx-numPinnedTabs]
}
return &waveobj.ORef{OType: waveobj.OType_Tab, OID: resolvedTabId}, nil return &waveobj.ORef{OType: waveobj.OType_Tab, OID: resolvedTabId}, nil
} }

View File

@ -31,28 +31,6 @@ func UpdateTabName(ctx context.Context, tabId, name string) error {
}) })
} }
// must delete all blocks individually first
// also deletes LayoutState
func DeleteTab(ctx context.Context, workspaceId string, tabId string) error {
return WithTx(ctx, func(tx *TxWrap) error {
tab, _ := DBGet[*waveobj.Tab](tx.Context(), tabId)
if tab == nil {
return nil
}
if len(tab.BlockIds) != 0 {
return fmt.Errorf("tab has blocks, must delete blocks first")
}
ws, _ := DBGet[*waveobj.Workspace](tx.Context(), workspaceId)
if ws != nil {
ws.TabIds = utilfn.RemoveElemFromSlice(ws.TabIds, tabId)
DBUpdate(tx.Context(), ws)
}
DBDelete(tx.Context(), waveobj.OType_Tab, tabId)
DBDelete(tx.Context(), waveobj.OType_LayoutState, tab.LayoutState)
return nil
})
}
func UpdateObjectMeta(ctx context.Context, oref waveobj.ORef, meta waveobj.MetaMapType, mergeSpecial bool) error { func UpdateObjectMeta(ctx context.Context, oref waveobj.ORef, meta waveobj.MetaMapType, mergeSpecial bool) error {
return WithTx(ctx, func(tx *TxWrap) error { return WithTx(ctx, func(tx *TxWrap) error {
if oref.IsEmpty() { if oref.IsEmpty() {