8000 Fix collapsing commit history by tjomson · Pull Request #665 · git-truck/git-truck · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix collapsing commit history #665

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

Merged
merged 2 commits into from
Nov 5, 2023
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
6 changes: 5 additions & 1 deletion src/components/FileHistoryElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ interface CommitDistFragProps {
commitCutoff: number
sortBy?: SortCommitsMethods
handleOnClick?: (commit: GitLogEntry) => void
setCollapsed: React.Dispatch<React.SetStateAction<boolean>>
collapsed: boolean
}

export function CommitDistFragment(props: CommitDistFragProps) {
Expand Down Expand Up @@ -75,6 +77,8 @@ export function CommitDistFragment(props: CommitDistFragProps) {
openByDefault={ true }
items={ items }
itemsCutoff={ props.commitCutoff }
collapsed = {props.collapsed}
setCollapsed = { props.setCollapsed}
></Accordion>
</Fragment>
)
Expand Down Expand Up @@ -105,7 +109,7 @@ function CommitHistory(props: { commits: GitLogEntry[] | undefined }) {
<ChevronButton id={commitHistoryExpandId} open={!collapsed} => setCollapsed(!collapsed)} />
</div>
<div>
<CommitDistFragment commitCutoff={ collapsed ? commitCutoff : commits.length } items={ commits } />
<CommitDistFragment commitCutoff={ collapsed ? commitCutoff : commits.length } items={ commits } setCollapsed={setCollapsed} collapsed/>
</div>
</>
)
Expand Down
13 changes: 8 additions & 5 deletions src/components/accordion/Accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ function Accordion({
titleLabels,
currentState,
actionClickLabels,
setCollapsed,
collapsed
}: {
items: Array<AccordionData>
itemsCutoff: number
Expand All @@ -29,17 +31,18 @@ function Accordion({
titleLabels?: boolean
currentState?: Array<boolean>
actionClickLabels?: (id: number) => void
setCollapsed: React.Dispatch<React.SetStateAction<boolean>>
collapsed: boolean
}) {
const [currentIdx, setCurrentIdx] = useState(new Array<number>())
const [showFullList, setShowFullList] = useState(false)
const btnOnClick = (idx: number) => {
multipleOpen
? setCurrentIdx((currentValue) =>
currentValue.includes(idx) ? currentValue.filter((item) => item !== idx) : [...currentValue, idx]
)
: setCurrentIdx((currentValue) => (currentValue.includes(idx) ? [] : [idx]))
}
const cutItems = showFullList ? items : items.slice(0, itemsCutoff)
const cutItems = !collapsed ? items : items.slice(0, itemsCutoff)
if (openByDefault && !multipleOpen) {
setCurrentIdx([0]);
}
Expand All @@ -66,17 +69,17 @@ function Accordion({
</>
))}
<ShowMoreLabel
show={!showFullList && items.length > itemsCutoff}
show={collapsed && items.length > itemsCutoff}
items={items.slice(itemsCutoff)}
toggle={() => setShowFullList(!showFullList)}
toggle={() => setCollapsed(!collapsed)}
/>
</ul>
)
}

export function ShowMoreLabel(props: ShowMoreLabelProps) {
if (!props.show) return null
return <span className="whitespace-pre text-xs font-medium opacity-70 hover:cursor-pointer" day(s) more</span>
return <span className="whitespace-pre text-xs font-medium opacity-70 hover:cursor-pointer" more day{props.items.length > 1 ? "s" : ""}</span>
}

export default Accordion
0