refactor: removed unnecessary view context
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
|
import { FC } from "react";
|
||||||
import { IconEdit, IconFilter, IconPlus } from "@tabler/icons-react";
|
import { IconEdit, IconFilter, IconPlus } from "@tabler/icons-react";
|
||||||
import { Flex, Group, Indicator } from "@mantine/core";
|
import { Flex, Group, Indicator } from "@mantine/core";
|
||||||
import { modals } from "@mantine/modals";
|
import { modals } from "@mantine/modals";
|
||||||
@ -7,15 +8,20 @@ import ToolPanelAction from "@/app/deals/components/desktop/ToolPanelAction/Tool
|
|||||||
import ViewSelector from "@/app/deals/components/desktop/ViewSelector/ViewSelector";
|
import ViewSelector from "@/app/deals/components/desktop/ViewSelector/ViewSelector";
|
||||||
import { useDealsContext } from "@/app/deals/contexts/DealsContext";
|
import { useDealsContext } from "@/app/deals/contexts/DealsContext";
|
||||||
import { useProjectsContext } from "@/app/deals/contexts/ProjectsContext";
|
import { useProjectsContext } from "@/app/deals/contexts/ProjectsContext";
|
||||||
import { useViewContext } from "@/app/deals/contexts/ViewContext";
|
|
||||||
import DealsTableFiltersModal from "@/app/deals/modals/DealsTableFiltersModal/DealsTableFiltersModal";
|
import DealsTableFiltersModal from "@/app/deals/modals/DealsTableFiltersModal/DealsTableFiltersModal";
|
||||||
import ProjectSelect from "@/components/selects/ProjectSelect/ProjectSelect";
|
import ProjectSelect from "@/components/selects/ProjectSelect/ProjectSelect";
|
||||||
import { useDrawersContext } from "@/drawers/DrawersContext";
|
import { useDrawersContext } from "@/drawers/DrawersContext";
|
||||||
import useIsMobile from "@/hooks/utils/useIsMobile";
|
import useIsMobile from "@/hooks/utils/useIsMobile";
|
||||||
|
|
||||||
const TopToolPanel = () => {
|
export type View = "board" | "table" | "schedule";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
view: View;
|
||||||
|
setView: (view: View) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
const TopToolPanel: FC<Props> = ({ view, setView }) => {
|
||||||
const { dealsFiltersForm, isChangedFilters } = useDealsContext();
|
const { dealsFiltersForm, isChangedFilters } = useDealsContext();
|
||||||
const { view } = useViewContext();
|
|
||||||
const { projects, setSelectedProjectId, selectedProject, projectsCrud } =
|
const { projects, setSelectedProjectId, selectedProject, projectsCrud } =
|
||||||
useProjectsContext();
|
useProjectsContext();
|
||||||
const { openDrawer } = useDrawersContext();
|
const { openDrawer } = useDrawersContext();
|
||||||
@ -45,7 +51,10 @@ const TopToolPanel = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Group justify={"space-between"}>
|
<Group justify={"space-between"}>
|
||||||
<ViewSelector />
|
<ViewSelector
|
||||||
|
value={view}
|
||||||
|
onChange={setView}
|
||||||
|
/>
|
||||||
<Flex
|
<Flex
|
||||||
wrap={"nowrap"}
|
wrap={"nowrap"}
|
||||||
align={"center"}
|
align={"center"}
|
||||||
|
|||||||
@ -2,27 +2,26 @@
|
|||||||
|
|
||||||
import { FC, PropsWithChildren } from "react";
|
import { FC, PropsWithChildren } from "react";
|
||||||
import { Button } from "@mantine/core";
|
import { Button } from "@mantine/core";
|
||||||
import { useViewContext, View } from "@/app/deals/contexts/ViewContext";
|
|
||||||
import SmallPageBlock from "@/components/layout/SmallPageBlock/SmallPageBlock";
|
import SmallPageBlock from "@/components/layout/SmallPageBlock/SmallPageBlock";
|
||||||
import style from "./ViewSelectButton.module.css";
|
import style from "./ViewSelectButton.module.css";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
viewName: View;
|
selected: boolean;
|
||||||
|
onSelect: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const ViewSelectButton: FC<PropsWithChildren<Props>> = ({
|
const ViewSelectButton: FC<PropsWithChildren<Props>> = ({
|
||||||
viewName,
|
selected,
|
||||||
|
onSelect,
|
||||||
children,
|
children,
|
||||||
}) => {
|
}) => {
|
||||||
const { view, setView } = useViewContext();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SmallPageBlock
|
<SmallPageBlock
|
||||||
active={view === viewName}
|
active={selected}
|
||||||
style={{ borderRadius: "var(--mantine-radius-xl)" }}>
|
style={{ borderRadius: "var(--mantine-radius-xl)" }}>
|
||||||
<Button
|
<Button
|
||||||
unstyled
|
unstyled
|
||||||
onClick={() => setView(viewName)}
|
onClick={onSelect}
|
||||||
radius="xl"
|
radius="xl"
|
||||||
className={style.container}>
|
className={style.container}>
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
@ -1,23 +1,44 @@
|
|||||||
|
import { FC } from "react";
|
||||||
import {
|
import {
|
||||||
IconCalendarWeekFilled,
|
IconCalendarWeekFilled,
|
||||||
IconLayoutDashboard,
|
IconLayoutDashboard,
|
||||||
IconMenu2,
|
IconMenu2,
|
||||||
} from "@tabler/icons-react";
|
} from "@tabler/icons-react";
|
||||||
import { Group } from "@mantine/core";
|
import { Group } from "@mantine/core";
|
||||||
|
import { View } from "@/app/deals/components/desktop/TopToolPanel/TopToolPanel";
|
||||||
import ViewSelectButton from "@/app/deals/components/desktop/ViewSelectButton/ViewSelectButton";
|
import ViewSelectButton from "@/app/deals/components/desktop/ViewSelectButton/ViewSelectButton";
|
||||||
|
|
||||||
const ViewSelector = () => {
|
type Props = {
|
||||||
|
value: View;
|
||||||
|
onChange: (view: View) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
const ViewSelector: FC<Props> = ({ value, onChange }) => {
|
||||||
|
const views = [
|
||||||
|
{
|
||||||
|
value: "board" as View,
|
||||||
|
icon: <IconLayoutDashboard />,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: "table" as View,
|
||||||
|
icon: <IconMenu2 />,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: "schedule" as View,
|
||||||
|
icon: <IconCalendarWeekFilled />,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Group>
|
<Group>
|
||||||
<ViewSelectButton viewName={"board"}>
|
{views.map(view => (
|
||||||
<IconLayoutDashboard />
|
<ViewSelectButton
|
||||||
</ViewSelectButton>
|
key={view.value}
|
||||||
<ViewSelectButton viewName={"table"}>
|
selected={value === view.value}
|
||||||
<IconMenu2 />
|
onSelect={() => onChange(view.value)}>
|
||||||
</ViewSelectButton>
|
{view.icon}
|
||||||
<ViewSelectButton viewName={"schedule"}>
|
</ViewSelectButton>
|
||||||
<IconCalendarWeekFilled />
|
))}
|
||||||
</ViewSelectButton>
|
|
||||||
</Group>
|
</Group>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,36 +1,22 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { Space } from "@mantine/core";
|
import { useState } from "react";
|
||||||
import TopToolPanel from "@/app/deals/components/desktop/TopToolPanel/TopToolPanel";
|
import TopToolPanel, {
|
||||||
import MainBlockHeader from "@/app/deals/components/mobile/MainBlockHeader/MainBlockHeader";
|
View,
|
||||||
import Funnel from "@/app/deals/components/shared/Funnel/Funnel";
|
} from "@/app/deals/components/desktop/TopToolPanel/TopToolPanel";
|
||||||
|
import {
|
||||||
|
BoardView,
|
||||||
|
ScheduleView,
|
||||||
|
TableView,
|
||||||
|
} from "@/app/deals/components/shared/views";
|
||||||
import { useBoardsContext } from "@/app/deals/contexts/BoardsContext";
|
import { useBoardsContext } from "@/app/deals/contexts/BoardsContext";
|
||||||
import { DealsContextProvider } from "@/app/deals/contexts/DealsContext";
|
import { DealsContextProvider } from "@/app/deals/contexts/DealsContext";
|
||||||
import { useProjectsContext } from "@/app/deals/contexts/ProjectsContext";
|
import { useProjectsContext } from "@/app/deals/contexts/ProjectsContext";
|
||||||
import { useViewContext } from "@/app/deals/contexts/ViewContext";
|
|
||||||
import PageBlock from "@/components/layout/PageBlock/PageBlock";
|
|
||||||
import DealsTable from "../../desktop/DealsTable/DealsTable";
|
|
||||||
|
|
||||||
const BoardView = () => (
|
|
||||||
<PageBlock>
|
|
||||||
<MainBlockHeader />
|
|
||||||
<Space h="md" />
|
|
||||||
<Funnel />
|
|
||||||
</PageBlock>
|
|
||||||
);
|
|
||||||
|
|
||||||
const TableView = () => (
|
|
||||||
<PageBlock>
|
|
||||||
<DealsTable />
|
|
||||||
</PageBlock>
|
|
||||||
);
|
|
||||||
|
|
||||||
const ScheduleView = () => <PageBlock>-</PageBlock>;
|
|
||||||
|
|
||||||
const PageBody = () => {
|
const PageBody = () => {
|
||||||
const { selectedBoard } = useBoardsContext();
|
const { selectedBoard } = useBoardsContext();
|
||||||
const { selectedProject } = useProjectsContext();
|
const { selectedProject } = useProjectsContext();
|
||||||
const { view } = useViewContext();
|
const [view, setView] = useState<View>("board");
|
||||||
|
|
||||||
const getViewContent = () => {
|
const getViewContent = () => {
|
||||||
switch (view) {
|
switch (view) {
|
||||||
@ -52,7 +38,10 @@ const PageBody = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<DealsContextProvider {...getContextProps()}>
|
<DealsContextProvider {...getContextProps()}>
|
||||||
<TopToolPanel />
|
<TopToolPanel
|
||||||
|
view={view}
|
||||||
|
setView={setView}
|
||||||
|
/>
|
||||||
{getViewContent()}
|
{getViewContent()}
|
||||||
</DealsContextProvider>
|
</DealsContextProvider>
|
||||||
);
|
);
|
||||||
|
|||||||
12
src/app/deals/components/shared/views/BoardView.tsx
Normal file
12
src/app/deals/components/shared/views/BoardView.tsx
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import { Space } from "@mantine/core";
|
||||||
|
import MainBlockHeader from "@/app/deals/components/mobile/MainBlockHeader/MainBlockHeader";
|
||||||
|
import Funnel from "@/app/deals/components/shared/Funnel/Funnel";
|
||||||
|
import PageBlock from "@/components/layout/PageBlock/PageBlock";
|
||||||
|
|
||||||
|
export const BoardView = () => (
|
||||||
|
<PageBlock>
|
||||||
|
<MainBlockHeader />
|
||||||
|
<Space h="md" />
|
||||||
|
<Funnel />
|
||||||
|
</PageBlock>
|
||||||
|
);
|
||||||
5
src/app/deals/components/shared/views/ScheduleView.tsx
Normal file
5
src/app/deals/components/shared/views/ScheduleView.tsx
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import PageBlock from "@/components/layout/PageBlock/PageBlock";
|
||||||
|
|
||||||
|
export const ScheduleView = () => {
|
||||||
|
return <PageBlock>-</PageBlock>;
|
||||||
|
};
|
||||||
8
src/app/deals/components/shared/views/TableView.tsx
Normal file
8
src/app/deals/components/shared/views/TableView.tsx
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import DealsTable from "@/app/deals/components/desktop/DealsTable/DealsTable";
|
||||||
|
import PageBlock from "@/components/layout/PageBlock/PageBlock";
|
||||||
|
|
||||||
|
export const TableView = () => (
|
||||||
|
<PageBlock>
|
||||||
|
<DealsTable />
|
||||||
|
</PageBlock>
|
||||||
|
);
|
||||||
3
src/app/deals/components/shared/views/index.ts
Normal file
3
src/app/deals/components/shared/views/index.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export { BoardView } from "./BoardView";
|
||||||
|
export { TableView } from "./TableView";
|
||||||
|
export { ScheduleView } from "./ScheduleView";
|
||||||
@ -1,23 +0,0 @@
|
|||||||
"use client";
|
|
||||||
|
|
||||||
import { useState } from "react";
|
|
||||||
import makeContext from "@/lib/contextFactory/contextFactory";
|
|
||||||
|
|
||||||
export type View = "board" | "table" | "schedule";
|
|
||||||
|
|
||||||
type ViewContextState = {
|
|
||||||
view: View;
|
|
||||||
setView: (view: View) => void;
|
|
||||||
};
|
|
||||||
|
|
||||||
const useViewContextState = (): ViewContextState => {
|
|
||||||
const [view, setView] = useState<View>("board");
|
|
||||||
|
|
||||||
return {
|
|
||||||
view,
|
|
||||||
setView,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export const [ViewContextProvider, useViewContext] =
|
|
||||||
makeContext<ViewContextState>(useViewContextState, "View");
|
|
||||||
@ -9,7 +9,6 @@ import PageBody from "@/app/deals/components/shared/PageBody/PageBody";
|
|||||||
import { BoardsContextProvider } from "@/app/deals/contexts/BoardsContext";
|
import { BoardsContextProvider } from "@/app/deals/contexts/BoardsContext";
|
||||||
import { ProjectsContextProvider } from "@/app/deals/contexts/ProjectsContext";
|
import { ProjectsContextProvider } from "@/app/deals/contexts/ProjectsContext";
|
||||||
import { StatusesContextProvider } from "@/app/deals/contexts/StatusesContext";
|
import { StatusesContextProvider } from "@/app/deals/contexts/StatusesContext";
|
||||||
import { ViewContextProvider } from "@/app/deals/contexts/ViewContext";
|
|
||||||
import PageContainer from "@/components/layout/PageContainer/PageContainer";
|
import PageContainer from "@/components/layout/PageContainer/PageContainer";
|
||||||
import {
|
import {
|
||||||
getBoardsOptions,
|
getBoardsOptions,
|
||||||
@ -38,8 +37,7 @@ export default async function DealsPage() {
|
|||||||
[HydrationBoundary, { state: dehydrate(queryClient) }],
|
[HydrationBoundary, { state: dehydrate(queryClient) }],
|
||||||
[ProjectsContextProvider],
|
[ProjectsContextProvider],
|
||||||
[BoardsContextProvider],
|
[BoardsContextProvider],
|
||||||
[StatusesContextProvider],
|
[StatusesContextProvider]
|
||||||
[ViewContextProvider]
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user