Skip to content

Commit

Permalink
✨ Add article link to function
Browse files Browse the repository at this point in the history
  • Loading branch information
fre-ben committed Feb 13, 2021
1 parent 8ea9d67 commit a6b81b8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/components/headline/headline.stories.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "./headline.css";
import { displayHeadline } from "./headline";
import { displayGermanHeadline } from "./headline";
import { createElement } from "../../utils/createElement";
import { getRandomHeadlineGerman } from "../../utils/api";

Expand All @@ -9,7 +9,7 @@ export default {
};

export const HeadlineFromAPI = (args, { loaded: { headline } }) => {
return displayHeadline(headline);
return displayGermanHeadline(headline);
};

HeadlineFromAPI.loaders = [
Expand Down
17 changes: 13 additions & 4 deletions src/components/headline/headline.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import { createElement } from "../../utils/createElement";

export function displayHeadline({ headline }) {
return createElement("p", {
className: "headline",
innerText: headline,
export function displayGermanHeadline({ headline, link }) {
return createElement("div", {
className: "headline__container",
childs: [
createElement("p", {
className: "headline",
innerText: headline,
}),
createElement("a", {
href: link,
innerText: "Artikel lesen",
}),
],
});
}
2 changes: 2 additions & 0 deletions src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ export type News = {
// Was ich brauch von currentsAPI
export type Headline = {
headline: string;
link: string;
};

const randomHeadline = Math.floor(Math.random() * 30);

function convertToText(headline: News): Headline {
return {
headline: headline.news[randomHeadline].title,
link: headline.news[randomHeadline].url,
};
}

Expand Down

0 comments on commit a6b81b8

Please sign in to comment.