Skip to content

Commit

Permalink
adding TODO and logic to take another photo immediately(?) if no person
Browse files Browse the repository at this point in the history
  • Loading branch information
natapokie committed Aug 30, 2024
1 parent 616f5fe commit e612e43
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
17 changes: 12 additions & 5 deletions client/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const Home = () => {
const intervalRef = useRef<ReturnType<typeof setTimeout> | null>(null); // test timer

// state to determine if we're displaying stuff (true) or not (false)
const [display, setDisplay] = useState<ResponseData | void>();
const [display, setDisplay] = useState<ResponseData | string | void>();
const [finalLikes, setFinalLikes] = useState<number>(0);

// state variables to indicate completed animations
Expand All @@ -24,11 +24,18 @@ const Home = () => {
console.log(`Connected with socket ${socket.id} on server ${process.env.SERVER_BASE_URL}`);
};

const onApiResonse = (data: ResponseData) => {
const onApiResonse = (data: ResponseData | string) => {
console.log('Received api response from socket');
setDisplay(data);
if (data.likes !== undefined) {
setFinalLikes(data.likes);

if (typeof data === 'string') {
// when data is a string (i.e., person not found), take a new photo
console.error(data);
takePhoto();
} else {
setDisplay(data);
if (data.likes !== undefined) {
setFinalLikes(data.likes);
}
}
};

Expand Down
3 changes: 2 additions & 1 deletion server/src/sockets/SocketManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ export class SocketManager {
// Parse the response data and emit event to all connected sockets
if (data.errorMsg) {
this.io.emit('err_msg', data.errorMsg);
// TODO: make person not found into a constant in /shared
} else if (data?.apiResponse === 'Person not found!') {
this.io.emit('api_response', 'Person not found!');
this.io.emit('api_response', data.apiResponse);
} else if (data?.apiResponse) {
const parsedResponse = parseResponse(data.apiResponse);
console.log('Received API Response and parsed');
Expand Down

0 comments on commit e612e43

Please sign in to comment.