Skip to content

Commit

Permalink
fix(client): add feature flag for camera preview
Browse files Browse the repository at this point in the history
  • Loading branch information
Jozwiaczek committed Sep 15, 2021
1 parent d5ad675 commit 036cef2
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 28 deletions.
4 changes: 4 additions & 0 deletions packages/client/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

# Client Config
PORT=8080
DISABLE_ESLINT_PLUGIN=true

# API
REACT_APP_API_URL=http://localhost:3030
Expand All @@ -28,3 +29,6 @@ REACT_APP_SENTRY_TRACES_SAMPLE=0
# Push notifications
# For more details check: https://github.com/web-push-libs/web-push#using-vapid-key-for-applicationserverkey
REACT_APP_PUSH_NOTIFICATION_PUBLIC_VAPID_KEY=

# Camera
REACT_APP_CAMERA_PREVIEW_ENABLED=false
26 changes: 23 additions & 3 deletions packages/client/src/pages/authorized/Dashboard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,47 @@
import React, { useEffect } from 'react';
import React, { useContext, useEffect, useMemo } from 'react';
import { useTranslation } from 'react-i18next';

import { ConnectionState } from '../../../enums/connectionState.enum';
import { DeviceStatus } from '../../../enums/deviceStatus.enum';
import { useAxios } from '../../../hooks';
import { WebSocketContext } from '../../../providers/api/WebSocketProvider/WebSocketProvider.context';
import { registerWebPush } from '../../../utils';
import { Title } from '../AuthorizedPages.styled';
import { RowSection } from './Dashboard.styled';
import CameraPreviewSection from './sections/CameraPreviewSection';
import TogglingSection from './sections/TogglingSection';
import GateDisconnected from './sections/TogglingSection/components/GateDisconnected';

const Dashboard = () => {
const { t } = useTranslation();
const axios = useAxios();
const { connectionState, deviceStatus } = useContext(WebSocketContext);

const isConnected = useMemo(
() => connectionState === ConnectionState.CONNECTED && deviceStatus === DeviceStatus.CONNECTED,
[connectionState, deviceStatus],
);

useEffect(() => {
void registerWebPush(axios);
}, [axios]);

const DeviceSections = () => (
<>
<TogglingSection />
<CameraPreviewSection />
</>
);

return (
<>
<Title data-testid="dashboard-title">{t('routes.dashboard.title')}</Title>
<RowSection>
<TogglingSection />
<CameraPreviewSection />
{isConnected ? (
<DeviceSections />
) : (
<GateDisconnected connectionState={connectionState} deviceStatus={deviceStatus} />
)}
</RowSection>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ const CameraPreviewSection = () => {
};
}, [cameraURL, reloadCameraPreview]);

if (process.env.REACT_APP_CAMERA_PREVIEW_ENABLED !== 'true') {
return null;
}

return (
<div>
{!isPreviewLoaded && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,20 @@ export const ToggleSliderWrapper = styled.div(
`,
);

export const DisconnectedContainer = styled.div`
margin-top: 36px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
`;
export const DisconnectedContainer = styled.div(
({ theme: { down, breakpoints } }) => css`
margin-top: 36px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
${down(breakpoints.sm)} {
margin-left: 50%;
transform: translateX(-50%);
}
`,
);

const wiresAnimation = keyframes`
0% {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,17 @@
import React, { useContext, useMemo } from 'react';
import React, { useContext } from 'react';

import { ToggleSlider } from '../../../../../elements';
import { ConnectionState } from '../../../../../enums/connectionState.enum';
import { DeviceStatus } from '../../../../../enums/deviceStatus.enum';
import { WebSocketContext } from '../../../../../providers/api/WebSocketProvider/WebSocketProvider.context';
import GateDisconnected from './components/GateDisconnected';
import { ToggleSliderWrapper } from './TogglingSection.styled';

const TogglingSection = () => {
const { toggleGate, connectionState, deviceStatus } = useContext(WebSocketContext);
const { toggleGate } = useContext(WebSocketContext);

const isConnected = useMemo(
() => connectionState === ConnectionState.CONNECTED && deviceStatus === DeviceStatus.CONNECTED,
[connectionState, deviceStatus],
return (
<ToggleSliderWrapper>
<ToggleSlider onToggle={toggleGate} />
</ToggleSliderWrapper>
);

if (isConnected) {
return (
<ToggleSliderWrapper>
<ToggleSlider onToggle={toggleGate} />
</ToggleSliderWrapper>
);
}

return <GateDisconnected connectionState={connectionState} deviceStatus={deviceStatus} />;
};

export default TogglingSection;

0 comments on commit 036cef2

Please sign in to comment.