Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PWA-1] fix: pwa app sidebar redirection #5416

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"use client";
import React, { FC } from "react";
import { observer } from "mobx-react";
import Link from "next/link";
import { useAppTheme } from "@/hooks/store";
import { usePlatformOS } from "@/hooks/use-platform-os";

type Props = {
projectId: string | null;
Expand All @@ -10,8 +13,11 @@ type Props = {
isSidebarCollapsed: boolean;
};

export const FavoriteItemTitle: FC<Props> = (props) => {
export const FavoriteItemTitle: FC<Props> = observer((props) => {
const { projectId, href, title, icon, isSidebarCollapsed } = props;
// store hooks
const { toggleSidebar } = useAppTheme();
const { isMobile } = usePlatformOS();

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

return (
Expand All @@ -30,4 +37,4 @@ export const FavoriteItemTitle: FC<Props> = (props) => {
{!isSidebarCollapsed && <span className="text-sm leading-5 font-medium flex-1 truncate">{title}</span>}
</Link>
);
};
});
20 changes: 16 additions & 4 deletions web/core/components/workspace/sidebar/projects-list-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { setCustomNativeDragPreview } from "@atlaskit/pragmatic-drag-and-drop/el
import { attachInstruction, extractInstruction } from "@atlaskit/pragmatic-drag-and-drop-hitbox/tree-item";
import { observer } from "mobx-react";
import Link from "next/link";
import { useParams, usePathname } from "next/navigation";
import { useParams, usePathname, useRouter } from "next/navigation";
import { createRoot } from "react-dom/client";
import {
PenSquare,
Expand Down Expand Up @@ -126,7 +126,8 @@ export const SidebarProjectsListItem: React.FC<Props> = observer((props) => {
const actionSectionRef = useRef<HTMLDivElement | null>(null);
const projectRef = useRef<HTMLDivElement | null>(null);
const dragHandleRef = useRef<HTMLButtonElement | null>(null);
// router params
// router
const router = useRouter();
const { workspaceSlug, projectId: URLProjectId } = useParams();
// pathname
const pathname = usePathname();
Expand Down Expand Up @@ -281,6 +282,17 @@ export const SidebarProjectsListItem: React.FC<Props> = observer((props) => {
else setIsProjectListOpen(false);
}, [URLProjectId]);

const handleItemClick = () => {
const isDifferentProject = URLProjectId !== project.id;
if (!isProjectListOpen) {
router.push(`/${workspaceSlug}/projects/${project.id}/issues`);
if (isDifferentProject && isMobile) {
toggleSidebar();
}
}
setIsProjectListOpen((prev) => !prev);
};

return (
<>
<PublishProjectModal isOpen={publishModalOpen} project={project} onClose={() => setPublishModal(false)} />
Expand Down Expand Up @@ -337,7 +349,7 @@ export const SidebarProjectsListItem: React.FC<Props> = observer((props) => {
<Disclosure.Button
as="button"
className="size-8 aspect-square flex-shrink-0 grid place-items-center"
onClick={() => setIsProjectListOpen(!isProjectListOpen)}
onClick={handleItemClick}
>
<div className="size-4 grid place-items-center flex-shrink-0">
<Logo logo={project.logo_props} size={16} />
Expand All @@ -359,7 +371,7 @@ export const SidebarProjectsListItem: React.FC<Props> = observer((props) => {
className={cn("flex-grow flex items-center gap-1.5 text-left select-none w-full", {
"justify-center": isSidebarCollapsed,
})}
onClick={() => setIsProjectListOpen(!isProjectListOpen)}
onClick={handleItemClick}
>
<div className="size-4 grid place-items-center flex-shrink-0">
<Logo logo={project.logo_props} size={16} />
Expand Down
Loading