Skip to content

Commit

Permalink
adding open all button
Browse files Browse the repository at this point in the history
  • Loading branch information
Courey committed Oct 16, 2024
1 parent d91fa13 commit cca475d
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions app/routes/group.$synonymId.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
*/
import type { LoaderFunctionArgs } from '@remix-run/node'
import { Link, useLoaderData } from '@remix-run/react'
import { Icon } from '@trussworks/react-uswds'
import { Button, Icon } from '@trussworks/react-uswds'
import { useRef, useState } from 'react'

Check warning on line 11 in app/routes/group.$synonymId.tsx

View check run for this annotation

Codecov / codecov/patch

app/routes/group.$synonymId.tsx#L9-L11

Added lines #L9 - L11 were not covered by tests

import type { SynonymGroup } from './synonyms/synonyms.lib'
import {

Check warning on line 14 in app/routes/group.$synonymId.tsx

View check run for this annotation

Codecov / codecov/patch

app/routes/group.$synonymId.tsx#L14

Added line #L14 was not covered by tests
Expand Down Expand Up @@ -40,6 +41,18 @@ export default function Group() {
const { members, eventIds, view, limit, page } =
useLoaderData<typeof loader>()
const searchString = `?view=${view}&limit=${limit}&page=${page}`
const detailsRef = useRef<NodeListOf<HTMLDetailsElement>>()
const [allOpen, setAllOpen] = useState(false)

Check warning on line 45 in app/routes/group.$synonymId.tsx

View check run for this annotation

Codecov / codecov/patch

app/routes/group.$synonymId.tsx#L42-L45

Added lines #L42 - L45 were not covered by tests
const buttonText = allOpen ? 'Close' : 'Open'

const toggleDetails = () => {
setAllOpen(!allOpen)

Check warning on line 49 in app/routes/group.$synonymId.tsx

View check run for this annotation

Codecov / codecov/patch

app/routes/group.$synonymId.tsx#L48-L49

Added lines #L48 - L49 were not covered by tests
if (detailsRef.current) {
detailsRef.current.forEach((details) => {
details.open = !allOpen

Check warning on line 52 in app/routes/group.$synonymId.tsx

View check run for this annotation

Codecov / codecov/patch

app/routes/group.$synonymId.tsx#L51-L52

Added lines #L51 - L52 were not covered by tests
})
}
}

return (

Check warning on line 57 in app/routes/group.$synonymId.tsx

View check run for this annotation

Codecov / codecov/patch

app/routes/group.$synonymId.tsx#L57

Added line #L57 was not covered by tests
<>
Expand All @@ -56,11 +69,17 @@ export default function Group() {
</div>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Back
</Link>
<Button
type="button"
onClick={toggleDetails}
>{`${buttonText} All`}</Button>
</ToolbarButtonGroup>

<h1>{`Group ${eventIds.join(', ')}`}</h1>
{members.map((circular) => (
<div key={circular.circularId}>
<details>

<div ref={(el) => (detailsRef.current = el?.querySelectorAll('details'))}>
{members.map((circular) => (
<details key={circular.circularId}>

Check warning on line 82 in app/routes/group.$synonymId.tsx

View check run for this annotation

Codecov / codecov/patch

app/routes/group.$synonymId.tsx#L80-L82

Added lines #L80 - L82 were not covered by tests
<summary>
<Link to={`/circulars/${circular.circularId}`}>
{circular.subject}
Expand All @@ -80,8 +99,8 @@ export default function Group() {
<PlainTextBody className="margin-2" children={circular.body} />
</div>
</details>
</div>
))}
))}
</div>
</>
)
}

0 comments on commit cca475d

Please sign in to comment.