-
Notifications
You must be signed in to change notification settings - Fork 868
feat(ui): add ClassRoom Timer #1288
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
Merged
Merged
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
e65ed53
feat(ui): add Countdown
Matrixbirds b38366f
fix(eslint): format
Matrixbirds 8f85130
fix(component): use date-fns in Countdown
Matrixbirds 9ae42d2
fix(component): rename Countdown to Timer
Matrixbirds b7c4f71
fix(component): useClockTick support duration
Matrixbirds 6c3b4d1
fix(component): adjust negated conditions
Matrixbirds e1726a9
fix(component): rename timer
Matrixbirds 9561c81
fix(component): remove timer in AppStoreButton
Matrixbirds 99f91e9
fix(component): format code
Matrixbirds 7441390
fix(component): rename timer
Matrixbirds fb7e29c
fix(component): timer types
Matrixbirds 4401926
Update packages/flat-components/src/components/ClassroomPage/Timer/in…
Matrixbirds f6da714
Update packages/flat-components/src/components/ClassroomPage/Timer/in…
BlackHole1 df9967f
fix(component): use NaN as initialize value to <Timer />
Matrixbirds a8fb79c
Merge remote-tracking branch 'origin' into feat_add_clock_tick
Matrixbirds ad0748d
rename
Matrixbirds de76fd2
fix(component): revert countdown code
Matrixbirds 58bf559
fix(component): revert countdown code
Matrixbirds 1efd905
refactor(component): use react schedule timing update
Matrixbirds 3b5fd43
refactor(component): fix timing
Matrixbirds 48c619b
refactor(component): format code
Matrixbirds 6bc3ea2
refactor(component): format code
Matrixbirds 48ce88f
fix(assets): style
Matrixbirds 2a7a70c
refactor(component): format code
Matrixbirds File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
packages/flat-components/src/components/ClassroomPage/Timer/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import React, { useState, useEffect, useMemo } from "react"; | ||
| import { useTranslation } from "react-i18next"; | ||
| import "./style.less"; | ||
| import { useIsUnMounted } from "../../../utils/hooks"; | ||
| import { RoomStatus } from "../../../types/room"; | ||
| import { intervalToDuration } from "date-fns/fp"; | ||
|
|
||
| export type TimerProps = { | ||
| roomStatus: RoomStatus; | ||
| beginTime: number; | ||
| }; | ||
|
|
||
| const paddingZero = (number: number): string => { | ||
| return String(number).padStart(2, "0"); | ||
| }; | ||
|
|
||
| const useClockTick = (beginTime: number, roomStatus: RoomStatus): string => { | ||
| const [timestamp, updateTimestamp] = useState<number>(Date.now()); | ||
| const unmounted = useIsUnMounted(); | ||
|
|
||
| useEffect(() => { | ||
| if (unmounted.current) { | ||
| return; | ||
| } | ||
|
|
||
| if (roomStatus === RoomStatus.Started) { | ||
| updateTimestamp(Date.now()); | ||
| } | ||
| }, [roomStatus, timestamp, unmounted]); | ||
|
|
||
| return useMemo(() => { | ||
| const { | ||
| days = 0, | ||
| hours = 0, | ||
| minutes = 0, | ||
| seconds = 0, | ||
| } = intervalToDuration({ | ||
| start: beginTime, | ||
| end: timestamp, | ||
| }); | ||
|
|
||
| const minutesAndSeconds = `${paddingZero(minutes)}:${paddingZero(seconds)}`; | ||
| const dayHours = hours + days * 24; | ||
|
|
||
| return dayHours > 0 ? `${paddingZero(dayHours)}:${minutesAndSeconds}` : minutesAndSeconds; | ||
| }, [beginTime, timestamp]); | ||
| }; | ||
|
|
||
| export const Timer: React.FC<TimerProps> = ({ roomStatus = RoomStatus.Paused, beginTime }) => { | ||
| const timing = useClockTick(beginTime, roomStatus); | ||
|
|
||
| const { t } = useTranslation(); | ||
|
|
||
| return ( | ||
| <span className="timer-bar"> | ||
| <span className={`timer-${roomStatus}`}>{t("room-started")}</span> | ||
| <span>{timing}</span> | ||
| </span> | ||
| ); | ||
| }; | ||
5 changes: 5 additions & 0 deletions
5
packages/flat-components/src/components/ClassroomPage/Timer/style.less
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| .timer-bar { | ||
| color: #7a7b7c; | ||
| font-size: 12px; | ||
| margin: 0 8px; | ||
| } |
20 changes: 20 additions & 0 deletions
20
packages/flat-components/src/components/ClassroomPage/Timer/timer.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { Meta, Story } from "@storybook/react"; | ||
| import React from "react"; | ||
| import { RoomStatus } from "../../../types/room"; | ||
| import { Timer, TimerProps } from "."; | ||
|
|
||
| const storyMeta: Meta = { | ||
| title: "ClassroomPage/Timer", | ||
| component: Timer, | ||
| }; | ||
|
|
||
| export default storyMeta; | ||
|
|
||
| export const Overview: Story<TimerProps> = args => { | ||
| return <Timer {...args} />; | ||
| }; | ||
|
|
||
| Overview.args = { | ||
| roomStatus: RoomStatus.Paused, | ||
| beginTime: Date.now(), | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.