Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Dribbble component #131

Merged
merged 2 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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