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

Improve platform responsiveness for smaller screens #2350

Merged
merged 4 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import { checkAuthStatusService } from 'services/AuthService';
import { UnauthenticatedRoute } from 'routes/UnauthenticatedRoute/UnauthenticatedRoute';
import { AuthenticatedRoute } from 'routes/AuthenticatedRoute/AuthenticatedRoute';
import { Logout } from 'containers/Auth/Logout/Logout';
import { isGreaterThanLgBreakpoint } from 'common/utils';

const App = () => {
const navigate = useNavigate();
// by default, do not assign any value to assume login or logout
// let's checkAuthStatusService allocate it on useEffect
const [authenticated, setAuthenticated] = useState<any>();
const [drawerOpen, setDrawerOpen] = useState(window.innerWidth > 768);
const [drawerOpen, setDrawerOpen] = useState(isGreaterThanLgBreakpoint());

useEffect(() => {
setAuthenticated(checkAuthStatusService());
Expand Down
3 changes: 3 additions & 0 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,7 @@ export const getAddOrRemoveRoleIds = (roles: any, payload: any) => {
return { ...rest, addRoleIds, deleteRoleIds };
};

// lg breakpoint is 1200px for MUI
export const isGreaterThanLgBreakpoint = () => window.innerWidth > 1200;

export default getObject;
9 changes: 3 additions & 6 deletions src/components/UI/Layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ export interface LayoutProps {
}

export const Layout = ({ children }: LayoutProps) => {
const { drawerOpen, setDrawerOpen } = useContext(SideDrawerContext);
let mainStyle = styles.Main;
if (!drawerOpen) {
mainStyle = styles.MainFullWidth;
}
const { setDrawerOpen } = useContext(SideDrawerContext);

return (
<>
<SideDrawer />
<main className={mainStyle} data-testid="layout">
<main className={styles.MainFullWidth} data-testid="layout">
<div className={styles.MobileHeader}>
<img src={GlificLogo} className={styles.GlificLogo} alt="Glific" />
<span
Expand Down
14 changes: 12 additions & 2 deletions src/components/UI/Layout/Navigation/SideDrawer/SideDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import GlificLogo from 'assets/images/logo/Logo.svg';
import { getUserRolePermissions, getUserAccountMenus, getStaffManagementMenus } from 'context/role';
import { Tooltip } from 'components/UI/Tooltip/Tooltip';
import { WalletBalance } from 'containers/WalletBalance/WalletBalance';
import { isGreaterThanLgBreakpoint } from 'common/utils';
import SideMenus from '../SideMenus/SideMenus';

import styles from './SideDrawer.module.css';

export const SideDrawer = () => {
Expand Down Expand Up @@ -100,7 +102,16 @@ export const SideDrawer = () => {

return (
<nav
className={drawerOpen ? styles.Drawer : styles.NavClose}
onMouseOver={() => {
if (!isGreaterThanLgBreakpoint()) setDrawerOpen(true);
}}
onMouseLeave={() => {
if (!isGreaterThanLgBreakpoint()) setDrawerOpen(false);
}}
onFocus={() => {
if (!isGreaterThanLgBreakpoint()) setDrawerOpen(true);
}}
className={drawerOpen && isGreaterThanLgBreakpoint() ? styles.Drawer : styles.NavClose}
aria-label="navigation menus"
data-testid="navbar"
>
Expand All @@ -124,7 +135,6 @@ export const SideDrawer = () => {
</Drawer>
</Hidden>
<Drawer
className={drawerOpen ? styles.DrawerOpen : styles.DrawerClose}
classes={{
paper: drawerOpen ? styles.DrawerOpen : styles.DrawerClose,
}}
Expand Down
2 changes: 1 addition & 1 deletion src/components/UI/Pager/Pager.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
position: fixed;
display: flex !important;
justify-content: flex-end !important;
width: calc(100% - 243px);
width: 100%;
background: #f9f7f3;
bottom: 0px;
right: 4px;
Expand Down
4 changes: 2 additions & 2 deletions src/containers/List/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export const List = ({
filterItemsQuery,
{
variables: filterPayload(),
fetchPolicy: 'cache-and-network',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how this is related to responsiveness?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we are opening or closing the sideDrawer this query is getting called again if we have this fetch-policy. I have checked multiple scenarios like adding deleting or editing a list item and there are no issues caused by changing this policy.

fetchPolicy: 'cache-first',
}
);

Expand All @@ -259,7 +259,7 @@ export const List = ({

useEffect(() => {
refetchCount();
}, [filterPayload, searchVal, filters]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refetchcount was getting called even if the filterPayload and filter were not changing while closing or opening the side drawer. Removing these doesnt seem to cause any issue with the existing features.

}, [searchVal]);

useEffect(() => {
if (userRole.length === 0) {
Expand Down