-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: converted files to typescript
- Removed vite-plugin-eslint because it is not maintained anymore and its typings are outdated - Added types to all files and made sure the project fully type checks
- Loading branch information
1 parent
db0a7c8
commit 08718a1
Showing
33 changed files
with
530 additions
and
519 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 was deleted.
Oops, something went wrong.
This file contains 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,52 @@ | ||
import { useEffect, useRef } from 'react'; | ||
import moment from 'moment'; | ||
import { type Activity } from '../store/api'; | ||
|
||
function sameDay(d: Date, t: Date): boolean { | ||
return d.getDate() === t.getDate() // getDate returns day number in month... | ||
&& d.getMonth() === t.getMonth() | ||
&& d.getFullYear() === t.getFullYear(); | ||
} | ||
|
||
function createFormat(has_time: boolean, date: Date, as = new Date()): string { | ||
const format = | ||
(!sameDay(date, as) ? 'dddd DD-MM ' : '') | ||
+ (has_time ? 'HH:mm' : ''); | ||
return format || '[]'; | ||
} | ||
|
||
type ActivityProps = Activity & { active: boolean }; | ||
|
||
export default function Activity({ | ||
active, name, start_date, end_date, | ||
has_start_time, has_end_time, participant_counter | ||
}: ActivityProps) { | ||
const activityRef = useRef<HTMLLIElement | null>(null); | ||
|
||
// Ensure that the current activity is visible | ||
useEffect(() => { | ||
if (active && activityRef.current) | ||
activityRef.current.scrollIntoView({ | ||
behavior: 'smooth' | ||
}); | ||
}, [active]); | ||
|
||
const startDate = moment(start_date) | ||
.format(createFormat(has_start_time, new Date(start_date))); | ||
const endDate = end_date | ||
? moment(end_date) | ||
.format(createFormat(has_end_time, new Date(end_date), new Date(start_date))) | ||
: null; | ||
const className = 'activity' + (active ? ' active' : ''); | ||
|
||
return ( | ||
<li className={className} ref={activityRef}> | ||
<h1> | ||
{name} | ||
{participant_counter && ` (${participant_counter})`} | ||
</h1> | ||
<time>{startDate}</time> | ||
{endDate && <> - <time>{endDate}</time></>} | ||
</li> | ||
); | ||
} |
This file contains 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
Oops, something went wrong.