Skip to content

Commit

Permalink
Merge branch 'release/2.7.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
marceloglacial committed Jul 27, 2021
2 parents 3c6622c + 77cf255 commit 360b5d6
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 139 deletions.
8 changes: 6 additions & 2 deletions components/Blocks/Blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Form from './Form/Form';
import Embed from './Embed/Embed';
import InstaFeed from './InstaFeed/InstaFeed';
import HubSpotForms from './Hubspot/Forms';
import parse from 'html-react-parser';

const BlocksView = (props) => {
const { attrs, innerHTML, blockName } = props;
Expand All @@ -15,6 +14,7 @@ const BlocksView = (props) => {
const blockType = {
'snow-blocks/hero': <Hero {...attrs} />,
'snow-blocks/postslist': <PostList {...attrs} />,
'snow-blocks/image': <ImageCore {...props} />,
'snow-blocks/instagram-feed': <InstaFeed {...attrs} />,
'snow-blocks/forms': <Form {...props} />,
'snow-blocks/hubspot-forms': <HubSpotForms {...props} />,
Expand All @@ -24,7 +24,11 @@ const BlocksView = (props) => {
};

if (!blockType[blockName])
return <div data-aos='fade-in'>{parse(innerHTML)}</div>;
return (
<div data-aos='fade-in'>
<div dangerouslySetInnerHTML={{ __html: innerHTML }} />
</div>
);

return <div data-aos='fade-up'>{blockType[blockName]}</div>;
};
Expand Down
3 changes: 1 addition & 2 deletions components/Blocks/Embed/Embed.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { getCaption } from 'functions/getCaption';
import Iframe from './components/Iframe';
import Twitter from './components/Twitter';

const Embed = (props) => {
const { innerHTML, attrs } = props;
const { url, providerNameSlug: type } = attrs;
const caption = innerHTML && getCaption(innerHTML);
const caption = innerHTML?.includes('figcaption');
const embeds = {
soundcloud: <Iframe type={'soundcloud'} url={url} caption={caption} />,
twitter: <Twitter url={url} caption={caption} />,
Expand Down
3 changes: 0 additions & 3 deletions components/Blocks/Embed/Embed.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ $spacing: 1rem;

.twitter {
margin: 0 auto;
border: solid 1px var(--grey-light);
border-radius: var(--border-radius);
overflow: hidden;

@media (min-width: 768px) {
max-width: 50%;
Expand Down
39 changes: 22 additions & 17 deletions components/Blocks/Embed/components/Twitter.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
import { TwitterTimelineEmbed, TwitterTweetEmbed } from 'react-twitter-embed';
import { twitter } from '../Embed.module.scss';
import { useEffect } from 'react';

const Twitter = (props) => {
const { url } = props;

// Single Tweet
if (url.includes('/status/')) {
const tweetID = url.split('/status/')[1];
if (!url) return null;

const hasStatus = url.includes('status');
const twitterTag = hasStatus ? 'twitter-tweet' : 'twitter-timeline';

useEffect(() => {
const script = document.createElement('script');
script.src = 'https://platform.twitter.com/widgets.js';
document.getElementsByClassName(twitterTag)[0].appendChild(script);
}, []);

if (hasStatus) {
return (
<div className={twitter}>
<blockquote className={twitterTag}>
<a href={`${url}`}></a>
</blockquote>
</div>
);
} else {
return (
<div className={twitter}>
<TwitterTweetEmbed tweetId={tweetID} />
<a className={twitterTag} href={url}></a>
</div>
);
}

// User Timeline
const userName = url.split('twitter.com/')[1];
return (
<div className={twitter}>
<TwitterTimelineEmbed
sourceType='profile'
screenName={userName}
options={{ height: 600 }}
/>
</div>
);
};
export default Twitter;
15 changes: 11 additions & 4 deletions components/Blocks/Gallery/Gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
// @see https://github.com/WordPress/gutenberg/issues/10994

import useApi from 'hooks/useApi';
import parseTagFromString from 'functions/parseTagFromString';
import Carousel, { Modal, ModalGateway } from 'react-images';
import GalleryImage from './components/GalleryImage';
import { useState } from 'react';
import { useEffect, useState } from 'react';

const Gallery = (props) => {
const { attrs, innerHTML } = props;
const { ids } = attrs;
const galleryClass = parseTagFromString(innerHTML, 'gallery').className;
const [modalIsOpen, setModalIsOpen] = useState(false);
const [selectedIndex, setSelectedIndex] = useState(0);
const [galleryClassName, setGalleryClassName] = useState('');

const images = ids.map((id) => {
const {
Expand All @@ -35,6 +34,14 @@ const Gallery = (props) => {
setSelectedIndex(index);
};

useEffect(() => {
const gallery = document.createElement('div');
gallery.innerHTML = innerHTML;
document.querySelector('.gallery').appendChild(gallery);
setGalleryClassName(gallery.children[0].className);
document.querySelector('.gallery').removeChild(gallery);
}, []);

return (
<>
<ModalGateway>
Expand All @@ -45,7 +52,7 @@ const Gallery = (props) => {
) : null}
</ModalGateway>

<figure className={galleryClass}>
<figure className={`gallery ${galleryClassName}`}>
<ul className='blocks-gallery-grid'>
{images.map((item, index) => {
const imageProps = {
Expand Down
46 changes: 18 additions & 28 deletions components/Blocks/Image/Image.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,27 @@
import Image from 'next/image';
import styles from './Image.module.scss';
import useApi from 'hooks/useApi';

const ImageCore = (props) => {
const { id, align } = props.attrs;
const { data: image, isLoading, isError } = useApi(`/api/media/${id}`);

if (isLoading) return 'loading ...';
if (isError) return 'Error!';

const { width, height } = image.media_details;
const imageSrc = image.source_url;
const imageAlt = image.alt_text;

const imageAlign = {
left: 'float-left mr-3',
right: 'float-right ml-3',
};

const { media, imageSize = 'full' } = props.attrs || props.attributes;
const { url, width, height } = media?.sizes[imageSize];
const { alt, caption } = media;
return (
<div className={`text-${align} ${align === 'full' && styles.full}`}>
<figure
className={`${styles.figure} ${imageAlign[align]} mt-4 mb-5`}
data-aos='fade-in'
>
<Image
src={imageSrc}
alt={imageAlt}
width={width || 1440}
height={height || 900}
<figure className={`${styles.figure} mt-4 mb-5`} data-aos='fade-in'>
<Image
src={url}
alt={alt}
width={width || 800}
height={height || 600}
className={styles.image}
/>
{caption && (
<figcaption
className={styles.figureCaption}
style={{ width: `${width}px` }}
dangerouslySetInnerHTML={{ __html: caption }}
/>
</figure>
</div>
)}
</figure>
);
};
export default ImageCore;
50 changes: 14 additions & 36 deletions components/Blocks/Image/Image.module.scss
Original file line number Diff line number Diff line change
@@ -1,46 +1,24 @@
.figure {
position: relative;
display: inline-flex;
display: flex;
justify-content: center;

div {
border-radius: var(--border-radius);
box-shadow: var(--shadow);
}

.figure-caption {
position: absolute;
bottom: 0;
width: 100%;
padding: 20% 1rem 1rem 1rem;
color: var(--white);
text-align: left;
border-bottom-left-radius: var(--border-radius);
border-bottom-right-radius: var(--border-radius);
background: rgb(0, 0, 0);
background: linear-gradient(
0deg,
rgba(0, 0, 0, 1) 0%,
rgba(0, 0, 0, 0) 100%
);
background-color: var(--grey-light);
}
}

.full {
position: relative;

.figure {
position: relative;
width: 100vw;
position: relative;
margin-left: -50vw;
left: 50%;

div,
img,
figcaption {
border-radius: 0;
width: 100%;
max-height: 90vh;
}
}
.figureCaption {
position: absolute;
bottom: 0;
width: 100%;
padding: 20% 1rem 1rem 1rem;
color: var(--white);
text-align: left;
border-bottom-left-radius: var(--border-radius);
border-bottom-right-radius: var(--border-radius);
background: rgb(0, 0, 0);
background: linear-gradient(0deg, rgba(0, 0, 0, 1) 0%, rgba(0, 0, 0, 0) 100%);
}
8 changes: 0 additions & 8 deletions functions/getCaption.js

This file was deleted.

28 changes: 0 additions & 28 deletions functions/parseTagFromString.js

This file was deleted.

6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "brinca-2020",
"version": "2.6.0",
"version": "2.7.0",
"private": true,
"scripts": {
"dev": "next dev",
Expand All @@ -16,13 +16,9 @@
"aos": "^2.3.4",
"bootstrap": "^4.6.0",
"cors": "^2.8.5",
"html-react-parser": "^1.2.6",
"htmlparser2": "^6.1.0",
"next-connect": "^0.10.1",
"postscribe": "^2.0.8",
"react-html-parser": "^2.0.2",
"react-images": "^1.2.0-beta.6",
"react-twitter-embed": "^3.0.3",
"sass": "^1.32.11",
"swr": "^0.5.6"
}
Expand Down
8 changes: 5 additions & 3 deletions pages/[slug].js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Layout from 'components/Layout/Layout';
import Blocks from 'components/Blocks/Blocks';
import { useRouter } from 'next/router';
import { getData } from 'functions/getData';
import HtmlParser from 'react-html-parser';

const Page = (props) => {
const { page } = props;
Expand All @@ -11,7 +10,7 @@ const Page = (props) => {
if (isFallback) {
return <div>Loading...</div>;
}
const title = HtmlParser(page[0].title.rendered);
const title = page[0]?.title?.rendered;

const blocks = page[0].blocks.map((block, index) => {
return <Blocks {...block} key={index} />;
Expand All @@ -20,7 +19,10 @@ const Page = (props) => {
return (
<Layout pageTitle={title} {...props}>
<header data-aos='fade-in'>
<h1 className='content-title'>{title}</h1>
<h1
className='content-title'
dangerouslySetInnerHTML={{ __html: title }}
/>
</header>
{blocks}
</Layout>
Expand Down
8 changes: 5 additions & 3 deletions pages/post/[slug].js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Layout from 'components/Layout/Layout';
import Blocks from 'components/Blocks/Blocks';
import { useRouter } from 'next/router';
import { getData } from 'functions/getData';
import HtmlParser from 'react-html-parser';

const Post = (props) => {
const { post } = props;
Expand All @@ -11,7 +10,7 @@ const Post = (props) => {
if (router.isFallback) {
return <div>Loading...</div>;
}
const title = HtmlParser(post[0].title.rendered);
const title = post[0]?.title?.rendered;

const blocks = post[0].blocks.map((block, index) => {
return <Blocks {...block} key={index} />;
Expand All @@ -20,7 +19,10 @@ const Post = (props) => {
return (
<Layout pageTitle={title} {...props}>
<header data-aos='fade-in'>
<h1 className='content-title'>{title}</h1>
<h1
className='content-title'
dangerouslySetInnerHTML={{ __html: title }}
/>
</header>
{blocks}
</Layout>
Expand Down

1 comment on commit 360b5d6

@vercel
Copy link

@vercel vercel bot commented on 360b5d6 Jul 27, 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.