Skip to content

Commit dfc5c95

Browse files
committed
Import update:
- verision logic updated and moved into the second useEffect, so that dependencies can be added without getting errors when fetching data. Otherwise it's typesafety updates
1 parent 53358e7 commit dfc5c95

File tree

5 files changed

+19
-16
lines changed

5 files changed

+19
-16
lines changed

src/common/ui/SpacedList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const SpacedList = ({
1313
return (
1414
<List disablePadding sx={{ ...sx }}>
1515
{React.Children.map(children, (child, idx) => {
16-
const baseKey = (child as any)?.key ?? "idx";
16+
const baseKey = (child as React.ReactElement)?.key ?? "idx";
1717
const key = `${String(baseKey)}-${idx}`;
1818
return (
1919
<Box

src/features/sidebar/view/internal/ClientSplitView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import { useEffect, useContext, useState } from "react";
3+
import { useEffect, useContext } from "react";
44
import { Stack, useMediaQuery, useTheme } from "@mui/material";
55
import { isMac, useKeyboardShortcut, SidebarTogglableContext } from "@/common";
66
import { useSidebarOpen } from "../../data";

src/features/sidebar/view/internal/diffbar/DiffContent.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,32 @@ const DiffContent = () => {
2626
const [selectedChange, setSelectedChange] = useState<number | null>(null);
2727
const [loading, setLoading] = useState(false);
2828

29-
3029
useEffect(() => {
31-
setData(null);
32-
if (version !== undefined) {
33-
setFromBranch(version.baseRef || "");
34-
setToBranch(version.id);
35-
}
36-
}, [project, specification, version]);
30+
setData(null);
31+
32+
let currentFromBranch = fromBranch;
33+
let currentToBranch = toBranch;
34+
35+
if (version !== undefined) {
36+
currentFromBranch = version.baseRef || "";
37+
currentToBranch = version.id;
38+
setFromBranch(version.baseRef || "");
39+
setToBranch(version.id);
40+
}
3741

38-
useEffect(() => {
3942
const compare = async () => {
40-
if (project && specification && fromBranch && toBranch) {
43+
if (project && specification && currentFromBranch && currentToBranch) {
4144
setLoading(true);
4245
const res = await fetch(
43-
`/api/diff/${project.owner}/${project.name}/${specification.id}?from=${fromBranch}&to=${toBranch}`
46+
`/api/diff/${project.owner}/${project.name}/${specification.id}?from=${currentFromBranch}&to=${currentToBranch}`
4447
);
4548
setLoading(false);
4649
const result = await res.json();
4750
setData(result);
4851
}
4952
};
5053
compare();
51-
}, [toBranch, fromBranch]);
54+
}, [toBranch, fromBranch, project, specification, version]);
5255

5356
const changes = data?.changes || [];
5457
const versions = project?.versions || [];

src/features/sidebar/view/internal/diffbar/components/DiffHeader.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const DiffHeader = ({
2525
Added changes from main:
2626
</Typography>
2727
<Select value={fromBranch} onChange={(e) => onChange(e.target.value)}>
28-
{versions.map((v: any) => (
28+
{versions.map((v: Version) => (
2929
<MenuItem key={v.id} value={v.id}>
3030
{v.name}
3131
</MenuItem>

src/features/sidebar/view/internal/tertiary/Container.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
'use client'
22

3-
import { SxProps } from "@mui/system"
3+
44
import { Box } from "@mui/material"
55
import { useTheme } from "@mui/material/styles"
66

77
const DiffContainer = ({
88
width,
99
isOpen,
10-
onClose,
10+
onClose: _onClose,
1111
children
1212
}: {
1313
width: number

0 commit comments

Comments
 (0)