Skip to content

Commit

Permalink
Refactor to consume data from endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
victorlmneves committed Sep 14, 2020
1 parent 7cb31cc commit f7acb11
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 91 deletions.
80 changes: 78 additions & 2 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ let cards = null
let carouselConfig = null
let carouselImages = null
let featuresSection = null
let twitterSection = null
let tweets = null
let socialNetworks = null
let copyright = null

const heroSectionContent = fetch(
'https://express-api.victorneves.dev/hero_section/',
Expand Down Expand Up @@ -165,6 +169,74 @@ interfaceTabsImagesContent.then(function (res) {
interfaceTabsImages = res
})

const twitterContent = fetch(
"https://express-api.victorneves.dev/twitter_section/",
requestOptions
)
.then((resp) => resp.json())
.then((res) => {
const obj = res.records

return obj
})
.catch((error) => console.log(JSON.stringify(error)))

twitterContent.then(function (res) {
twitterSection = res[0]
})

const tweetsContent = fetch(
"https://express-api.victorneves.dev/tweets/",
requestOptions
)
.then((resp) => resp.json())
.then((res) => {
const obj = res.records

return obj
})
.catch((error) => console.log(JSON.stringify(error)))

tweetsContent.then(function (res) {
console.log("tweets ", res)
tweets = res
})

const socialNetworksContent = fetch(
"https://express-api.victorneves.dev/social_networks/",
requestOptions
)
.then((resp) => resp.json())
.then((res) => {
const obj = res.records

return obj
})
.catch((error) => console.log(JSON.stringify(error)))

socialNetworksContent.then(function (res) {
socialNetworks = res
})

const copyrightContent = fetch(
"https://express-api.victorneves.dev/copyrights/",
requestOptions
)
.then((resp) => resp.json())
.then((res) => {
const obj = {
__class: res.records[0].css,
text: res.records[0].text,
}

return obj
})
.catch((error) => console.log(JSON.stringify(error)))

copyrightContent.then(function (res) {
copyright = res
})

router.get('/', function (req, res, next) {
res.render("index", {
heroSection,
Expand All @@ -174,8 +246,12 @@ router.get('/', function (req, res, next) {
carouselImages,
appsSection,
interfaceTabs,
interfaceTabsImages
})
interfaceTabsImages,
tweets,
twitterSection,
socialNetworks,
copyright,
});
})

module.exports = router
8 changes: 4 additions & 4 deletions src/_modules/cards/cards.pug
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ mixin twitterCards(spec)
each val in spec
li.twitter__card
.twitter__user
image(class='twitter__img' src=`images/${val.userPhoto}` alt=`Photo of ${val.userName}`)
p.twitter__name #{userName}
image(class='twitter__img' src=`images/${val.photo}` alt=`Photo of ${val.username}`)
p.twitter__name #{username}
img(class='twitter__icon' alt='Twitter' src='images/social-twitter.svg')
p.twitter__text #{val.tweetText}
p.twitter__date #{val.tweetDate}
p.twitter__text #{val.text}
p.twitter__date #{val.date}
2 changes: 1 addition & 1 deletion src/_modules/link/link.pug
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ mixin menuLink(text, css, link)

mixin linkWithImage(name, css, link, image)
a(class=css href=link)
image(src=image alt=name)
image(src=`images/${image}` alt=name)
91 changes: 7 additions & 84 deletions views/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -83,75 +83,17 @@ block content
.section__content.section__content--left
+sectionTitle(appsSection.title)
+text(appsSection.text)
+interfaceTabs({
interfaceTabs,
interfaceTabsImages
})
+interfaceTabs({interfaceTabs,interfaceTabsImages})

section.section.section--twitter
.section__inner.section__inner--row
.section__content.section__content--left
+sectionTitle('We believe in the power of community')
+text({__class: 'section__text', text: 'Our goal is to create a product and service that you’re satisfied with and use it every day. This is why we’re constantly working on our services to make it better every day and really listen to what our users has to say.'})
+primaryButton('Read more testimonials', 'section__button')
+sectionTitle(twitterSection.title)
+text({__class: twitterSection.text_css, text: twitterSection.text})
+primaryButton(twitterSection.link_text, twitterSection.link_css)

.section__content
+twitterCards([
{
userPhoto: 'person-patrick-martin.png',
userName: 'Patrick Martin',
tweetText: 'ShowTrackr is a real gem! I started using it a couple months ago and it completely changed the way how I watch TV shows. I can only recommend it!',
tweetDate: 'Jan 18, 2018'
},
{
userPhoto: 'person-bruce-murphy.png',
userName: 'Bruce Murphy',
tweetText: 'ShowTrackr is a real gem! I started using it a couple months ago and it completely changed the way how I watch TV shows.',
tweetDate: 'Jan 18, 2018'
},
{
userPhoto: 'person-crystal-perkins.png',
userName: 'Crystal Perkins',
tweetText: 'ShowTrackr. I can only recommend it!',
tweetDate: 'Jan 18, 2018'
},
{
userPhoto: 'person-gregory-wallace.png',
userName: 'Gregory Wallace',
tweetText: 'ShowTrackr is a real gem! I started using it a couple months ago and it completely changed the way how I watch TV shows. I can only recommend it!',
tweetDate: 'Jan 18, 2018'
},
{
userPhoto: 'person-megan-walters.png',
userName: 'Megan Walters',
tweetText: 'ShowTrackr is a real gem! I started using it a couple months ago and it completely changed the way how I watch TV shows.',
tweetDate: 'Jan 18, 2018'
},
{
userPhoto: 'person-thomas-cruz.png',
userName: 'Thomas Cruz',
tweetText: 'ShowTrackr. I can only recommend it!',
tweetDate: 'Jan 18, 2018'
},
{
userPhoto: 'person-andrew-cook.png',
userName: 'Andrew Cook',
tweetText: 'ShowTrackr is a real gem! I started using it a couple months ago and it completely changed the way how I watch TV shows. I can only recommend it!',
tweetDate: 'Jan 18, 2018'
},
{
userPhoto: 'person-joseph-mathews.png',
userName: 'Joseph Mathews',
tweetText: 'ShowTrackr is a real gem! I started using it a couple months ago and it completely changed the way how I watch TV shows.',
tweetDate: 'Jan 18, 2018'
},
{
userPhoto: 'person-patrick-martin.png',
userName: 'Patrick Martin',
tweetText: 'ShowTrackr is a real gem! I started using it a couple months ago and it completely changed the way how I watch TV shows.',
tweetDate: 'Jan 18, 2018'
}
])
+twitterCards(tweets)

section.section
.section__inner.section__inner--get-started
Expand Down Expand Up @@ -184,27 +126,8 @@ block content

footer(css='footer')
div(class='footer__inner')
+socialNetworks([
{
name: 'Twitter',
css: 'social-networks__link',
link: '#',
image: 'images/social-twitter.svg'
},
{
name: 'Facebook',
css: 'social-networks__link',
link: '#',
image: 'images/social-facebook.svg'
},
{
name: 'YouTube',
css: 'social-networks__link',
link: '#',
image: 'images/social-youtube.svg'
}
])
+socialNetworks(socialNetworks)

+text({__class: 'footer__copyrights', text: 'Copyright 2020 All rights reserved — Designed by Daniel Korpai | Code by Victor Neves'})
+text(copyright)

+back-to-top()

0 comments on commit f7acb11

Please sign in to comment.