Skip to content

Commit 3ee1477

Browse files
[PWA-1] fix: pwa app sidebar redirection (#5416)
* fix: pwa app sidebar redirection * chore: pwa app sidebar improvement
1 parent 59697d3 commit 3ee1477

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

web/core/components/workspace/sidebar/favorites/favorite-items/common/favorite-item-title.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
"use client";
22
import React, { FC } from "react";
3+
import { observer } from "mobx-react";
34
import Link from "next/link";
5+
import { useAppTheme } from "@/hooks/store";
6+
import { usePlatformOS } from "@/hooks/use-platform-os";
47

58
type Props = {
69
projectId: string | null;
@@ -10,8 +13,11 @@ type Props = {
1013
isSidebarCollapsed: boolean;
1114
};
1215

13-
export const FavoriteItemTitle: FC<Props> = (props) => {
16+
export const FavoriteItemTitle: FC<Props> = observer((props) => {
1417
const { projectId, href, title, icon, isSidebarCollapsed } = props;
18+
// store hooks
19+
const { toggleSidebar } = useAppTheme();
20+
const { isMobile } = usePlatformOS();
1521

1622
const linkClass = "flex items-center gap-1.5 truncate w-full";
1723
const collapsedClass =
@@ -22,6 +28,7 @@ export const FavoriteItemTitle: FC<Props> = (props) => {
2228
const projectItem = document.getElementById(`${projectId}`);
2329
projectItem?.scrollIntoView({ behavior: "smooth" });
2430
}
31+
if (isMobile) toggleSidebar();
2532
};
2633

2734
return (
@@ -30,4 +37,4 @@ export const FavoriteItemTitle: FC<Props> = (props) => {
3037
{!isSidebarCollapsed && <span className="text-sm leading-5 font-medium flex-1 truncate">{title}</span>}
3138
</Link>
3239
);
33-
};
40+
});

web/core/components/workspace/sidebar/projects-list-item.tsx

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { setCustomNativeDragPreview } from "@atlaskit/pragmatic-drag-and-drop/el
88
import { attachInstruction, extractInstruction } from "@atlaskit/pragmatic-drag-and-drop-hitbox/tree-item";
99
import { observer } from "mobx-react";
1010
import Link from "next/link";
11-
import { useParams, usePathname } from "next/navigation";
11+
import { useParams, usePathname, useRouter } from "next/navigation";
1212
import { createRoot } from "react-dom/client";
1313
import {
1414
PenSquare,
@@ -35,6 +35,7 @@ import {
3535
DropIndicator,
3636
DragHandle,
3737
Intake,
38+
ControlLink,
3839
} from "@plane/ui";
3940
// components
4041
import { Logo } from "@/components/common";
@@ -126,7 +127,8 @@ export const SidebarProjectsListItem: React.FC<Props> = observer((props) => {
126127
const actionSectionRef = useRef<HTMLDivElement | null>(null);
127128
const projectRef = useRef<HTMLDivElement | null>(null);
128129
const dragHandleRef = useRef<HTMLButtonElement | null>(null);
129-
// router params
130+
// router
131+
const router = useRouter();
130132
const { workspaceSlug, projectId: URLProjectId } = useParams();
131133
// pathname
132134
const pathname = usePathname();
@@ -281,11 +283,16 @@ export const SidebarProjectsListItem: React.FC<Props> = observer((props) => {
281283
else setIsProjectListOpen(false);
282284
}, [URLProjectId]);
283285

286+
const handleItemClick = () => {
287+
if (!isProjectListOpen && !isMobile) router.push(`/${workspaceSlug}/projects/${project.id}/issues`);
288+
setIsProjectListOpen((prev) => !prev);
289+
};
290+
284291
return (
285292
<>
286293
<PublishProjectModal isOpen={publishModalOpen} project={project} onClose={() => setPublishModal(false)} />
287294
<LeaveProjectModal project={project} isOpen={leaveProjectModalOpen} onClose={() => setLeaveProjectModal(false)} />
288-
<Disclosure key={`${project.id}_${URLProjectId}`} ref={projectRef} defaultOpen={isProjectListOpen}>
295+
<Disclosure key={`${project.id}_${URLProjectId}`} ref={projectRef} defaultOpen={isProjectListOpen} as="div">
289296
<div
290297
id={`sidebar-${projectId}-${projectListType}`}
291298
className={cn("relative", {
@@ -328,22 +335,19 @@ export const SidebarProjectsListItem: React.FC<Props> = observer((props) => {
328335
</Tooltip>
329336
)}
330337
{isSidebarCollapsed ? (
331-
<Link
338+
<ControlLink
332339
href={`/${workspaceSlug}/projects/${project.id}/issues`}
333340
className={cn("flex-grow flex items-center gap-1.5 truncate text-left select-none", {
334341
"justify-center": isSidebarCollapsed,
335342
})}
343+
onClick={handleItemClick}
336344
>
337-
<Disclosure.Button
338-
as="button"
339-
className="size-8 aspect-square flex-shrink-0 grid place-items-center"
340-
onClick={() => setIsProjectListOpen(!isProjectListOpen)}
341-
>
345+
<Disclosure.Button as="button" className="size-8 aspect-square flex-shrink-0 grid place-items-center">
342346
<div className="size-4 grid place-items-center flex-shrink-0">
343347
<Logo logo={project.logo_props} size={16} />
344348
</div>
345349
</Disclosure.Button>
346-
</Link>
350+
</ControlLink>
347351
) : (
348352
<>
349353
<Tooltip
@@ -352,21 +356,24 @@ export const SidebarProjectsListItem: React.FC<Props> = observer((props) => {
352356
disabled={!isSidebarCollapsed}
353357
isMobile={isMobile}
354358
>
355-
<Link href={`/${workspaceSlug}/projects/${project.id}/issues`} className="flex-grow flex truncate">
359+
<ControlLink
360+
href={`/${workspaceSlug}/projects/${project.id}/issues`}
361+
className="flex-grow flex truncate"
362+
onClick={handleItemClick}
363+
>
356364
<Disclosure.Button
357365
as="button"
358366
type="button"
359367
className={cn("flex-grow flex items-center gap-1.5 text-left select-none w-full", {
360368
"justify-center": isSidebarCollapsed,
361369
})}
362-
onClick={() => setIsProjectListOpen(!isProjectListOpen)}
363370
>
364371
<div className="size-4 grid place-items-center flex-shrink-0">
365372
<Logo logo={project.logo_props} size={16} />
366373
</div>
367374
<p className="truncate text-sm font-medium text-custom-sidebar-text-200">{project.name}</p>
368375
</Disclosure.Button>
369-
</Link>
376+
</ControlLink>
370377
</Tooltip>
371378
<CustomMenu
372379
customButton={

0 commit comments

Comments
 (0)