-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(articles): broken main image (#22)
* fix(articles): broken main image * fix(article): removed unused import * fix(articles) update image size
- Loading branch information
Showing
4 changed files
with
96 additions
and
75 deletions.
There are no files selected for viewing
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,88 +1,113 @@ | ||
export interface Article { | ||
id: number; | ||
meta: { | ||
type: string; | ||
detail_url: string; | ||
html_url: string; | ||
slug: string; | ||
first_published_at: string; | ||
}; | ||
title: string; | ||
intro: string; | ||
body: string; | ||
contributors: Array<{ | ||
id: number; | ||
meta: { | ||
type: string; | ||
detail_url: string; | ||
html_url: string; | ||
slug: string; | ||
first_published_at: string; | ||
}; | ||
name: string; | ||
contribution_type: string; | ||
image?: string; | ||
}>; | ||
tags: Array<{ | ||
id: number; | ||
name: string; | ||
slug: string; | ||
}>; | ||
main_image?: { | ||
title: string; | ||
intro: string; | ||
body: string; | ||
contributors: Array<{ | ||
id: number; | ||
name: string; | ||
contribution_type: string; | ||
image?: string; | ||
}>; | ||
tags: Array<{ | ||
id: number; | ||
name: string; | ||
slug: string; | ||
}>; | ||
main_image?: { | ||
alt: string; | ||
url: string; | ||
sizes: { | ||
thumbnail: { | ||
url: string; | ||
width: number; | ||
height: number; | ||
}; | ||
small: { | ||
url: string; | ||
width: number; | ||
height: number; | ||
}; | ||
medium: { | ||
url: string; | ||
full_url: string; | ||
width: number; | ||
height: number; | ||
alt: string; | ||
}; | ||
large: { | ||
url: string; | ||
width: number; | ||
height: number; | ||
}; | ||
extra_large: { | ||
url: string; | ||
width: number; | ||
height: number; | ||
}; | ||
}; | ||
}; | ||
} | ||
|
||
export interface FetchArticlesProps { | ||
api_url: string; | ||
limit?: number; | ||
offset?: number; | ||
tags?: string[]; | ||
api_url: string; | ||
limit?: number; | ||
offset?: number; | ||
tags?: string[]; | ||
} | ||
|
||
export const fetchArticles = async ({ | ||
api_url, | ||
tags = [], | ||
limit = 6, | ||
offset = 0, | ||
api_url, | ||
tags = [], | ||
limit = 6, | ||
offset = 0, | ||
}: FetchArticlesProps): Promise<Article[]> => { | ||
const url = new URL(`${api_url}api/v2/news/`); | ||
url.searchParams.set("fields", "title,tags,first_published_at,main_image"); | ||
url.searchParams.set("limit", limit.toString(10)); | ||
url.searchParams.set("offset", offset.toString(10)); | ||
const url = new URL(`${api_url}api/v2/news/`); | ||
url.searchParams.set("fields", "title,tags,first_published_at,main_image"); | ||
url.searchParams.set("limit", limit.toString(10)); | ||
url.searchParams.set("offset", offset.toString(10)); | ||
|
||
if (tags?.length) { | ||
url.searchParams.set("tags", tags.join(",")); | ||
} | ||
if (tags?.length) { | ||
url.searchParams.set("tags", tags.join(",")); | ||
} | ||
|
||
const response = await fetch(url.toString()); | ||
const data = await response.json(); | ||
const articles: Article[] = data.items; | ||
return articles; | ||
const response = await fetch(url.toString()); | ||
const data = await response.json(); | ||
const articles: Article[] = data.items; | ||
return articles; | ||
}; | ||
|
||
export const fetchArticleIdBySlug = async ({ | ||
slug, | ||
api_url, | ||
slug, | ||
api_url, | ||
}: { | ||
slug: string; | ||
api_url: string; | ||
slug: string; | ||
api_url: string; | ||
}): Promise<number | null> => { | ||
const response = await fetch(`${api_url}api/v2/news/?&slug=${slug}`); | ||
const data = await response.json(); | ||
const articles: Article[] = data.items; | ||
if (articles.length > 0) { | ||
return articles[0].id; | ||
} else { | ||
return null; | ||
} | ||
const response = await fetch(`${api_url}api/v2/news/?&slug=${slug}`); | ||
const data = await response.json(); | ||
const articles: Article[] = data.items; | ||
if (articles.length > 0) { | ||
return articles[0].id; | ||
} else { | ||
return null; | ||
} | ||
}; | ||
|
||
export const fetchArticleById = async ({ | ||
id, | ||
api_url, | ||
id, | ||
api_url, | ||
}: { | ||
id: number; | ||
api_url: string; | ||
id: number; | ||
api_url: string; | ||
}): Promise<Article> => { | ||
const response = await fetch(`${api_url}api/v2/news/${id}/`); | ||
const data = await response.json(); | ||
return data; | ||
const response = await fetch(`${api_url}api/v2/news/${id}/`); | ||
const data = await response.json(); | ||
return data; | ||
}; |