Merge pull request #59 from dakshesh14/fix/issue_view

fix: sidebar collapsed hydration, changing list view type causing weird behavior
This commit is contained in:
Vihar Kurama 2022-12-20 19:43:45 +05:30 committed by GitHub
commit 1e2e4d3729
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 39 deletions

View File

@ -44,12 +44,13 @@ type ContextType = {
groupByProperty: NestedKeyOf<IIssue> | null; groupByProperty: NestedKeyOf<IIssue> | null;
filterIssue: "activeIssue" | "backlogIssue" | null; filterIssue: "activeIssue" | "backlogIssue" | null;
toggleCollapsed: () => void; toggleCollapsed: () => void;
setIssueView: (display: "list" | "kanban") => void;
setGroupByProperty: (property: NestedKeyOf<IIssue> | null) => void; setGroupByProperty: (property: NestedKeyOf<IIssue> | null) => void;
setOrderBy: (property: NestedKeyOf<IIssue> | null) => void; setOrderBy: (property: NestedKeyOf<IIssue> | null) => void;
setFilterIssue: (property: "activeIssue" | "backlogIssue" | null) => void; setFilterIssue: (property: "activeIssue" | "backlogIssue" | null) => void;
resetFilterToDefault: () => void; resetFilterToDefault: () => void;
setNewFilterDefaultView: () => void; setNewFilterDefaultView: () => void;
setIssueViewToKanban: () => void;
setIssueViewToList: () => void;
}; };
type StateType = Theme; type StateType = Theme;
@ -72,9 +73,12 @@ export const reducer: ReducerFunctionType = (state, action) => {
...state, ...state,
collapsed: !state.collapsed, collapsed: !state.collapsed,
}; };
localStorage.setItem("collapsed", JSON.stringify(newState.collapsed));
return newState; return newState;
case REHYDRATE_THEME: { case REHYDRATE_THEME: {
return { ...initialState, ...payload }; let collapsed: any = localStorage.getItem("collapsed");
collapsed = collapsed ? JSON.parse(collapsed) : false;
return { ...initialState, ...payload, collapsed };
} }
case SET_ISSUE_VIEW: { case SET_ISSUE_VIEW: {
const newState = { const newState = {
@ -159,23 +163,47 @@ export const ThemeContextProvider: React.FC<{ children: React.ReactNode }> = ({
}); });
}, []); }, []);
const setIssueView = useCallback( const setIssueViewToKanban = useCallback(() => {
(display: "list" | "kanban") => { dispatch({
dispatch({ type: SET_ISSUE_VIEW,
type: SET_ISSUE_VIEW, payload: {
payload: { issueView: "kanban",
issueView: display, },
}, });
}); dispatch({
type: SET_GROUP_BY_PROPERTY,
payload: {
groupByProperty: "state_detail.name",
},
});
if (!activeWorkspace || !activeProject) return;
saveDataToServer(activeWorkspace.slug, activeProject.id, {
...state,
issueView: "kanban",
groupByProperty: "state_detail.name",
});
}, [activeWorkspace, activeProject, state]);
if (!activeWorkspace || !activeProject) return; const setIssueViewToList = useCallback(() => {
saveDataToServer(activeWorkspace.slug, activeProject.id, { dispatch({
...state, type: SET_ISSUE_VIEW,
issueView: display, payload: {
}); issueView: "list",
}, },
[activeProject, activeWorkspace, state] });
); dispatch({
type: SET_GROUP_BY_PROPERTY,
payload: {
groupByProperty: null,
},
});
if (!activeWorkspace || !activeProject) return;
saveDataToServer(activeWorkspace.slug, activeProject.id, {
...state,
issueView: "list",
groupByProperty: null,
});
}, [activeWorkspace, activeProject, state]);
const setGroupByProperty = useCallback( const setGroupByProperty = useCallback(
(property: NestedKeyOf<IIssue> | null) => { (property: NestedKeyOf<IIssue> | null) => {
@ -259,7 +287,6 @@ export const ThemeContextProvider: React.FC<{ children: React.ReactNode }> = ({
collapsed: state.collapsed, collapsed: state.collapsed,
toggleCollapsed, toggleCollapsed,
issueView: state.issueView, issueView: state.issueView,
setIssueView,
groupByProperty: state.groupByProperty, groupByProperty: state.groupByProperty,
setGroupByProperty, setGroupByProperty,
orderBy: state.orderBy, orderBy: state.orderBy,
@ -268,6 +295,8 @@ export const ThemeContextProvider: React.FC<{ children: React.ReactNode }> = ({
setFilterIssue, setFilterIssue,
resetFilterToDefault: resetToDefault, resetFilterToDefault: resetToDefault,
setNewFilterDefaultView: setNewDefaultView, setNewFilterDefaultView: setNewDefaultView,
setIssueViewToKanban,
setIssueViewToList,
}} }}
> >
<ToastAlert /> <ToastAlert />

View File

@ -10,7 +10,6 @@ import type { IIssue } from "types";
const useIssuesFilter = (projectIssues: IIssue[]) => { const useIssuesFilter = (projectIssues: IIssue[]) => {
const { const {
issueView, issueView,
setIssueView,
groupByProperty, groupByProperty,
setGroupByProperty, setGroupByProperty,
orderBy, orderBy,
@ -19,6 +18,8 @@ const useIssuesFilter = (projectIssues: IIssue[]) => {
setFilterIssue, setFilterIssue,
resetFilterToDefault, resetFilterToDefault,
setNewFilterDefaultView, setNewFilterDefaultView,
setIssueViewToKanban,
setIssueViewToList,
} = useTheme(); } = useTheme();
const { states } = useUser(); const { states } = useUser();
@ -90,7 +91,6 @@ const useIssuesFilter = (projectIssues: IIssue[]) => {
return { return {
groupedByIssues, groupedByIssues,
issueView, issueView,
setIssueView,
groupByProperty, groupByProperty,
setGroupByProperty, setGroupByProperty,
orderBy, orderBy,
@ -99,6 +99,8 @@ const useIssuesFilter = (projectIssues: IIssue[]) => {
setFilterIssue, setFilterIssue,
resetFilterToDefault, resetFilterToDefault,
setNewFilterDefaultView, setNewFilterDefaultView,
setIssueViewToKanban,
setIssueViewToList,
} as const; } as const;
}; };

View File

@ -126,7 +126,6 @@ const SingleCycle: React.FC = () => {
const { const {
issueView, issueView,
setIssueView,
groupByProperty, groupByProperty,
setGroupByProperty, setGroupByProperty,
groupedByIssues, groupedByIssues,
@ -134,6 +133,8 @@ const SingleCycle: React.FC = () => {
setFilterIssue, setFilterIssue,
orderBy, orderBy,
filterIssue, filterIssue,
setIssueViewToKanban,
setIssueViewToList,
} = useIssuesFilter(cycleIssuesArray ?? []); } = useIssuesFilter(cycleIssuesArray ?? []);
const openCreateIssueModal = ( const openCreateIssueModal = (
@ -269,10 +270,7 @@ const SingleCycle: React.FC = () => {
className={`h-7 w-7 p-1 grid place-items-center rounded hover:bg-gray-200 duration-300 outline-none ${ className={`h-7 w-7 p-1 grid place-items-center rounded hover:bg-gray-200 duration-300 outline-none ${
issueView === "list" ? "bg-gray-200" : "" issueView === "list" ? "bg-gray-200" : ""
}`} }`}
onClick={() => { onClick={() => setIssueViewToList()}
setIssueView("list");
setGroupByProperty(null);
}}
> >
<ListBulletIcon className="h-4 w-4" /> <ListBulletIcon className="h-4 w-4" />
</button> </button>
@ -281,10 +279,7 @@ const SingleCycle: React.FC = () => {
className={`h-7 w-7 p-1 grid place-items-center rounded hover:bg-gray-200 duration-300 outline-none ${ className={`h-7 w-7 p-1 grid place-items-center rounded hover:bg-gray-200 duration-300 outline-none ${
issueView === "kanban" ? "bg-gray-200" : "" issueView === "kanban" ? "bg-gray-200" : ""
}`} }`}
onClick={() => { onClick={() => setIssueViewToKanban()}
setIssueView("kanban");
setGroupByProperty("state_detail.name");
}}
> >
<Squares2X2Icon className="h-4 w-4" /> <Squares2X2Icon className="h-4 w-4" />
</button> </button>

View File

@ -134,7 +134,6 @@ const ProjectIssues: NextPage = () => {
const { const {
issueView, issueView,
setIssueView,
groupByProperty, groupByProperty,
setGroupByProperty, setGroupByProperty,
groupedByIssues, groupedByIssues,
@ -144,6 +143,8 @@ const ProjectIssues: NextPage = () => {
filterIssue, filterIssue,
resetFilterToDefault, resetFilterToDefault,
setNewFilterDefaultView, setNewFilterDefaultView,
setIssueViewToKanban,
setIssueViewToList,
} = useIssuesFilter(projectIssues?.results.filter((p) => p.parent === null) ?? []); } = useIssuesFilter(projectIssues?.results.filter((p) => p.parent === null) ?? []);
useEffect(() => { useEffect(() => {
@ -171,10 +172,7 @@ const ProjectIssues: NextPage = () => {
className={`h-7 w-7 p-1 grid place-items-center rounded hover:bg-gray-200 duration-300 outline-none ${ className={`h-7 w-7 p-1 grid place-items-center rounded hover:bg-gray-200 duration-300 outline-none ${
issueView === "list" ? "bg-gray-200" : "" issueView === "list" ? "bg-gray-200" : ""
}`} }`}
onClick={() => { onClick={() => setIssueViewToList()}
setIssueView("list");
setGroupByProperty(null);
}}
> >
<ListBulletIcon className="h-4 w-4" /> <ListBulletIcon className="h-4 w-4" />
</button> </button>
@ -183,10 +181,7 @@ const ProjectIssues: NextPage = () => {
className={`h-7 w-7 p-1 grid place-items-center rounded hover:bg-gray-200 duration-300 outline-none ${ className={`h-7 w-7 p-1 grid place-items-center rounded hover:bg-gray-200 duration-300 outline-none ${
issueView === "kanban" ? "bg-gray-200" : "" issueView === "kanban" ? "bg-gray-200" : ""
}`} }`}
onClick={() => { onClick={() => setIssueViewToKanban()}
setIssueView("kanban");
setGroupByProperty("state_detail.name");
}}
> >
<Squares2X2Icon className="h-4 w-4" /> <Squares2X2Icon className="h-4 w-4" />
</button> </button>