Skip to content

Commit

Permalink
chore(REC-740): refacto chapter card
Browse files Browse the repository at this point in the history
  • Loading branch information
trollepierre committed Dec 6, 2020
1 parent 044cf70 commit 5997bb0
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 148 deletions.
2 changes: 1 addition & 1 deletion front/components/ArticleCard/ArticleCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
target="_blank"
rel="noreferrer"
class="article__dropbox article__footer__button">
{{ $t("viewGallery") }}
{{ $t("viewGallery") }}
</a>
</template>
</footer>
Expand Down
130 changes: 9 additions & 121 deletions front/components/ChapterCard/ChapterCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,86 +19,35 @@
rel="noreferrer"
class="chapter__image">
</div>
<footer class="chapter__footer">
<ul
v-for="paragraph in chapterText"
:key="paragraph.text"
class="paragraph-container">
<li
v-if="paragraph"
class="paragraph">
<iframe
v-if="paragraph.iframeSrc"
:width="dimensions.width"
:height="dimensions.height"
:src="paragraph.iframeSrc"
:title="chapterTitle"
class="youtube-iframe"
allow="accelerometer; encrypted-media; gyroscope;"
allowfullscreen/>
<p
v-else-if="paragraph.link"
class="chapter__footer_text">
<a
:href="paragraph.link"
rel="noreferrer"
target="_blank">
{{ paragraph.link }}
</a>
</p>
<h3
v-else
class="chapter__footer_text">
{{ paragraph.text }}
</h3>
</li>
</ul>
</footer>
<paragraphs
:chapterText="chapterText"
:title="chapterTitle"/>
</article>
</template>

