added a feature for the git heatmap which shows the amount of commits done on the cell youre hovering over
This commit is contained in:
parent
ffb96d1c02
commit
19b8bc0dd2
1 changed files with 21 additions and 9 deletions
|
|
@ -31,6 +31,7 @@ export default function ContributionHeatmap() {
|
||||||
const [error, setError] = useState(false);
|
const [error, setError] = useState(false);
|
||||||
const [totalContribs, setTotalContribs] = useState(0);
|
const [totalContribs, setTotalContribs] = useState(0);
|
||||||
const [activities, setActivities] = useState<Activity[]>([]);
|
const [activities, setActivities] = useState<Activity[]>([]);
|
||||||
|
const [hoveredCell, setHoveredCell] = useState<{ date: string; contribs: number } | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function fetchHeatmap() {
|
async function fetchHeatmap() {
|
||||||
|
|
@ -45,7 +46,7 @@ export default function ContributionHeatmap() {
|
||||||
data.forEach((item) => {
|
data.forEach((item) => {
|
||||||
const d = new Date(item.timestamp * 1000);
|
const d = new Date(item.timestamp * 1000);
|
||||||
const dateStr = d.getFullYear() + "-" + String(d.getMonth() + 1).padStart(2, "0") + "-" + String(d.getDate()).padStart(2, "0");
|
const dateStr = d.getFullYear() + "-" + String(d.getMonth() + 1).padStart(2, "0") + "-" + String(d.getDate()).padStart(2, "0");
|
||||||
map.set(dateStr, item.contributions);
|
map.set(dateStr, (map.get(dateStr) || 0) + item.contributions);
|
||||||
total += item.contributions;
|
total += item.contributions;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -135,13 +136,23 @@ export default function ContributionHeatmap() {
|
||||||
data-level={day.level >= 0 ? day.level : undefined}
|
data-level={day.level >= 0 ? day.level : undefined}
|
||||||
style={{ visibility: day.level === -1 ? "hidden" : "visible" }}
|
style={{ visibility: day.level === -1 ? "hidden" : "visible" }}
|
||||||
title={day.level >= 0 ? `${day.contribs} contributions on ${day.date}` : undefined}
|
title={day.level >= 0 ? `${day.contribs} contributions on ${day.date}` : undefined}
|
||||||
|
onMouseEnter={() => day.level >= 0 && setHoveredCell({ date: day.date, contribs: day.contribs })}
|
||||||
|
onMouseLeave={() => setHoveredCell(null)}
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
<div style={{ display: "flex", justifyContent: "flex-end", alignItems: "center", gap: "4px", fontSize: "0.75rem", color: "var(--gray)" }}>
|
<div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", fontSize: "0.75rem", color: "var(--gray)", marginTop: "4px" }}>
|
||||||
|
<div>
|
||||||
|
{hoveredCell ? (
|
||||||
|
<span><strong style={{ color: "var(--fg)" }}>{hoveredCell.contribs}</strong> contributions on {hoveredCell.date}</span>
|
||||||
|
) : (
|
||||||
|
<span>Hover over a day to see contributions</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div style={{ display: "flex", alignItems: "center", gap: "4px" }}>
|
||||||
<span>Less</span>
|
<span>Less</span>
|
||||||
<div className="heatmap-legend-cell" data-level="0"></div>
|
<div className="heatmap-legend-cell" data-level="0"></div>
|
||||||
<div className="heatmap-legend-cell" data-level="1"></div>
|
<div className="heatmap-legend-cell" data-level="1"></div>
|
||||||
|
|
@ -150,6 +161,7 @@ export default function ContributionHeatmap() {
|
||||||
<div className="heatmap-legend-cell" data-level="4"></div>
|
<div className="heatmap-legend-cell" data-level="4"></div>
|
||||||
<span>More</span>
|
<span>More</span>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
{activities.length > 0 && (
|
{activities.length > 0 && (
|
||||||
<div>
|
<div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue