Skip to content

Commit

Permalink
Removed some minor errors that cause console errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nabil-nablotech committed Jan 10, 2024
1 parent 59d3a3f commit 26de71c
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 26 deletions.
41 changes: 22 additions & 19 deletions Frontend/src/components/input/input.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* eslint-disable react/display-name */
import { Input as AntInput } from "antd";
import type { InputProps } from "antd";
import React from "react";

type PropsType = {
label: string;
Expand All @@ -8,22 +10,23 @@ type PropsType = {
} & InputProps;

/** This component renders a input field */
export const Input: React.FC<PropsType> = ({
label,
password = false,
error = undefined,
...props
}) => {
return (
<div className="py-1">
<div className={"font-bold pb-2"}>{label}</div>
{password && (
<AntInput.Password status={error ? "error" : undefined} {...props} />
)}
{!password && (
<AntInput status={error ? "error" : undefined} {...props} />
)}
{error && <p className="text-danger">{error}</p>}
</div>
);
};
export const Input = React.forwardRef<HTMLInputElement, PropsType>(
({ label, password = false, error = undefined, ...props }, ref) => {
return (
<div className="py-1">
<div className={"font-bold pb-2"}>{label}</div>
{password && (
<AntInput.Password
status={error ? "error" : undefined}
{...props}
ref={ref}
/>
)}
{!password && (
<AntInput status={error ? "error" : undefined} {...props} ref={ref} />
)}
{error && <p className="text-danger">{error}</p>}
</div>
);
}
);
6 changes: 4 additions & 2 deletions Frontend/src/components/video-recording-screen/hls-player.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// src/components/HlsPlayer.js
import React, { useEffect, useRef } from "react";
import Hls from "hls.js";
import { Camera } from "@/types";
Expand All @@ -14,7 +13,10 @@ const HlsPlayer = ({ camera }: { camera: Camera }) => {
if (Hls.isSupported()) {
const hls = new Hls({
xhrSetup: (xhr) => {
xhr.setRequestHeader("Authorization", `Bearer ${session.accessToken}`);
xhr.setRequestHeader(
"Authorization",
`Bearer ${session.accessToken}`
);
},
});
hls.loadSource(camera.url); // Replace with your HLS stream URL
Expand Down
9 changes: 8 additions & 1 deletion Frontend/src/containers/video-stream-container.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"use client";
import { useEffect } from "react";
import type { FC } from "react";
import { Tooltip } from "antd";
import { VideoRecordingScreen } from "@/components";
import { useCameraSlice } from "@/hooks";
import { cameras as camerasData } from "@/data";
import { FullscreenOutlined, FullscreenExitOutlined } from "@ant-design/icons";
import React from "react";

Expand All @@ -13,7 +15,7 @@ type PropsType = {
/* This container renders different video recording screens */
export const VideoStreamContainer: FC<PropsType> = ({ sizePerScreen = 9 }) => {
/* hooks */
const { cameras, isFullScreenGrid, toggleIsFullScreenGrid } =
const { cameras, isFullScreenGrid, toggleIsFullScreenGrid, setCameras } =
useCameraSlice();

/* event handlers */
Expand All @@ -30,6 +32,11 @@ export const VideoStreamContainer: FC<PropsType> = ({ sizePerScreen = 9 }) => {
toggleIsFullScreenGrid();
};

/* useEffect hooks */
useEffect(() => {
setCameras(camerasData);
}, []);

return (
<>
<div className="grid grid-cols-3 auto-rows-auto gap-1 items-stretch min-h-[80vh]">
Expand Down
1 change: 0 additions & 1 deletion Frontend/src/data/camera-data.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
"use client";
import { Camera } from "@/types";

export const cameras: Camera[] = [
Expand Down
6 changes: 6 additions & 0 deletions Frontend/src/hooks/use-camera-slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
selectIsFullScreenGrid,
updateCamera,
toggleIsFullScreenGrid,
setCameras,
} from "@/store";

export const useCameraSlice = () => {
Expand All @@ -19,6 +20,10 @@ export const useCameraSlice = () => {
const isFullScreenGrid: boolean = useAppSelector(selectIsFullScreenGrid);

/* redux camera state updaters */
const setCamerasState = (cameras: Camera[]) => {
dispatch(setCameras(cameras));
};

const updateCameraState = (updatedCamera: Camera) => {
dispatch(updateCamera(updatedCamera));
};
Expand All @@ -32,6 +37,7 @@ export const useCameraSlice = () => {
cameraCount: cameraCount,
activeCameraCount: activeCameraCount,
isFullScreenGrid: isFullScreenGrid,
setCameras: setCamerasState,
updateCamera: updateCameraState,
toggleIsFullScreenGrid: toggleIsFullScreenGridState,
};
Expand Down
1 change: 1 addition & 0 deletions Frontend/src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export {
selectCameraCount,
selectActiveCameraCount,
selectIsFullScreenGrid,
setCameras,
updateCamera,
toggleIsFullScreenGrid,
} from "./slices/camera-slice";
Expand Down
10 changes: 7 additions & 3 deletions Frontend/src/store/slices/camera-slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { createSlice } from "@reduxjs/toolkit";
import type { PayloadAction } from "@reduxjs/toolkit";
import type { RootState } from "../store";
import { Camera } from "@/types";
import type { Camera } from "@/types";
import { cameras } from "@/data";

// CameraSlice State type
Expand All @@ -15,7 +15,7 @@ type CameraStateType = {

// Define the initial state using that type
const initialState = {
cameras: cameras,
cameras: [],
cameraCount: 8,
activeCameraCount: 4,
isFullScreenGrid: false,
Expand All @@ -27,6 +27,9 @@ export const cameraSlice = createSlice({
initialState,
reducers: {
// Use the PayloadAction type to declare the contents of `action.payload`
setCameras: (state: CameraStateType, action: PayloadAction<Camera[]>) => {
state.cameras = [...action.payload];
},
updateCamera: (state: CameraStateType, action: PayloadAction<Camera>) => {
state.cameras = state.cameras.map((item) => {
if (item.key === action.payload.key) {
Expand All @@ -41,7 +44,8 @@ export const cameraSlice = createSlice({
},
});

export const { updateCamera, toggleIsFullScreenGrid } = cameraSlice.actions;
export const { updateCamera, toggleIsFullScreenGrid, setCameras } =
cameraSlice.actions;

// Other code such as selectors can use the imported `RootState` type
export const selectCameras = (state: RootState) => state.camera.cameras;
Expand Down

0 comments on commit 26de71c

Please sign in to comment.