<script>
import translationsService from '../../services/services/translations'
import {
generateCleanUrlLink, generateIframeLink, urlTester, youtubeEmbedUrlTester,
} from './paragraph-link-utils'
import { iframeDimensions } from '../../services'
import translationsService from '../../services/services/translations'
import Paragraphs from './Paragraphs/Paragraphs'
export default {
export default {
name: 'ChapterCard',
components: { Paragraphs },
props: { chapter: { type: Object, default: () => {} } },
data: () => ({ dimensions: iframeDimensions() }),
computed: {
imgLink() {
const { imgLink } = this.chapter
return !imgLink ? false : imgLink
},
styleMissing() {
return `height: ${this.dimensions.height}px;"`
},
chapterTitle() {
const language = this.$store.state.locale
return translationsService.getChapterTitle(this.chapter, language)
},
chapterAlt() {
return this.$t('altComplement') + (this.chapterText[0] ? this.chapterText[0].text : '')
return this.$t('altComplement') + (this.chapterText[0] ? this.chapterText[0] : '')
},
chapterText() {
const language = this.$store.state.locale
const chapterText = translationsService.getChapterText(this.chapter, language)
return chapterText
.filter(paragraph => !!paragraph)
.map(this.enhanceParagraph)
},
},
methods: {
enhanceParagraph(paragraph) {
return {
iframeSrc: youtubeEmbedUrlTester(paragraph) ? generateIframeLink(paragraph) : undefined,
link: urlTester(paragraph) ? generateCleanUrlLink(paragraph) : undefined,
text: paragraph,
}
return translationsService.getChapterText(this.chapter, language)
},
},
i18n: {
Expand Down Expand Up @@ -167,65 +116,4 @@
color: #000;
text-align: center;
}
.chapter__footer {
text-align: center;
padding: 0 15px;
border-top: 1px solid #E6E6E6;
}
.chapter__footer button {
text-transform: uppercase;
color: #D14800;
background: #FFFFFF;
border: 1px solid #D14800;
cursor: pointer;
padding: 15px 30px;
border-radius: 4px;
width: 100%;
margin-bottom: 10px;
font-weight: 700;
}
.chapter__footer button:hover {
background: #D14800;
color: #FFFFFF;
}
.chapter__footer button:disabled,
.chapter__footer button:active {
background: #BDBDBD;
border-color: #616161;
color: #FAFAFA;
cursor: auto;
}
.youtube-iframe {
margin: 30px 0;
border: none;
}
.chapter__footer_text {
font-size: 18px;
word-spacing: 1px;
}
.missing-image {
display: flex;
justify-content: center;
}
.paragraph {
list-style-type: none;
}
.paragraph-container {
padding: 0;
}
@media only screen and (min-width: 640px) {
.chapter__footer_text {
font-weight: lighter;
}
}
</style>
30 changes: 30 additions & 0 deletions front/components/ChapterCard/Paragraphs/Paragraphs.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Paragraphs from './Paragraphs.vue'

describe('Component | Paragraphs.vue', () => {
let wrapper
let propsData

beforeEach(() => {
propsData = { title: 'title', chapterText: ['voilà', ''] }
})

describe('template', () => {
it('should match snapshot with text', () => {
wrapper = shallowMount(Paragraphs, { propsData })
expect(wrapper).toMatchSnapshot()
})

it('should match snapshot with link', () => {
propsData = { title: 'title', chapterText: ['https://www.rec.me'] }
wrapper = shallowMount(Paragraphs, { propsData })
expect(wrapper).toMatchSnapshot()
})

it('should match snapshot with video', () => {
propsData = { title: 'title', chapterText: ['https://www.youtu.be/embed/123'] }
wrapper = shallowMount(Paragraphs, { propsData })
expect(wrapper).toMatchSnapshot()
})
})
})

129 changes: 129 additions & 0 deletions front/components/ChapterCard/Paragraphs/Paragraphs.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<template>
<footer class="chapter__footer">
<ul
v-for="paragraph in paragraphs"
:key="paragraph.text"
class="paragraph-container">
<li
v-if="paragraph"
class="paragraph">
<iframe
v-if="paragraph.iframeSrc"
:width="dimensions.width"
:height="dimensions.height"
:src="paragraph.iframeSrc"
:title="title"
class="youtube-iframe"
allow="accelerometer; encrypted-media; gyroscope;"
allowfullscreen/>
<p
v-else-if="paragraph.link"
class="chapter__footer_text">
<a
:href="paragraph.link"
rel="noreferrer"
target="_blank">
{{ paragraph.link }}
</a>
</p>
<h3
v-else
class="chapter__footer_text">
{{ paragraph.text }}
</h3>
</li>
</ul>
</footer>
</template>
<script>
import { iframeDimensions } from '../../../services'
import {
generateCleanUrlLink,
generateIframeLink,
urlTester,
youtubeEmbedUrlTester,
} from './paragraph-link-utils'
export default {
name: 'Paragraphs',
props: {
chapterText: { type: Array, default: () => [] },
title: { type: String, default: () => '' },
},
data: () => ({ dimensions: iframeDimensions() }),
computed: {
paragraphs() {
return this.chapterText
.filter(paragraph => !!paragraph)
.map(this.enhanceParagraph)
},
},
methods: {
enhanceParagraph(paragraph) {
return {
iframeSrc: youtubeEmbedUrlTester(paragraph) ? generateIframeLink(paragraph) : undefined,
link: urlTester(paragraph) ? generateCleanUrlLink(paragraph) : undefined,
text: paragraph,
}
},
},
}
</script>

<style scoped>
.chapter__footer {
text-align: center;
padding: 0 15px;
border-top: 1px solid #E6E6E6;
}
.chapter__footer button {
text-transform: uppercase;
color: #D14800;
background: #FFFFFF;
border: 1px solid #D14800;
cursor: pointer;
padding: 15px 30px;
border-radius: 4px;
width: 100%;
margin-bottom: 10px;
font-weight: 700;
}
.chapter__footer button:hover {
background: #D14800;
color: #FFFFFF;
}
.chapter__footer button:disabled,
.chapter__footer button:active {
background: #BDBDBD;
border-color: #616161;
color: #FAFAFA;
cursor: auto;
}
.youtube-iframe {
margin: 30px 0;
border: none;
}
.chapter__footer_text {
font-size: 18px;
word-spacing: 1px;
}
.paragraph {
list-style-type: none;
}
.paragraph-container {
padding: 0;
}
@media only screen and (min-width: 640px) {
.chapter__footer_text {
font-weight: lighter;
}
}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Component | Paragraphs.vue template should match snapshot with link 1`] = `
<footer class="chapter__footer">
<ul class="paragraph-container">
<li class="paragraph">
<p class="chapter__footer_text"><a href="https://www.rec.me" rel="noreferrer" target="_blank">
https://www.rec.me
</a></p>
</li>
</ul>
</footer>
`;

exports[`Component | Paragraphs.vue template should match snapshot with text 1`] = `
<footer class="chapter__footer">
<ul class="paragraph-container">
<li class="paragraph">
<h3 class="chapter__footer_text">
voilà
</h3>
</li>
</ul>
</footer>
`;

exports[`Component | Paragraphs.vue template should match snapshot with video 1`] = `
<footer class="chapter__footer">
<ul class="paragraph-container">
<li class="paragraph"><iframe width="512" height="288" src="https://www.youtu.be/embed/123?rel=0&amp;modestbranding=1" title="title" allow="accelerometer; encrypted-media; gyroscope;" allowfullscreen="allowfullscreen" class="youtube-iframe"></iframe></li>
</ul>
</footer>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,6 @@ exports[`Component | ChapterCard.vue template should match snapshot 1`] = `
</p>
</header>
<div class="chapter__content"><img src="webf" alt="An image showing Title of the first paragraph" rel="noreferrer" class="chapter__image"></div>
<footer class="chapter__footer">
<ul class="paragraph-container">
<li class="paragraph">
<h3 class="chapter__footer_text">
Title of the first paragraph
</h3>
</li>
</ul>
<ul class="paragraph-container">
<li class="paragraph">
<p class="chapter__footer_text"><a href="https://github.com/trollepierre" rel="noreferrer" target="_blank">
https://github.com/trollepierre
</a></p>
</li>
</ul>
<ul class="paragraph-container">
<li class="paragraph">
<h3 class="chapter__footer_text">
url
</h3>
</li>
</ul>
<ul class="paragraph-container">
<li class="paragraph"><iframe width="512" height="288" src="https://www.youtube.com/embed/-18AYp_7iW0?rel=0&amp;modestbranding=1" title="My title" allow="accelerometer; encrypted-media; gyroscope;" allowfullscreen="allowfullscreen" class="youtube-iframe"></iframe></li>
</ul>
</footer>
<paragraphs-stub chaptertext="Title of the first paragraph,https://github.com/trollepierre,url,https://www.youtube.com/embed/-18AYp_7iW0" title="My title"></paragraphs-stub>
</article>
`;

0 comments on commit 5997bb0

Please sign in to comment.