Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close related section #1207

Merged
merged 5 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions components/accordian-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import AccordionContext from 'react-bootstrap/AccordionContext'
import { useAccordionButton } from 'react-bootstrap/AccordionButton'
import ArrowRight from '@/svgs/arrow-right-s-fill.svg'
import ArrowDown from '@/svgs/arrow-down-s-fill.svg'
import { useContext, useEffect } from 'react'
import { useContext, useEffect, useState } from 'react'

const KEY_ID = '0'

function ContextAwareToggle ({ children, headerColor = 'var(--theme-grey)', eventKey, show }) {
const { activeEventKey } = useContext(AccordionContext)
Expand All @@ -29,10 +31,20 @@ function ContextAwareToggle ({ children, headerColor = 'var(--theme-grey)', even
}

export default function AccordianItem ({ header, body, headerColor = 'var(--theme-grey)', show }) {
const [activeKey, setActiveKey] = useState()

useEffect(() => {
setActiveKey(show ? KEY_ID : null)
}, [show])

const handleOnSelect = () => {
setActiveKey(activeKey === KEY_ID ? null : KEY_ID)
}

return (
<Accordion defaultActiveKey={show ? '0' : undefined}>
<ContextAwareToggle show={show} eventKey='0'><div style={{ color: headerColor }}>{header}</div></ContextAwareToggle>
<Accordion.Collapse eventKey='0' className='mt-2'>
<Accordion defaultActiveKey={activeKey} activeKey={activeKey} onSelect={handleOnSelect}>
<ContextAwareToggle show={show} eventKey={KEY_ID}><div style={{ color: headerColor }}>{header}</div></ContextAwareToggle>
<Accordion.Collapse eventKey={KEY_ID} className='mt-2'>
<div>{body}</div>
</Accordion.Collapse>
</Accordion>
Expand Down
9 changes: 8 additions & 1 deletion components/item-full.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,14 @@ function TopLevelItem ({ item, noReply, ...props }) {
</article>
{!noReply &&
<>
<Reply item={item} replyOpen placeholder={item.ncomments > 3 ? 'fractions of a penny for your thoughts?' : 'early comments get more zaps'} onCancelQuote={cancelQuote} onQuoteReply={quoteReply} quote={quote} />
<Reply
item={item}
replyOpen
placeholder={item.ncomments > 3 ? 'fractions of a penny for your thoughts?' : 'early comments get more zaps'}
onCancelQuote={cancelQuote}
onQuoteReply={quoteReply}
quote={quote}
/>
{
// Don't show related items for Saloon items (position is set but no subName)
(!item.position && item.subName) &&
Expand Down
10 changes: 9 additions & 1 deletion components/reply.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ export function ReplyOnAnotherPage ({ item }) {
)
}

export default forwardRef(function Reply ({ item, onSuccess, replyOpen, children, placeholder, onQuoteReply, onCancelQuote, quote }, ref) {
export default forwardRef(function Reply ({
item,
replyOpen,
children,
placeholder,
onQuoteReply,
onCancelQuote,
quote
}, ref) {
ekzyis marked this conversation as resolved.
Show resolved Hide resolved
const [reply, setReply] = useState(replyOpen || quote)
const me = useMe()
const parentId = item.id
Expand Down
Loading