-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d32e26
commit 5ad819c
Showing
26 changed files
with
355 additions
and
317 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,88 @@ | ||
import React from 'react' | ||
import { Link } from 'react-router-dom' | ||
import { type Project as ProjectType } from '../models/ProjectsResponse' | ||
import ProjectRepository from '../repositories/ProjectRepository' | ||
import styles from './../style/components/Project.module.css' | ||
import { type Project as ProjectType } from '../models/ProjectsResponse' | ||
|
||
import FavoriteStar from './FavoriteStar' | ||
import { Tooltip } from '@mui/material' | ||
import FavoriteStar from './FavoriteStar' | ||
|
||
interface Props { | ||
project: ProjectType | ||
onFavoriteChanged: () => void | ||
} | ||
|
||
function timeSince(date: Date) { | ||
const seconds = Math.floor((new Date().getUTCMilliseconds() - date.getUTCMilliseconds()) / 1000); | ||
let interval = seconds / 31536000; | ||
|
||
if (interval > 1) { | ||
return Math.floor(interval) + " years"; | ||
} | ||
interval = seconds / 2592000; | ||
if (interval > 1) { | ||
return Math.floor(interval) + " months"; | ||
} | ||
interval = seconds / 86400; | ||
if (interval > 1) { | ||
return Math.floor(interval) + " days"; | ||
} | ||
interval = seconds / 3600; | ||
if (interval > 1) { | ||
return Math.floor(interval) + " hours"; | ||
} | ||
interval = seconds / 60; | ||
if (interval > 1) { | ||
return Math.floor(interval) + " minutes"; | ||
} | ||
return Math.floor(seconds) + " seconds"; | ||
} | ||
|
||
export default function Project(props: Props): JSX.Element { | ||
const latestVersion = ProjectRepository.getLatestVersion(props.project.versions) | ||
|
||
return ( | ||
<div className={styles['project-card']}> | ||
<div className={styles['project-card-header']}> | ||
<Tooltip title={props.project.name} placement="top-start" arrow> | ||
<Link to={`${props.project.name}/latest`}> | ||
{props.project.logo ? ( | ||
<> | ||
|
||
{props.project.logo ? | ||
<> | ||
<Link to={`${props.project.name}/latest`}> | ||
<img | ||
className={styles['project-logo']} | ||
src={ProjectRepository.getProjectLogoURL(props.project.name)} | ||
alt={`${props.project.name} project logo`} | ||
/> | ||
</Link> | ||
</> : <></> | ||
} | ||
|
||
<div className={styles['project-header']}> | ||
<Link to={`${props.project.name}/latest`}> | ||
<div className={styles['project-card-title']}> | ||
{props.project.name}{' '} | ||
<span className={styles['secondary-typography']}> | ||
{latestVersion.name} | ||
</span> | ||
</div> | ||
</Link> | ||
|
||
<div className={styles['project-card-title-with-logo']}> | ||
{props.project.name}{' '} | ||
<span className={styles['project-card-version']}> | ||
{ | ||
ProjectRepository.getLatestVersion(props.project.versions) | ||
.name | ||
} | ||
</span> | ||
</div> | ||
</> | ||
) : ( | ||
<div className={styles['project-card-title']}> | ||
{props.project.name}{' '} | ||
<span className={styles['project-card-version']}> | ||
{ | ||
ProjectRepository.getLatestVersion(props.project.versions) | ||
.name | ||
} | ||
</span> | ||
</div> | ||
)} | ||
</Link> | ||
<Tooltip title={new Date(latestVersion.timestamp).toISOString().slice(0, -8).replace('T', ' ')} placement="left" arrow> | ||
<div className={styles['secondary-typography']}> | ||
{timeSince(new Date(latestVersion.timestamp))} ago | ||
</div> | ||
</Tooltip> | ||
</div> | ||
<div className={styles['project-header']}> | ||
<div className={styles.subhead}> | ||
{props.project.versions.length === 1 | ||
? `${props.project.versions.length} version` | ||
: `${props.project.versions.length} versions`} | ||
</div> | ||
|
||
<FavoriteStar | ||
projectName={props.project.name} | ||
onFavoriteChanged={props.onFavoriteChanged} | ||
/> | ||
</div> | ||
<div className={styles.subhead}> | ||
{props.project.versions.length === 1 | ||
? `${props.project.versions.length} version` | ||
: `${props.project.versions.length} versions`} | ||
</div> | ||
</div> | ||
) | ||
} |
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
Oops, something went wrong.