Skip to content

Commit

Permalink
chore: pruned useless abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
LatentDream committed Apr 24, 2024
1 parent 55ac040 commit 875ac9c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 36 deletions.
6 changes: 1 addition & 5 deletions src/renderer/hooks/useTestImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,5 @@ export const useDiscoverPytestElements = () => {
return ok(newElems);
}

// Return a function that takes the file path as an argument
return async (filePath: string) => {
const result = await getTests(filePath);
return result;
};
return getTests
};
2 changes: 1 addition & 1 deletion src/renderer/hooks/useTestSequencerState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export function createNewTest(test: NewTest): Test {
completionTime: undefined,
error: null,
isSavedToCloud: false,
exportToCloud: test.exportToCloud || true,
exportToCloud: test.exportToCloud === undefined ? true : test.exportToCloud,
createdAt: new Date().toISOString(),
minValue: test.minValue,
maxValue: test.maxValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,41 +42,22 @@ export const ChangeLinkedTestModal = ({
const discoverPytestElement = useDiscoverPytestElements();

const handleDiscoverPytestElements = async (filePath: string) => {
try {
const result = await discoverPytestElement(filePath);
if (result.isOk()) {
setAvailableTests(result.value);
if (result.value.length > 0) {
setSelectedPath(result.value[0].path);
}
} else {
console.error(result.error);
const result = await discoverPytestElement(filePath);
if (result.isOk()) {
setAvailableTests(result.value);
if (result.value.length > 0) {
setSelectedPath(result.value[0].path);
}
} catch (error) {
console.error(error);
} else {
console.error(result.error);
}
};

const openFilePicker = async () => {
return new Promise<string | null>((resolve, reject) => {
window.api.openTestPicker().then((result) => {
if (!result) {
reject(new Error("No file selected."));
} else {
resolve(result.filePath);
}
});
});
};

const handleFilePicker = async () => {
try {
const filePath = await openFilePicker();
if (filePath) {
await handleDiscoverPytestElements(filePath);
}
} catch (error) {
console.error(error);
const res = await window.api.openTestPicker();
if (!res) return;
if (res.filePath) {
await handleDiscoverPytestElements(res.filePath);
}
};

Expand Down

0 comments on commit 875ac9c

Please sign in to comment.