ArticleMeta to capture Authors and Article created date

This commit is contained in:
2025-11-12 05:17:50 +05:30
parent 7fa61e6c2e
commit 6798b64431
5 changed files with 26 additions and 8 deletions

View File

@@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import { Typography } from '@mui/material'; import { Typography } from '@mui/material';
import { Author } from "../Author"; import { ArticleMeta } from "../ArticleMeta";
import { ArticleCardProps } from "../../types/props"; import { ArticleCardProps } from "../../types/props";
import { StyledCard, StyledCardContent, StyledTypography } from "../../types/styles"; import { StyledCard, StyledCardContent, StyledTypography } from "../../types/styles";
@@ -46,7 +46,7 @@ export default function ArticleCardSize2({
</StyledTypography> </StyledTypography>
</div> </div>
</StyledCardContent> </StyledCardContent>
<Author authors={article.authors} /> <ArticleMeta article={article} />
</StyledCard> </StyledCard>
); );
}; };

View File

@@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import { CardMedia, Typography } from '@mui/material'; import { CardMedia, Typography } from '@mui/material';
import { Author } from "../Author"; import { ArticleMeta } from "../ArticleMeta";
import { ArticleCardProps } from "../../types/props"; import { ArticleCardProps } from "../../types/props";
import { StyledCard, StyledCardContent, StyledTypography } from "../../types/styles"; import { StyledCard, StyledCardContent, StyledTypography } from "../../types/styles";
@@ -42,7 +42,7 @@ export default function ArticleCardSize4({
{article.description} {article.description}
</StyledTypography> </StyledTypography>
</StyledCardContent> </StyledCardContent>
<Author authors={article.authors} /> <ArticleMeta article={article} />
</StyledCard> </StyledCard>
); );
}; };

View File

@@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import { CardMedia, Typography } from '@mui/material'; import { CardMedia, Typography } from '@mui/material';
import { Author } from "../Author"; import { ArticleMeta } from "../ArticleMeta";
import { ArticleCardProps } from "../../types/props"; import { ArticleCardProps } from "../../types/props";
import { StyledCard, StyledCardContent, StyledTypography } from "../../types/styles"; import { StyledCard, StyledCardContent, StyledTypography } from "../../types/styles";
@@ -43,7 +43,7 @@ export default function ArticleCardSize6({
{article.description} {article.description}
</StyledTypography> </StyledTypography>
</StyledCardContent> </StyledCardContent>
<Author authors={article.authors} /> <ArticleMeta article={article} />
</StyledCard> </StyledCard>
); );
}; };

View File

@@ -3,8 +3,14 @@ import AvatarGroup from "@mui/material/AvatarGroup";
import Avatar from "@mui/material/Avatar"; import Avatar from "@mui/material/Avatar";
import {Typography} from "@mui/material"; import {Typography} from "@mui/material";
import React from "react"; import React from "react";
import { ArticleMetaProps } from "../types/props";
export function ArticleMeta({
article,
}: ArticleMetaProps ) {
const authors = article.authors;
export function Author({ authors }: { authors: { name: string; avatar: string }[] }) {
return ( return (
<Box <Box
sx={{ sx={{
@@ -33,7 +39,15 @@ export function Author({ authors }: { authors: { name: string; avatar: string }[
{authors.map((author) => author.name).join(', ')} {authors.map((author) => author.name).join(', ')}
</Typography> </Typography>
</Box> </Box>
<Typography variant="caption">July 14, 2021</Typography> <Typography variant="caption" color="text.secondary">
{new Date(article.created_at).toLocaleString('en-US', {
year: 'numeric',
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
})}
</Typography>
</Box> </Box>
); );
} }

View File

@@ -13,6 +13,10 @@ export interface ArticleProps {
onBack: () => void; onBack: () => void;
} }
export interface ArticleMetaProps {
article: ArticleModel;
}
export interface ArticleCardProps { export interface ArticleCardProps {
article: ArticleModel; article: ArticleModel;
index: number; index: number;