Skip to content

Commit

Permalink
Merge pull request #5 from fre-ben/englishheadline
Browse files Browse the repository at this point in the history
✨ Add getRandomHeadlineEnglish button
  • Loading branch information
fre-ben authored Mar 7, 2021
2 parents ca12a80 + 327b078 commit 3ca1cec
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 10 deletions.
4 changes: 0 additions & 4 deletions notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,3 @@ return test;
dRj7MBwlYafKn4RJFGHIM--anhE1w_bpXLYKo7hdZIKJW0eX

https://api.currentsapi.services/v1/latest-news?language=de&apiKey=dRj7MBwlYafKn4RJFGHIM--anhE1w_bpXLYKo7hdZIKJW0eX

## Todo

- Sport news rausfiltern
18 changes: 18 additions & 0 deletions src/components/headline/headline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,21 @@ export function displayGermanHeadline({ headline, link }) {
],
});
}

export function displayEnglishHeadline({ headline, link }) {
return createElement("div", {
className: "headline__container",
childs: [
createElement("p", {
className: "headline",
innerText: headline,
}),
createElement("a", {
className: "headline__link",
href: link,
innerText: "Read article",
target: "_blank",
}),
],
});
}
6 changes: 6 additions & 0 deletions src/pages/catlinez/catlinez.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@
display: grid;
justify-items: center;
}

.button__container {
display: grid;
grid-auto-flow: column;
gap: 0.5em;
}
32 changes: 26 additions & 6 deletions src/pages/catlinez/catlinez.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import { displayHeader } from "../../components/header/header";
import { createElement } from "../../utils/createElement";
import {
getRandomCat,
getRandomHeadlineEnglish,
getRandomHeadlineGerman,
randomNumber,
} from "../../utils/api";
import { displayCat } from "../../components/cat/randomcat";
import { displayGermanHeadline } from "../../components/headline/headline";
import {
displayGermanHeadline,
displayEnglishHeadline,
} from "../../components/headline/headline";

export default {
title: "Pages/Catlinez",
Expand All @@ -18,9 +21,9 @@ export const catlinez = (args, { loaded: { cat, headline } }) => {
const catElement = displayCat(cat);
const headlineElement = displayGermanHeadline(headline);

const randomButton = createElement("button", {
className: "randomButton",
innerText: "Refresh",
const randomButtonGer = createElement("button", {
className: "randomButtonGer",
innerText: "German Catline",
onclick: async () => {
const cat = await getRandomCat();
const headline = await getRandomHeadlineGerman();
Expand All @@ -30,10 +33,27 @@ export const catlinez = (args, { loaded: { cat, headline } }) => {
buildCatlinez.replaceChild(headlineElement, buildCatlinez.childNodes[2]);
},
});
const randomButtonEng = createElement("button", {
className: "randomButtonEng",
innerText: "English Catline",
onclick: async () => {
const cat = await getRandomCat();
const headline = await getRandomHeadlineEnglish();
const catElement = displayCat(cat);
const headlineElement = displayEnglishHeadline(headline);
buildCatlinez.replaceChild(catElement, buildCatlinez.childNodes[1]);
buildCatlinez.replaceChild(headlineElement, buildCatlinez.childNodes[2]);
},
});

const buttons = createElement("div", {
className: "button__container",
childs: [randomButtonGer, randomButtonEng],
});

const buildCatlinez = createElement("div", {
className: "catlinez__container",
childs: [displayHeader(), catElement, headlineElement, randomButton],
childs: [displayHeader(), catElement, headlineElement, buttons],
});

return buildCatlinez;
Expand Down
9 changes: 9 additions & 0 deletions src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,12 @@ export async function getRandomHeadlineGerman() {
const headline = convertToText(result);
return headline;
}

export async function getRandomHeadlineEnglish() {
const response = await fetch(
`https://api.currentsapi.services/v1/latest-news?category=general&apiKey=dRj7MBwlYafKn4RJFGHIM--anhE1w_bpXLYKo7hdZIKJW0eX`
);
const result = (await response.json()) as News;
const headline = convertToText(result);
return headline;
}

1 comment on commit 3ca1cec

@vercel
Copy link

@vercel vercel bot commented on 3ca1cec Mar 7, 2021

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.