Skip to content

Commit

Permalink
Periodically update the time of reference for questions
Browse files Browse the repository at this point in the history
  • Loading branch information
Isti01 committed Mar 18, 2024
1 parent 155d7b1 commit 0a48220
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/components/tiles/question-tile.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
'use client';
import { useEffect, useState } from 'react';

import { PresentationWithDates } from '@/models/models';

import { PresentationTile } from '../presentation/PresentationGrid';
Expand All @@ -11,8 +13,14 @@ type Props = {
const MARGIN_MINUTES = 10;

export function RoomQuestion({ presentations, room, delay }: Props) {
const now = new Date();
now.setMinutes(now.getMinutes() - delay);
const [now, setNow] = useState(new Date(0));

useEffect(() => {
setNow(getNow(delay));
const id = setInterval(() => setNow(getNow(delay)), 30000);
return () => clearInterval(id);
}, []);

const presentationInRoom = presentations.filter((p) => {
const endDateWithMargin = new Date(p.endDate);
endDateWithMargin.setMinutes(endDateWithMargin.getMinutes() + MARGIN_MINUTES);
Expand All @@ -30,3 +38,9 @@ export function RoomQuestion({ presentations, room, delay }: Props) {
</p>
);
}

function getNow(delay: number): Date {
const now = new Date();
now.setMinutes(now.getMinutes() - delay);
return now;
}

0 comments on commit 0a48220

Please sign in to comment.