Skip to content

Commit

Permalink
310-links-card (#342)
Browse files Browse the repository at this point in the history
* Removed old favicon, minified meta, copied in models

* Extract artifacts

* Link card and story

* Add no image story

* fix: increase height of CardMedia component to 180 in order to display images properly
  • Loading branch information
kjy5 authored Feb 13, 2024
1 parent 5247742 commit 35a6214
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 409 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dist/
.prettierrc.cjs
src/models/artifact-metas.json
408 changes: 0 additions & 408 deletions public/artifact-metas.json

This file was deleted.

1 change: 0 additions & 1 deletion public/vite.svg

This file was deleted.

22 changes: 22 additions & 0 deletions src/components/link-card.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import LinkCard from './link-card.tsx';
import { Meta, StoryObj } from '@storybook/react';
import artifactMetas from '../utils/artifact-metas.ts';

const meta: Meta<typeof LinkCard> = {
component: LinkCard,
};
export default meta;

type Story = StoryObj<typeof LinkCard>;

export const Default: Story = {
args: {
linkMeta: artifactMetas[7].links[0],
},
};

export const NoImage: Story = {
args: {
linkMeta: artifactMetas[9].links[0],
},
};
68 changes: 68 additions & 0 deletions src/components/link-card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { LinkMeta } from '../models/artifact-meta-models.ts';
import { Avatar, Card, CardActionArea, CardContent, CardMedia, Link, Stack, Typography } from '@mui/material';

/**
* Content of a link.
* @param title The title of the link.
* @param description The description of the link.
* @param faviconSrc The favicon of the link.
* @param domain The domain of the link.
* @constructor
*/
function LinkContent({
title,
description,
faviconSrc,
domain,
}: {
title: string;
description: string;
faviconSrc: string;
domain: string;
}) {
return (
<CardContent>
<Stack spacing={2}>
<Typography gutterBottom variant="h5" component="div">
{title}
</Typography>

<Typography variant="body2" color="text.secondary">
{description}
</Typography>

<Stack direction={'row'} spacing={2} alignItems={'center'}>
{faviconSrc && <Avatar src={faviconSrc} />}
<Link href={`https://${domain}`}>{domain}</Link>
</Stack>
</Stack>
</CardContent>
);
}

/**
* Rich representation of a link.
* @param linkMeta The metadata of the link.
* @constructor
*/
function LinkCard({ linkMeta }: { linkMeta: LinkMeta }) {
return (
<Link href={linkMeta.url} underline={'none'}>
<Card sx={{ maxWidth: 345 }}>
<CardActionArea>
{linkMeta.imageSrc && (
<CardMedia component={'img'} height={180} image={linkMeta.imageSrc} alt={linkMeta.title} />
)}
<LinkContent
title={linkMeta.title}
description={linkMeta.description}
faviconSrc={linkMeta.faviconSrc}
domain={linkMeta.domain}
/>
</CardActionArea>
</Card>
</Link>
);
}

export default LinkCard;
64 changes: 64 additions & 0 deletions src/models/artifact-meta-models.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
enum Year {
None = -1,
Freshman,
Sophomore,
Junior,
Senior,
}

enum Quarter {
None = -1,
Fall,
Winter,
Spring,
Summer,
}

interface ImageMeta {
title: string;
description: string;
width: number;
height: number;
src: string;
thumbnailSrc: string;
}

interface LinkMeta {
url: string;
title: string;
description: string;
imageSrc: string;
faviconSrc: string;
domain: string;
}

interface LinkExtract {
title: string;
description: string;
images: string[];
sitename: string;
favicon: string;
duration: number;
domain: string;
url: string;
source: string;
}

interface ArtifactMeta {
title: string;
subtitle: string;
year: Year;
quarter: Quarter;
text: string;
images: ImageMeta[];
links: LinkMeta[];
embeds: string[];
}

/**
* A map of artifact names to their metadata.
*/
type ArtifactMetas = ArtifactMeta[];

export { Quarter, Year };
export type { ArtifactMeta, ArtifactMetas, ImageMeta, LinkMeta, LinkExtract };
1 change: 1 addition & 0 deletions src/models/artifact-metas.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/utils/artifact-metas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ArtifactMetas } from '../models/artifact-meta-models.ts';
import artifactMetasString from '../models/artifact-metas.json?raw';

const artifactMetas: ArtifactMetas = JSON.parse(artifactMetasString) as ArtifactMetas;

export default artifactMetas;

0 comments on commit 35a6214

Please sign in to comment.