-
Notifications
You must be signed in to change notification settings - Fork 78
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
Fix mobile location tab #1106
base: main
Are you sure you want to change the base?
Fix mobile location tab #1106
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
import { Box } from '@mui/material'; | ||
import { useMediaQuery } from '@mui/material'; | ||
import { WebsocSectionMeeting } from '@packages/antalmanac-types'; | ||
import { Fragment, useCallback } from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
import { MOBILE_BREAKPOINT } from '../../../../../globals'; | ||
import MapLink from '../../../../buttons/MapLink'; | ||
|
||
import { TableBodyCellContainer } from '$components/RightPane/SectionTable/SectionTableBody/SectionTableBodyCells/TableBodyCellContainer'; | ||
import locationIds from '$lib/location_ids'; | ||
|
@@ -16,9 +19,10 @@ interface LocationsCellProps { | |
export const LocationsCell = ({ meetings }: LocationsCellProps) => { | ||
const isDark = useThemeStore((store) => store.isDark); | ||
const { setActiveTab } = useTabStore(); | ||
const isMobileScreen = useMediaQuery(`(max-width: ${MOBILE_BREAKPOINT})`); | ||
|
||
const focusMap = useCallback(() => { | ||
setActiveTab(2); | ||
setActiveTab(isMobileScreen ? 3 : 2); | ||
}, [setActiveTab]); | ||
|
||
return ( | ||
|
@@ -30,16 +34,12 @@ export const LocationsCell = ({ meetings }: LocationsCellProps) => { | |
const buildingId = locationIds[buildingName]; | ||
return ( | ||
<Fragment key={meeting.timeIsTBA + bldg}> | ||
<Link | ||
style={{ | ||
textDecoration: 'none', | ||
}} | ||
to={`/map?location=${buildingId}`} | ||
onClick={focusMap} | ||
color={isDark ? 'dodgerblue' : 'blue'} | ||
> | ||
{bldg} | ||
</Link> | ||
<MapLink | ||
buildingId={buildingId} | ||
buildingName={bldg} | ||
focusMap={focusMap} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The point to the MapLink is to move the map-focusing business logic into there so that we don't have to keep re-writing the |
||
isDark={isDark} | ||
/> | ||
<br /> | ||
</Fragment> | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
interface MapLinkProps { | ||
buildingId: number; | ||
buildingName: string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a misnomer, since it has both the building and the room number |
||
focusMap: () => void; | ||
isDark: boolean; | ||
} | ||
|
||
const MapLink: React.FC<MapLinkProps> = ({ buildingId, buildingName, focusMap, isDark }) => { | ||
return ( | ||
<Link | ||
to={`/map?location=${buildingId}`} | ||
onClick={focusMap} | ||
style={{ | ||
textDecoration: 'none', | ||
color: isDark ? 'dodgerblue' : 'blue', | ||
}} | ||
> | ||
{buildingName} | ||
</Link> | ||
); | ||
}; | ||
|
||
export default MapLink; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you need to add the
isMobileScreen
to theuseCallback
's dependency array to allow this fix to work when the screen is resized.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in putting the
isMobileScreen
to theuseCallback
's dependency array causes the whole page to want to refresh for some reason, while putting it before doesn't.