Skip to content

Commit 726177d

Browse files
committed
Fix
1 parent 8e25f9d commit 726177d

File tree

2 files changed

+28
-42
lines changed

2 files changed

+28
-42
lines changed

src/components/SetRepository.tsx

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ function SetRepository(): ReactElement {
9292
console.log({ type, owner });
9393
setOwnerData(undefined);
9494

95-
if (type === "Organization") {
95+
if (type === CurrentRepositoryType.Organization) {
9696
github
9797
.graphQL<OrganizationData>(graphqlOrganization, {
9898
organization: owner,
9999
})
100100
.then(({ organization }) => {
101101
setOwnerData(organization);
102102
});
103-
} else if (type === "User") {
103+
} else if (type === CurrentRepositoryType.User) {
104104
github
105105
.graphQL<UserData>(graphqlUser, {
106106
user: owner,
@@ -129,13 +129,10 @@ function SetRepository(): ReactElement {
129129

130130
function handleConfirmSetRepository(): void {
131131
if (!newRepository) return;
132-
const nr = {};
133-
Object.assign(nr, newRepository);
134-
for (const qk of Object.keys(nr)) {
135-
if (!nr[qk] || nr[qk] === "") delete nr[qk];
136-
}
137-
138-
window.localStorage.setItem("currentRepository", JSON.stringify(nr));
132+
window.localStorage.setItem(
133+
"currentRepository",
134+
JSON.stringify(newRepository)
135+
);
139136
handleCloseSetRepository();
140137
}
141138

@@ -144,14 +141,10 @@ function SetRepository(): ReactElement {
144141
}
145142

146143
function handleGoToNextStep(): void {
147-
const nr: CurrentRepository | undefined = newRepository;
148-
if (!nr) return;
149-
if (steps[currentStepIndex + 1].value === "repository") {
150-
nr[steps[currentStepIndex + 1].value] = "";
144+
if (newRepository && currentStep.label === "Owner") {
145+
setNewRepository({ ...newRepository, repository: "" });
151146
getRepositories();
152147
}
153-
154-
setNewRepository(nr);
155148
setCurrentStep(steps[currentStepIndex + 1]);
156149
}
157150

@@ -205,8 +198,11 @@ function SetRepository(): ReactElement {
205198
<Autocomplete
206199
disableClearable
207200
fullWidth
208-
options={["Organization", "User"]}
209-
value={newRepository[currentStep.value]}
201+
options={[
202+
CurrentRepositoryType.Organization,
203+
CurrentRepositoryType.User,
204+
]}
205+
value={newRepository.type}
210206
onChange={(_event, newValue: string) => {
211207
setNewRepository({
212208
...newRepository,
@@ -217,12 +213,25 @@ function SetRepository(): ReactElement {
217213
<TextField {...params} label={currentStep.label} />
218214
)}
219215
/>
216+
) : currentStep.label === "Owner" ? (
217+
<TextField
218+
fullWidth
219+
margin="dense"
220+
label={currentStep.label}
221+
value={newRepository.owner}
222+
onChange={(event: ChangeEvent<HTMLInputElement>): void => {
223+
setNewRepository({
224+
...newRepository,
225+
[currentStep.value]: event.target.value,
226+
});
227+
}}
228+
/>
220229
) : currentStep.label === "Repository" && repositoriesPicker ? (
221230
<Autocomplete
222231
disableClearable
223232
fullWidth
224233
options={repositoriesPicker}
225-
value={newRepository[currentStep.value]}
234+
value={newRepository.repository}
226235
onChange={(_event, newValue: string) => {
227236
setNewRepository({
228237
...newRepository,
@@ -234,18 +243,7 @@ function SetRepository(): ReactElement {
234243
)}
235244
/>
236245
) : (
237-
<TextField
238-
fullWidth
239-
margin="dense"
240-
label={currentStep.label}
241-
value={newRepository[currentStep.value]}
242-
onChange={(event: ChangeEvent<HTMLInputElement>): void => {
243-
setNewRepository({
244-
...newRepository,
245-
[currentStep.value]: event.target.value,
246-
});
247-
}}
248-
/>
246+
<CircularProgress color="primary" />
249247
)}
250248
</Grid>
251249
</Grid>

src/lib/util.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
import moment, { Moment } from "moment";
22

3-
export function groupByKey<T>(
4-
array: Array<T>,
5-
key: string
6-
): { [key: string]: Array<T> } {
7-
return array.reduce((hash, obj) => {
8-
if (obj[key] === undefined) return hash;
9-
return Object.assign(hash, {
10-
[obj[key]]: (hash[obj[key]] || []).concat(obj),
11-
});
12-
}, {});
13-
}
14-
153
export function arrayOfDatesBetweenDates(
164
startDate: string,
175
endDate: string

0 commit comments

Comments
 (0)