Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .qwen-session
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6b5aa18b-cd2a-44b0-9806-dfe8452db7a9
78 changes: 78 additions & 0 deletions packages/web-shell/client/App.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,76 @@
overflow: hidden;
}

.mobileDrawer {
display: contents;
}

.mobileBackdrop {
display: none;
}

.hamburgerButton {
display: none;
align-items: center;
justify-content: center;
width: 40px;
height: 40px;
padding: 0;
border: none;
background: transparent;
color: var(--foreground);
cursor: pointer;
flex-shrink: 0;
border-radius: var(--radius);
}

.hamburgerButton:hover {
background: var(--accent);
}

.hamburgerButton svg {
width: 20px;
height: 20px;
}

@media (max-width: 760px) {
.mobileDrawer {
display: block;
position: fixed;
top: 0;
left: 0;
bottom: 0;
z-index: 50;
Comment thread
pomelo-nwu marked this conversation as resolved.
Resolved
pointer-events: none;
visibility: hidden;
}
Comment thread
pomelo-nwu marked this conversation as resolved.
Resolved

.mobileDrawerOpen {
visibility: visible;
pointer-events: auto;
}

.mobileBackdrop {
display: block;
position: fixed;
inset: 0;
z-index: 49;
background: rgba(0, 0, 0, 0.5);
opacity: 0;
pointer-events: none;
transition: opacity 200ms ease;
}

.mobileDrawerOpen .mobileBackdrop {
opacity: 1;
pointer-events: auto;
}

.hamburgerButton {
display: flex;
}
}

.appChatEmpty.appWithSidebar {
justify-content: flex-start;
overflow: hidden;
Expand All @@ -59,6 +129,14 @@
overflow-y: auto;
}

@media (max-width: 760px) {
.appChatEmpty .hamburgerButton {
position: sticky;
top: 0;
z-index: 1;
}
}

