Skip to content

Commit afa2e28

Browse files
Fix bug causing each list item of a list group to be rendered in a ul
1 parent 5199e14 commit afa2e28

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

web/components/PostImg.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ const PostImg = styled.img`
1515
`
1616
const PostLqipImg = styled(PostImg)`
1717
position: absolute;
18-
width: 100%;
19-
transform: scale(1);
20-
transition: visibility 0ms ease 400ms;
18+
/* width: 100%; */
19+
/* TODO: what exactly are these supposed to be doing? */
20+
/* transform: scale(1);
21+
transition: visibility 0ms ease 400ms; */
2122
`
2223
const PhotoCredit = styled.p`
2324
text-align: center;

web/pages/posts/[slug].js

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -338,28 +338,32 @@ function Post(props) {
338338
// TODO: test if list rendering works correctly with multiple lists in post
339339
let list = []
340340
let listGroupKey = ''
341-
props.body && props.body.forEach(section => {
342-
// console.log('section >>> ', section)
341+
props.body && props.body.forEach((section, i, arr) => {
342+
343343
if (section.listItem) {
344+
// console.log('section.listItem', section)
344345
list.push(
345346
<ListItem key={section._key}>
346347
{formatListItem(section.children, section.markDefs)}
347348
</ListItem>
348349
)
349350
listGroupKey += section._key
350351
}
351-
352-
if (list.length > 0) {
353-
// console.log('list: ', list)
352+
353+
if (
354+
// If the current section isn't a list item, but the list array has items, then we know the end of the list was just passed and we can now group the list items under a <ul> for rendering:
355+
!section.listItem && (list.length > 0) ||
356+
// This case ensures that a list is properly rendered when the last element of a post is a list:
357+
section.listItem && (i === arr.length - 1)
358+
) {
354359
postContent.push(
355-
// TODO: why is key needed on this UL here?
356360
<UL key={listGroupKey}>{list}</UL>
357361
)
358362
list = []
359363
listGroupKey = ''
360364
}
361365

362-
else {
366+
if (!section.listItem) {
363367
switch(section._type) {
364368
case 'block':
365369
postContent.push(
@@ -479,15 +483,5 @@ export async function getStaticProps(context) {
479483
`, { slug } )
480484
return { props: post }
481485
}
482-
483-
// Post.getInitialProps = async function(context) {
484-
// // default the slug so that it doesn't return "undefined"
485-
// // console.log('context: ', context)
486-
// const { slug = "" } = context.query
487-
// const data = await client.fetch(`
488-
// *[_type == "post" && slug.current == $slug][0]
489-
// `, { slug })
490-
// return data
491-
// }
492486

493487
export default Post

0 commit comments

Comments
 (0)