Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
yaodingyd committed Jun 9, 2024
1 parent f713d4d commit 8a68fea
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
7 changes: 7 additions & 0 deletions src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ export function checkRoutesData() {
export function checkLastRoutesData() {
return (dispatch, getState) => {
const limit = getState().limit
const routes = getState().routes

// if current routes are not a multiple of LIMIT_INCREMENT, that means the last fetch already fetched all the routes
if (routes && routes.length % LIMIT_INCREMENT !== 0) {
return
}

console.log(`fetching ${limit +LIMIT_INCREMENT } routes`)
dispatch({
type: Types.ACTION_UPDATE_ROUTE_LIMIT,
Expand Down
2 changes: 1 addition & 1 deletion src/actions/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async function initDevices() {
export default function init() {
return async (dispatch, getState) => {
let state = getState();
if (state.dongleId) {
if (state.dongleId && !state.routes) {
dispatch(checkLastRoutesData());
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/Dashboard/DriveList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ const DriveList = (props) => {
content = (
<div className={`${classes.drives} DriveList`}>
{displayRoutes.map((drive, index) => {
// when the second to last item is in view, we fetch the next routes
return (index === routesSize - 2 ?
// when the last item is in view, we fetch the next routes
return (index === routesSize - 1 ?
<ScrollIntoView key={drive.fullname} onInView={() => dispatch(checkLastRoutesData())}>
<DriveListItem drive={drive} />
</ScrollIntoView> :
Expand Down
10 changes: 8 additions & 2 deletions src/components/DeviceInfo/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as Sentry from '@sentry/react';
import dayjs from 'dayjs';

import { withStyles, Typography, Button, CircularProgress, Popper, Tooltip } from '@material-ui/core';
import AccessTime from '@material-ui/icons/AccessTime';

import { athena as Athena, devices as Devices } from '@commaai/api';
import { analyticsEvent } from '../../actions';
Expand Down Expand Up @@ -110,6 +111,11 @@ const styles = (theme) => ({
padding: '5px 10px',
borderRadius: 15,
},
actionButtonIcon: {
minWidth: 60,
padding: '8px 16px',
borderRadius: 15,
},
snapshotContainer: {
borderBottom: `1px solid ${Colors.white10}`,
},
Expand Down Expand Up @@ -525,10 +531,10 @@ class DeviceInfo extends Component {
: 'take snapshot'}
</Button>
<Button
classes={{ root: `${classes.button} ${actionButtonClass}` }}
classes={{ root: `${classes.button} ${classes.actionButtonIcon}` }}
onClick={ this.onOpenTimeSelect }
>
set time filter
<AccessTime fontSize="inherit"/>
</Button>
<Popper
className={ classes.popover }
Expand Down
10 changes: 6 additions & 4 deletions src/components/explorer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class ExplorerApp extends Component {
}

componentDidUpdate(prevProps, prevState) {
const { pathname, zoom, dongleId } = this.props;
const { pathname, zoom, dongleId, limit } = this.props;

if (prevProps.pathname !== pathname) {
this.setState({ drawerIsOpen: false });
Expand All @@ -149,9 +149,10 @@ class ExplorerApp extends Component {
this.props.dispatch(pause());
}

if (prevProps.dongleId !== dongleId) {
const d = new Date();
d.setHours(d.getHours() + 1, 0, 0, 0);
// this is necessary when user goes to explorer for the first time, dongleId is not populated in state yet
// so init() will not successfully fetch routes data
// when checkLastRoutesData is called within init(), it would set limit so we don't need to check again
if (prevProps.dongleId !== dongleId && limit === 0) {
this.props.dispatch(checkLastRoutesData());
}
}
Expand Down Expand Up @@ -255,6 +256,7 @@ const stateToProps = Obstruction({
pathname: 'router.location.pathname',
dongleId: 'dongleId',
devices: 'devices',
limit: 'limit',
});

export default connect(stateToProps)(withStyles(styles)(ExplorerApp));

0 comments on commit 8a68fea

Please sign in to comment.