.app,
.app * {
box-sizing: border-box;
Expand Down
112 changes: 102 additions & 10 deletions packages/web-shell/client/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,47 @@ export function App({
const [sidebarSwitchingSessionId, setSidebarSwitchingSessionId] = useState<
string | null
>(null);
const [mobileDrawerOpen, setMobileDrawerOpen] = useState(false);
const closeMobileDrawer = useCallback(() => setMobileDrawerOpen(false), []);
Comment thread
pomelo-nwu marked this conversation as resolved.
Resolved

useEffect(() => {
const mql = window.matchMedia('(max-width: 760px)');
Comment thread
pomelo-nwu marked this conversation as resolved.
Resolved
const handler = (e: MediaQueryListEvent) => {
if (!e.matches) setMobileDrawerOpen(false);
};
mql.addEventListener('change', handler);
return () => mql.removeEventListener('change', handler);
}, []);

useEffect(() => {
if (!mobileDrawerOpen) return;
const onKey = (e: KeyboardEvent) => {
if (e.key === 'Escape') {
Comment thread
pomelo-nwu marked this conversation as resolved.
Resolved
const target = e.target as HTMLElement | null;
if (
target &&
Comment thread
pomelo-nwu marked this conversation as resolved.
Resolved
(target.tagName === 'INPUT' ||
target.tagName === 'TEXTAREA' ||
target.isContentEditable)
) {
return;
}
e.stopPropagation();
Comment thread
pomelo-nwu marked this conversation as resolved.
Resolved
e.preventDefault();
closeMobileDrawer();
}
};
const prevOverflow = document.body.style.overflow;
document.body.style.overflow = 'hidden';
const preventScroll = (e: TouchEvent) => e.preventDefault();
Comment thread
pomelo-nwu marked this conversation as resolved.
Resolved
document.addEventListener('touchmove', preventScroll, { passive: false });
window.addEventListener('keydown', onKey, true);
return () => {
document.body.style.overflow = prevOverflow;
document.removeEventListener('touchmove', preventScroll);
window.removeEventListener('keydown', onKey, true);
};
}, [mobileDrawerOpen, closeMobileDrawer]);
const handleSidebarCollapsedChange = useCallback((collapsed: boolean) => {
setSidebarCollapsed(collapsed);
writeSidebarCollapsed(collapsed);
Expand Down Expand Up @@ -2155,6 +2196,7 @@ export function App({
const session = await (
sessionActions as typeof sessionActions & SessionActionsWithCreate
).createSession();
closeMobileDrawer();
Comment thread
pomelo-nwu marked this conversation as resolved.
Resolved
if (onSessionIdChange) {
onSessionIdChange(session.sessionId);
return true;
Expand All @@ -2169,7 +2211,7 @@ export function App({
reportError(error, 'Failed to create a new session');
return false;
}
}, [onSessionIdChange, reportError, sessionActions]);
}, [closeMobileDrawer, onSessionIdChange, reportError, sessionActions]);

const loadSidebarSession = useCallback(
async (sessionId: string) => {
Expand All @@ -2178,14 +2220,15 @@ export function App({
await sessionActions.loadSession(sessionId, {
deferTranscriptReset: true,
});
closeMobileDrawer();
Comment thread
pomelo-nwu marked this conversation as resolved.
Resolved
Comment thread
pomelo-nwu marked this conversation as resolved.
Resolved
} catch (error) {
setSidebarSwitchingSessionId((current) =>
current === sessionId ? null : current,
);
throw error;
}
},
[sessionActions],
[closeMobileDrawer, sessionActions],
);

useEffect(() => {
Expand Down Expand Up @@ -2915,10 +2958,12 @@ export function App({
if (cmd === 'resume') {
const sessionId = text.slice(match[0].length).trim();
if (sessionId) {
closeMobileDrawer();
Comment thread
pomelo-nwu marked this conversation as resolved.
Resolved
sessionActions.loadSession(sessionId).catch((error: unknown) => {
reportError(error, 'Failed to load session');
});
} else {
closeMobileDrawer();
setShowResumeDialog(true);
}
return true;
Expand Down Expand Up @@ -3098,6 +3143,7 @@ export function App({
enqueuePrompt,
echoOrDeferLocalCommand,
branchCurrentSession,
closeMobileDrawer,
createNewSession,
handleBusyGoalClear,
handleGoalSlashCommand,
Expand Down Expand Up @@ -3521,6 +3567,7 @@ export function App({
>
<ResumeDialog
onSelect={(sessionId) => {
closeMobileDrawer();
sessionActions
.loadSession(sessionId)
.catch((error: unknown) => {
Expand Down Expand Up @@ -3793,16 +3840,61 @@ export function App({

<div className={styles.appShell}>
{sidebarOptions.enabled && (
<WebShellSidebar
collapsed={sidebarCollapsed}
onCollapsedChange={handleSidebarCollapsedChange}
onOpenSettings={() => setShowSettingsDialog(true)}
onNewSession={createNewSession}
onLoadSession={loadSidebarSession}
onError={reportError}
/>
<div
{...(mobileDrawerOpen
? { role: 'dialog', 'aria-modal': 'true' as const }
: {})}
aria-label={t('sidebar.label')}
className={[
styles.mobileDrawer,
mobileDrawerOpen ? styles.mobileDrawerOpen : undefined,
]
Comment thread
pomelo-nwu marked this conversation as resolved.
Resolved
.filter(Boolean)
.join(' ')}
>
<div
className={styles.mobileBackdrop}
onClick={closeMobileDrawer}
aria-hidden="true"
/>
<WebShellSidebar
collapsed={sidebarCollapsed}
Comment thread
pomelo-nwu marked this conversation as resolved.
Resolved
Comment thread
pomelo-nwu marked this conversation as resolved.
Resolved
onCollapsedChange={handleSidebarCollapsedChange}
onOpenSettings={() => {
Comment thread
pomelo-nwu marked this conversation as resolved.
Resolved
closeMobileDrawer();
setShowSettingsDialog(true);
}}
onNewSession={createNewSession}
onLoadSession={loadSidebarSession}
onError={reportError}
mobileOpen={mobileDrawerOpen}
/>
</div>
)}
<div className={styles.chatPane}>
{sidebarOptions.enabled && (
<button
type="button"
className={styles.hamburgerButton}
Comment thread
pomelo-nwu marked this conversation as resolved.
Resolved
Comment thread
pomelo-nwu marked this conversation as resolved.
Resolved
onClick={() => setMobileDrawerOpen((open) => !open)}
aria-label={t('sidebar.toggleMenu')}
aria-expanded={mobileDrawerOpen}
>
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
aria-hidden="true"
>
<line x1="3" y1="6" x2="21" y2="6" />
<line x1="3" y1="12" x2="21" y2="12" />
<line x1="3" y1="18" x2="21" y2="18" />
</svg>
</button>
)}
<WebShellCustomizationProvider value={customization}>
<CompactModeContext.Provider value={compactMode}>
<TodoContextsProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -632,4 +632,16 @@
.sidebar {
display: none;
}

.sidebar.mobileOpen {
Comment thread
pomelo-nwu marked this conversation as resolved.
Resolved
display: flex;
position: relative;
z-index: 50;
width: var(--web-shell-sidebar-width, 260px);
min-width: var(--web-shell-sidebar-width, 260px);
}
Comment thread
pomelo-nwu marked this conversation as resolved.
Resolved

.resizeHandle {
display: none;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface WebShellSidebarProps {
onNewSession: () => Promise<boolean> | boolean;
onLoadSession: (sessionId: string) => Promise<void> | void;
onError: (error: unknown, fallback: string) => void;
mobileOpen?: boolean;
}

function cx(...classes: Array<string | false | undefined>): string {
Expand Down Expand Up @@ -175,6 +176,7 @@ export function WebShellSidebar({
onNewSession,
onLoadSession,
onError,
mobileOpen,
}: WebShellSidebarProps) {
const { t } = useI18n();
const connection = useConnection();
Expand Down Expand Up @@ -754,6 +756,7 @@ export function WebShellSidebar({
styles.sidebar,
collapsed && styles.collapsed,
isResizing && styles.resizing,
mobileOpen && styles.mobileOpen,
)}
aria-label={t('sidebar.label')}
style={sidebarStyle}
Expand Down
2 changes: 2 additions & 0 deletions packages/web-shell/client/i18n.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ const EN: Messages = {
'quickActions.exitShellMode': 'Exit Shell',
'quickActions.setGoal': 'Set goal',
'sidebar.label': 'Workspace sidebar',
'sidebar.toggleMenu': 'Toggle menu',
'sidebar.newChat': 'New chat',
'sidebar.project': 'Project',
'sidebar.projectFallback': 'Project',
Expand Down Expand Up @@ -1603,6 +1604,7 @@ const ZH: Messages = {
'quickActions.exitShellMode': '退出Shell',
'quickActions.setGoal': '设置目标',
'sidebar.label': '工作区侧边栏',
'sidebar.toggleMenu': '切换菜单',
'sidebar.newChat': '新对话',
'sidebar.project': '项目',
'sidebar.projectFallback': '项目',
Expand Down
Loading