-
Notifications
You must be signed in to change notification settings - Fork 3
[Feature] Study status changing in real time #10
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
saseungmin
merged 2 commits into
CodeSoom:main
from
saseungmin:real-time-change-study-recruit-status
Nov 20, 2020
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import React, { useState } from 'react'; | ||
|
|
||
| import styled from '@emotion/styled'; | ||
|
|
||
| import useInterval from '../../util/useInterval'; | ||
|
|
||
| import DateTimeStatus from '../../styles/DateTimeStatus'; | ||
|
|
||
| const DateTimeChangeWrapper = styled.div``; | ||
|
|
||
| const isCheckedTimeStatus = ({ | ||
| realTime, applyEndTime, participants, personnel, | ||
| }) => (!!((realTime - applyEndTime >= 0 || participants.length === personnel))); | ||
|
|
||
| const DateTimeChange = ({ group }) => { | ||
| const { participants, personnel, applyEndDate } = group; | ||
| const applyEndTime = new Date(applyEndDate).getTime(); | ||
|
|
||
| const [realTime, setRealTime] = useState(Date.now()); | ||
|
|
||
| useInterval(() => { | ||
| setRealTime(Date.now()); | ||
| }, 1000); | ||
|
|
||
| const valid = { | ||
| realTime, applyEndTime, participants, personnel, | ||
| }; | ||
|
|
||
| const timeStatusChange = () => { | ||
| if (isCheckedTimeStatus(valid)) { | ||
| return ( | ||
| <DateTimeStatus status="deadline">모집마감</DateTimeStatus> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <DateTimeStatus status="recruit">모집중</DateTimeStatus> | ||
| ); | ||
| }; | ||
|
|
||
| return ( | ||
| <DateTimeChangeWrapper> | ||
| {`모집 인원: ${participants.length} / ${personnel}`} | ||
| {timeStatusChange()} | ||
| </DateTimeChangeWrapper> | ||
| ); | ||
| }; | ||
|
|
||
| export default DateTimeChange; | ||
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,71 @@ | ||
| import React from 'react'; | ||
|
|
||
| import { render } from '@testing-library/react'; | ||
|
|
||
| import DateTimeChange from './DateTimeChange'; | ||
|
|
||
| describe('DateTimeChange', () => { | ||
| const renderDateTimeChange = ({ group }) => render(( | ||
| <DateTimeChange | ||
| group={group} | ||
| /> | ||
| )); | ||
|
|
||
| describe('current time is before the application deadline', () => { | ||
| it('renders Recruiting text', () => { | ||
| const nowDate = new Date(); | ||
| const tomorrow = nowDate.setDate(nowDate.getDate() + 1); | ||
|
|
||
| const group = { | ||
| applyEndDate: tomorrow, | ||
| participants: [ | ||
| 'user2', | ||
| ], | ||
| personnel: 2, | ||
| }; | ||
|
|
||
| const { container } = renderDateTimeChange({ group }); | ||
|
|
||
| expect(container).toHaveTextContent('모집중'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('current time is after the application deadline', () => { | ||
| it('renders Application deadline text', () => { | ||
| const nowDate = new Date(); | ||
| const yesterday = nowDate.setDate(nowDate.getDate() - 1); | ||
|
|
||
| const group = { | ||
| applyEndDate: yesterday, | ||
| participants: [ | ||
| 'user2', | ||
| ], | ||
| personnel: 2, | ||
| }; | ||
|
|
||
| const { container } = renderDateTimeChange({ group }); | ||
|
|
||
| expect(container).toHaveTextContent('모집마감'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('When the number of study group participants equals the maximum number of participants', () => { | ||
| it('renders Application deadline text', () => { | ||
| const nowDate = new Date(); | ||
| const tomorrow = nowDate.setDate(nowDate.getDate() - 1); | ||
|
|
||
| const group = { | ||
| applyEndDate: tomorrow, | ||
| participants: [ | ||
| 'user2', | ||
| 'user3', | ||
| ], | ||
| personnel: 2, | ||
| }; | ||
|
|
||
| const { container } = renderDateTimeChange({ group }); | ||
|
|
||
| expect(container).toHaveTextContent('모집마감'); | ||
| }); | ||
| }); | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import React from 'react'; | ||
|
|
||
| import styled from '@emotion/styled'; | ||
| import { css } from '@emotion/react'; | ||
|
|
||
| import palette from './palette'; | ||
|
|
||
| const DateTimeStatusWrapper = styled.div` | ||
| margin-left: 1.5rem; | ||
| font-weight: 600; | ||
| font-size: 1.1rem; | ||
| font-family: 'Gamja Flower', cursive; | ||
| padding: .1rem .5rem .1rem .5rem; | ||
| display: inline-flex; | ||
| color: white; | ||
| border-radius: 0.5rem; | ||
| margin-top: 1rem; | ||
| margin-bottom: 1rem; | ||
|
|
||
| ${(props) => props.status === 'recruit' | ||
| && css` | ||
| background: ${palette.cyan[4]}; | ||
| animation: blink-animation 1.5s steps(5, start) infinite; | ||
| -webkit-animation: blink-animation 1.5s steps(5, start) infinite; | ||
| @keyframes blink-animation { | ||
| to { | ||
| visibility: hidden; | ||
| } | ||
| } | ||
| @-webkit-keyframes blink-animation { | ||
| to { | ||
| visibility: hidden; | ||
| } | ||
| } | ||
| `} | ||
|
|
||
|
|
||
| ${(props) => props.status === 'deadline' | ||
| && css` | ||
| background: #ff6b6b; | ||
| `} | ||
| `; | ||
|
|
||
| const DateTimeStatus = ({ children, status }) => ( | ||
| <DateTimeStatusWrapper status={status}> | ||
| {children} | ||
| </DateTimeStatusWrapper> | ||
| ); | ||
|
|
||
| export default DateTimeStatus; |
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,22 @@ | ||
| import { useRef, useEffect } from 'react'; | ||
|
|
||
| const useInterval = (callback, delay) => { | ||
| const savedCallback = useRef(); | ||
|
|
||
| useEffect(() => { | ||
| savedCallback.current = callback; | ||
| }); | ||
|
|
||
| useEffect(() => { | ||
| function tick() { | ||
| savedCallback.current(); | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| // eslint-disable-next-line prefer-const | ||
| let id = setInterval(tick, delay); | ||
|
|
||
| return () => clearInterval(id); | ||
| }, [delay]); | ||
| }; | ||
|
|
||
| export default useInterval; | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useInterval에 대한 테스트를 어떻게 작성해야할까..🤔 (coverage 실패)