Skip to content

Commit bc7daa1

Browse files
Conditionally render back to top btn. Prevent error when testing post with no tags
1 parent b91b8cf commit bc7daa1

File tree

3 files changed

+21
-39
lines changed

3 files changed

+21
-39
lines changed

web/components/KeywordTags.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ const TagCount = styled.span`
2727

2828
function KeywordTags(props) {
2929
// console.log('props: ', props)
30-
const tags = sortObjProperties(props.tags, 'name')
30+
const tags = props.tags.length > 0 ? sortObjProperties(props.tags, 'name') : null
3131

3232
return (
3333
<div>
34-
{/* this length check prevents `All Posts` button from rendering prior to the rest of the tag buttons */}
35-
{tags.length > 0 && (
34+
{/* this prevents `All Posts` button from rendering prior to the rest of the tag buttons */}
35+
{tags && (
3636
<TagBtn
3737
onClick={props.handleTagFilter}
3838
id='clearFilter'
@@ -46,7 +46,7 @@ function KeywordTags(props) {
4646
</TagBtn>
4747
)}
4848

49-
{tags.map(tag => (
49+
{tags && tags.map(tag => (
5050
tag.count > 0 && (
5151
<TagBtn
5252
key={tag.name}

web/components/Layout.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ function Layout(props) {
4949

5050
<title>Jason Roundtree - Blog</title>
5151
<meta name="viewport" content="initial-scale=1.0, width=device-width" />
52-
{/* TODO: check to see if favicons load after build */}
5352
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"/>
5453
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png"/>
5554
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"/>

web/pages/posts/[slug].js

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// import { useEffect, useState } from 'react'
1+
import { useEffect, useState } from 'react'
22
import Link from 'next/link'
33
import client from '../../client'
44
import styled from 'styled-components'
@@ -105,7 +105,14 @@ const H3 = styled.h3`
105105
`
106106

107107
function Post(props) {
108+
const [articleBtmPos, setArticleBtmPos] = useState(0)
108109
// console.log('propsPost: ', props)
110+
111+
useEffect(() => {
112+
const articleBottom = document.querySelector('article').getClientRects()[0].bottom
113+
setArticleBtmPos(articleBottom)
114+
}, [])
115+
109116
function handleScrollToTop() {
110117
window.scroll({
111118
top: 0,
@@ -181,29 +188,7 @@ function Post(props) {
181188
// inline text
182189
if (children[j].text) {
183190
renderedContent.push(children[j].text)
184-
}
185-
// TODO: i don't think this is currently setup correctly since it pushes to blockContent but should probably be renderedContent. There's currently no ext links within a code aside so add some to test (add some to git log part?):
186-
// else if (children[j].marks && children[j].marks.length > 0) {
187-
// // console.log('children[j]: ', children[j])
188-
// // console.log('content[i]: ', content[i])
189-
// const hrefTarget = matchExtLinkMarkDef(
190-
// children[j],
191-
// content[i].markDefs
192-
// )
193-
// hrefTarget && (
194-
// console.log('CXXCXXCXCXXCXCX') ||
195-
// blockContent.push(
196-
// <ExternalLink
197-
// target="_blank"
198-
// href={hrefTarget.href}
199-
// key={hrefTarget._key}
200-
// >
201-
// {hrefTarget.text}
202-
// </ExternalLink>
203-
// )
204-
// )
205-
// }
206-
else {
191+
} else {
207192
renderedContent.push(
208193
<AsideCode key={children[j]._key}>
209194
{children[j].str_content_inline}
@@ -317,19 +302,17 @@ function Post(props) {
317302
</MainContent>
318303
</article>
319304

320-
<Button
321-
onClick={handleScrollToTop}
322-
>
323-
{/* ⬆︎ */}
324-
Back to top
325-
{/* ⬆︎ */}
326-
</Button>
305+
{articleBtmPos > 1000 && (
306+
<Button onClick={handleScrollToTop}>
307+
Back to top
308+
</Button>
309+
)}
310+
327311
<br />
312+
328313
<Link href="/">
329314
<a>
330-
<Button>
331-
Blog Home
332-
</Button>
315+
<Button>Blog Home</Button>
333316
</a>
334317
</Link>
335318

0 commit comments

Comments
 (0)