@@ -6,19 +6,23 @@ import {
66 Flex ,
77 FlexItem ,
88 MenuToggle ,
9+ Modal ,
910 Switch ,
11+ Tooltip ,
1012} from "@patternfly/react-core" ;
13+ import { BarsIcon } from "@patternfly/react-icons" ; // Add a tools icon
1114import { useQueryClient } from "@tanstack/react-query" ;
12- import * as React from "react" ;
15+ import React from "react" ;
1316import { useCookies } from "react-cookie" ;
17+ import { useMediaQuery } from "react-responsive" ;
1418import { useLocation , useNavigate } from "react-router" ;
1519import ChrisAPIClient from "../../api/chrisapiclient" ;
20+ import { clearCartOnLogout } from "../../store/cart/cartSlice" ;
1621import { useAppDispatch , useAppSelector } from "../../store/hooks" ;
1722import { setLogoutSuccess } from "../../store/user/userSlice" ;
1823import { ThemeContext } from "../DarkTheme/useTheme" ;
1924import FeedDetails from "../FeedDetails" ;
2025import CartNotify from "./CartNotify" ;
21- import { clearCartOnLogout } from "../../store/cart/cartSlice" ;
2226
2327type ToolbarComponentProps = {
2428 showToolbar : boolean ;
@@ -29,6 +33,8 @@ type ToolbarComponentProps = {
2933const ToolbarComponent : React . FC < ToolbarComponentProps > = (
3034 props : ToolbarComponentProps ,
3135) => {
36+ const isSmallerScreen = useMediaQuery ( { maxWidth : 1224 } ) ;
37+
3238 const { token, titleComponent } = props ;
3339 const dispatch = useAppDispatch ( ) ;
3440 const navigate = useNavigate ( ) ;
@@ -38,6 +44,7 @@ const ToolbarComponent: React.FC<ToolbarComponentProps> = (
3844 const queryClient = useQueryClient ( ) ;
3945 const username = useAppSelector ( ( state ) => state . user . username ) ;
4046 const [ dropdownOpen , setIsDropdownOpen ] = React . useState ( false ) ;
47+ const [ trayOpen , setTrayOpen ] = React . useState ( false ) ; // State for tray visibility
4148
4249 const handleChange = ( ) => {
4350 toggleTheme ( ) ;
@@ -81,78 +88,103 @@ const ToolbarComponent: React.FC<ToolbarComponentProps> = (
8188 </ DropdownItem > ,
8289 ] ;
8390
91+ const toggleTray = ( ) => {
92+ setTrayOpen ( ! trayOpen ) ;
93+ } ;
94+
8495 return (
85- < Flex
86- justifyContent = { { default : "justifyContentSpaceBetween" } }
87- alignItems = { { default : "alignItemsCenter" } }
88- style = { {
89- width : "100%" ,
90- } }
91- >
92- < FlexItem > { titleComponent && titleComponent } </ FlexItem >
93- { /* Center */ }
94- < FlexItem flex = { { default : "flex_1" } } >
95- { props . showToolbar && < FeedDetails /> }
96- </ FlexItem >
96+ < >
97+ < Flex
98+ justifyContent = { { default : "justifyContentSpaceBetween" } }
99+ alignItems = { { default : "alignItemsCenter" } }
100+ style = { {
101+ width : "100%" ,
102+ } }
103+ >
104+ < FlexItem > { titleComponent && titleComponent } </ FlexItem >
105+ { /* Center */ }
106+ < FlexItem flex = { { default : "flex_1" } } >
107+ { props . showToolbar && ! isSmallerScreen && < FeedDetails /> }
108+ </ FlexItem >
97109
98- { /* Right section */ }
99- < FlexItem align = { { default : "alignRight" } } >
100- < Flex
101- alignItems = { { default : "alignItemsCenter" } }
102- spaceItems = { { default : "spaceItemsMd" } }
103- >
104- < FlexItem >
105- < CartNotify />
106- </ FlexItem >
107- < FlexItem >
108- < Switch
109- id = "simple-switch"
110- label = "Theme"
111- isChecked = { isDarkTheme }
112- onChange = { handleChange }
113- ouiaId = "Basic Switch"
114- />
115- </ FlexItem >
116- < FlexItem >
117- { token ? (
118- < Dropdown
119- isPlain
120- onSelect = { onDropdownToggle }
121- isOpen = { dropdownOpen }
122- toggle = { ( toggleRef ) => (
123- < MenuToggle ref = { toggleRef } onClick = { onDropdownToggle } >
124- { username }
125- </ MenuToggle >
126- ) }
127- >
128- < DropdownList > { userDropdownItems } </ DropdownList >
129- </ Dropdown >
130- ) : (
131- < >
132- < Button
133- style = { { padding : "0.25em" } }
134- variant = "link"
135- onClick = { ( ) => {
136- navigate (
137- `/login?redirectTo=${ location . pathname } ${ location . search } ` ,
138- ) ;
139- } }
140- >
141- Login
142- </ Button >
143- < Button
144- style = { { padding : "0.25em" } }
145- variant = "link"
146- onClick = { ( ) => navigate ( "/signup" ) }
147- >
148- Sign Up
149- </ Button >
150- </ >
110+ { /* Right section */ }
111+ < FlexItem align = { { default : "alignRight" } } >
112+ < Flex
113+ alignItems = { { default : "alignItemsCenter" } }
114+ spaceItems = { { default : "spaceItemsMd" } }
115+ >
116+ { isSmallerScreen && (
117+ < FlexItem >
118+ < Tooltip position = "bottom" content = "Configure Panels" >
119+ < Button
120+ variant = "plain"
121+ aria-label = "Tools"
122+ onClick = { toggleTray }
123+ icon = { < BarsIcon /> }
124+ />
125+ </ Tooltip >
126+ </ FlexItem >
151127 ) }
152- </ FlexItem >
153- </ Flex >
154- </ FlexItem >
155- </ Flex >
128+ < FlexItem >
129+ < CartNotify />
130+ </ FlexItem >
131+ < FlexItem >
132+ < Switch
133+ id = "simple-switch"
134+ label = "Theme"
135+ isChecked = { isDarkTheme }
136+ onChange = { handleChange }
137+ ouiaId = "Basic Switch"
138+ />
139+ </ FlexItem >
140+ < FlexItem >
141+ { token ? (
142+ < Dropdown
143+ isPlain
144+ onSelect = { onDropdownToggle }
145+ isOpen = { dropdownOpen }
146+ toggle = { ( toggleRef ) => (
147+ < MenuToggle ref = { toggleRef } onClick = { onDropdownToggle } >
148+ { username }
149+ </ MenuToggle >
150+ ) }
151+ >
152+ < DropdownList > { userDropdownItems } </ DropdownList >
153+ </ Dropdown >
154+ ) : (
155+ < >
156+ < Button
157+ style = { { padding : "0.25em" } }
158+ variant = "link"
159+ onClick = { ( ) => {
160+ navigate (
161+ `/login?redirectTo=${ location . pathname } ${ location . search } ` ,
162+ ) ;
163+ } }
164+ >
165+ Login
166+ </ Button >
167+ < Button
168+ style = { { padding : "0.25em" } }
169+ variant = "link"
170+ onClick = { ( ) => navigate ( "/signup" ) }
171+ >
172+ Sign Up
173+ </ Button >
174+ </ >
175+ ) }
176+ </ FlexItem >
177+ </ Flex >
178+ </ FlexItem >
179+ </ Flex >
180+
181+ { /* Modal tray for FeedDetails */ }
182+ { isSmallerScreen && trayOpen && (
183+ < Modal isOpen = { trayOpen } onClose = { toggleTray } title = "" variant = "small" >
184+ < FeedDetails />
185+ </ Modal >
186+ ) }
187+ </ >
156188 ) ;
157189} ;
158190
0 commit comments