Skip to content

Commit

Permalink
Enable Dribbble component (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathsimpson authored Oct 4, 2023
1 parent baebea0 commit 1d58163
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 33 deletions.
2 changes: 0 additions & 2 deletions components/Home/Dribbble/Dribbble.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import React from 'react';

import { Stack } from '../../ui/box';
import { Heading, Text } from '../../ui/typography';
import { TextLink } from '../../TextLink';
Expand Down
59 changes: 30 additions & 29 deletions pages/api/get-dribbble-shots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ type DribbbleShot = {
link: string;
};

type Data = {
type ResponseData = {
shots: DribbbleShot[];
};

type ResponseError = {
error: string;
};

// Return type from Dribbble API
type DribbbleApiShot = {
description: string;
Expand All @@ -25,38 +29,35 @@ type DribbbleApiShot = {
const ACCESS_TOKEN = process.env.DRIBBBLE_ACCESS_TOKEN;
const API_ENDPOINT = `https://api.dribbble.com/v2/user/shots?access_token=${ACCESS_TOKEN}`;

const getDribbbleShots = async (): Promise<DribbbleShot[]> => {
const dribbbleShots = fetch(API_ENDPOINT, {
headers: { Accept: 'application/json' }
})
.then((response) => response.json())

.then((data) => {
return (data as DribbbleApiShot[])
.map((shot) => ({
description: shot.description.replace(/(<([^>]+)>)/gi, ''),
imageUrl: shot.images.normal,
link:
shot.images && (shot.images.hidpi || shot.images.normal)
? shot.images.hidpi || shot.images.normal
: shot.html_url
}))
.filter((shot) => !shot.imageUrl.includes('.gif'));
});

return dribbbleShots;
const formatShots = (shots: DribbbleApiShot[]): DribbbleShot[] => {
return shots
.map((shot) => ({
description: shot.description.replace(/(<([^>]+)>)/gi, ''),
imageUrl: shot.images.normal,
link:
shot.images && (shot.images.hidpi || shot.images.normal)
? shot.images.hidpi || shot.images.normal
: shot.html_url
}))
.filter((shot) => !shot.imageUrl.includes('.gif'));
};

export default async function handler(
req: NextApiRequest,
res: NextApiResponse<Data>
res: NextApiResponse<ResponseData | ResponseError>
) {
return getDribbbleShots()
.then((shots) => {
res.status(200).json({ shots });
await fetch(API_ENDPOINT, {
headers: { Accept: 'application/json' }
})
.then((response) => {
if (!response.ok) {
throw new Error("Unsuccessful response from Dribbble's API");
}

return response.json().then((data) => {
const formatted = formatShots(data as DribbbleApiShot[]);
return res.status(200).json({ shots: formatted });
});
})
.catch((error) => ({
statusCode: 422,
body: JSON.stringify(error)
}));
.catch((error) => res.status(422).json({ error }));
}
4 changes: 2 additions & 2 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { HomeHero } from '../components/Home/HomeHero';
import { Projects } from '../components/Home/Projects';
import { PageContainer } from '../components/Container';
import { Development } from '../components/Home/Development';
// import { Dribbble } from '../components/Home/Dribbble/Dribbble';
import { Dribbble } from '../components/Home/Dribbble/Dribbble';
import { getAllProjects } from '../lib/mdxContent/projects';
import type { Project } from '../lib/mdxContent/projects';
import { Prose } from 'components/ui/prose';
Expand All @@ -24,7 +24,7 @@ const Home: NextPage<HomePageProps> = ({ allProjects }) => {
<Stack gap="xxxlarge" marginBottom="xxxlarge">
<Projects data={allProjects} />
<Development />
{/* <Dribbble /> */}
<Dribbble />

<Prose>
<h2>Contact Me</h2>
Expand Down

1 comment on commit 1d58163

@vercel
Copy link

@vercel vercel bot commented on 1d58163 Oct 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.