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

Display unique devices and if they're iOS or Android #279

Merged
merged 1 commit into from
Jan 9, 2022
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
31 changes: 18 additions & 13 deletions src/components/GrowerDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,9 @@ const useStyle = makeStyles((theme) => ({
},
}));

const GrowerDetail = (props) => {
const GrowerDetail = ({ open, growerId, onClose }) => {
// console.log('render: grower detail');
const classes = useStyle();
const { growerId } = props;
const appContext = useContext(AppContext);
const growerContext = useContext(GrowerContext);
const { sendMessageFromGrower } = useContext(MessagingContext);
Expand All @@ -125,6 +124,7 @@ const GrowerDetail = (props) => {
async function loadGrowerDetail() {
if (grower && grower.id !== growerId) {
setGrower({});
setDeviceIdentifiers([]);
}
if (growerId) {
const match = await getGrower({
Expand All @@ -139,23 +139,28 @@ const GrowerDetail = (props) => {
) {
setGrowerRegistrations(null);
api.getGrowerRegistrations(growerId).then((registrations) => {
console.log('grower registrations: ', registrations);
if (registrations && registrations.length) {
const sortedRegistrations = registrations.sort((a, b) =>
const sortedReg = registrations.sort((a, b) =>
a.created_at > b.created_at ? 1 : -1
);
setGrowerRegistrations(sortedRegistrations);
setDeviceIdentifiers(
sortedRegistrations
.map((reg) => ({
const uniqueDevices = {};
const devices = sortedReg.reduce((result, reg) => {
if (!uniqueDevices[reg.device_identifier]) {
uniqueDevices[reg.device_identifier] = true;
// if manufacturer isn't 'apple' it's an android phone
result.push({
id: reg.device_identifier,
os:
reg.manufacturer.toLowerCase() === 'apple'
? 'iOS'
: 'Android',
}))
.filter((id) => id)
);
});
}
return result;
}, []);

setDeviceIdentifiers(devices);
setGrowerRegistrations(sortedReg);
}
});
}
Expand Down Expand Up @@ -225,7 +230,7 @@ const GrowerDetail = (props) => {

return (
<>
<Drawer anchor="right" open={props.open} onClose={props.onClose}>
<Drawer anchor="right" open={open} onClose={onClose}>
<Grid
style={{
width: GROWER_IMAGE_SIZE,
Expand All @@ -242,7 +247,7 @@ const GrowerDetail = (props) => {
</Box>
</Grid>
<Grid item>
<IconButton onClick={() => props.onClose()}>
<IconButton onClick={() => onClose()}>
<Close />
</IconButton>
</Grid>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Routers.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import ReportingCard6 from './reportingCards/ReportingCard6';
export default function Routers() {
const refContainer = useRef();
const appContext = useContext(AppContext);
const { search } = useLocation();

return useMemo(() => {
return (
Expand Down Expand Up @@ -78,11 +79,10 @@ export default function Routers() {
}
key={`route_${idx}`}
/>
),
)
)}
<Route path="/reporting">
{(() => {
const { search } = useLocation();
const queryParams = new URLSearchParams(search);
const props = {
startDate: queryParams.get('start-date'),
Expand Down
9 changes: 6 additions & 3 deletions src/components/common/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ export default function GSMenu(props) {
.filter(({ disabled }) => !disabled)
.map((item, i) =>
item?.children ? (
<div className={classes.menuItemWithChildren}>
<div
key={`${item}-${i}`}
className={classes.menuItemWithChildren}
>
<Typography className={classes.menuTitle}>
{item.name}
</Typography>
Expand Down Expand Up @@ -144,9 +147,9 @@ export default function GSMenu(props) {
</Grid>
</MenuItem>
</Link>
),
)
),
[appContext.routes, props.active, classes],
[appContext.routes, props.active, classes]
)}
</>
);
Expand Down