Skip to content

Commit 18289a5

Browse files
committed
🚚 update: Highlight directly by clicking commits in CommitSelector (#19)
Improve UI by removing the checked commit highlighter button and adding a heading
1 parent f6c0d09 commit 18289a5

File tree

3 files changed

+30
-17
lines changed

3 files changed

+30
-17
lines changed

src/components/App/App.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ function App() {
3333

3434
useEffect(() => {
3535
if (objectData.objects !== undefined) {
36+
setIsLoading(true);
3637
const updatedObjectData = colorObjectsAndConnections(
3738
objectData,
3839
selectedCommits

src/components/CommitSelector/CommitSelector.css

+8-5
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,20 @@
1515
z-index: 2;
1616
}
1717

18+
#commit-selector h2 {
19+
margin: 0.5em 0.5em 1em 0.5em;
20+
}
21+
1822
#commit-selector-commit-wrapper,
19-
#commit-selector-shortcut-btn-wrapper,
20-
#commit-selector-btn-wrapper {
23+
#commit-selector-shortcut-btn-wrapper {
2124
width: 100%;
2225
display: flex;
2326
flex-direction: column;
2427
align-items: center;
2528
}
2629

27-
#commit-selector-btn-wrapper {
28-
padding-bottom: 0.5em;
30+
#commit-selector-shortcut-btn-wrapper {
31+
margin-bottom: 1em;
2932
}
3033

3134
#commit-selector-dismiss {
@@ -35,7 +38,7 @@
3538
}
3639

3740
#selector-commit-wrapper {
38-
max-height: 73vh;
41+
max-height: 71vh;
3942
overflow: auto;
4043
width: 100%;
4144
display: flex;

src/components/CommitSelector/CommitSelector.jsx

+21-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState, useEffect } from "react";
1+
import { useState, useEffect, useRef } from "react";
22
import "./CommitSelector.css";
33
import cross from "./cross.svg";
44

@@ -12,11 +12,13 @@ const CommitSelector = ({
1212
new Array(commits.length).fill(false)
1313
);
1414

15+
const timeoutInstance = useRef();
16+
1517
useEffect(() => {
1618
if (selectedCommits.length === 0)
1719
setIsChecked(new Array(commits.length).fill(false));
1820
else {
19-
const updatedCheckedState = [];
21+
let updatedCheckedState = [];
2022
for (let i = 0; i < commits.length; i++) {
2123
if (
2224
selectedCommits.some(
@@ -34,14 +36,25 @@ const CommitSelector = ({
3436
const handleCheckboxChange = (index) => {
3537
let checkboxState = [...isChecked]; // Can't directly assign, as passing by reference isn't considered as a change
3638
checkboxState[index] = !checkboxState[index];
39+
3740
setIsChecked(checkboxState);
41+
debouncedCommitSubmission(checkboxState);
42+
};
43+
44+
const debouncedCommitSubmission = (checkboxState) => {
45+
clearTimeout(timeoutInstance.current);
46+
47+
timeoutInstance.current = setTimeout(
48+
() => submitSelectedCommits(checkboxState),
49+
900
50+
);
3851
};
3952

40-
const submitSelectedCommits = () => {
53+
const submitSelectedCommits = (checkboxState) => {
4154
let commitArr = [];
42-
for (let i = 0; i < commits.length; i++) {
43-
if (isChecked[i] === true) commitArr.push(commits[i].hash);
44-
}
55+
for (let i = 0; i < commits.length; i++)
56+
if (checkboxState[i] === true) commitArr.push(commits[i].hash);
57+
4558
selectCommits(commitArr);
4659
};
4760

@@ -73,6 +86,8 @@ const CommitSelector = ({
7386
</button>
7487
</div>
7588

89+
<h2>Highlight Commits</h2>
90+
7691
<div id="commit-selector-shortcut-btn-wrapper">
7792
<button onClick={() => submitAllCommits()}>
7893
Highlight All Commits
@@ -83,12 +98,6 @@ const CommitSelector = ({
8398
</button>
8499
</div>
85100

86-
<div id="commit-selector-btn-wrapper">
87-
<button onClick={() => submitSelectedCommits()}>
88-
Highlight Checked Commits
89-
</button>
90-
</div>
91-
92101
<div
93102
id="selector-commit-wrapper"
94103
onWheel={(event) => event.stopPropagation()}

0 commit comments

Comments
 (0)