Skip to content

Commit

Permalink
Fix: Only remove entry if deletion is confirmed (#10)
Browse files Browse the repository at this point in the history
* update minWidth and minHeight for a better UI

* fix: remove file only after confirmation is given

* make sure regex is only compiled once

---------

Co-authored-by: Ryan Dsouza <[email protected]>
  • Loading branch information
ryands17 and Ryan Dsouza authored Aug 21, 2024
1 parent 1ff421c commit 6b06428
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 30 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
"devDependencies": {
"@tauri-apps/cli": "2.0.0-beta.20",
"internal-ip": "^7.0.0",
"prettier": "^3.3.3",
"typescript": "^5.2.2",
"vite": "^4.5.0",
"vite-plugin-solid": "^2.7.2"
}
},
"prettier": {}
}
10 changes: 10 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub fn get_size<'a>(

pub fn get_dir_names(path: &Path) -> Vec<PathBuf> {
let mut filenames = Vec::new();
let node_modules_regex = Regex::new(r"node_modules").unwrap();

let walker = GlobWalkerBuilder::from_patterns(path, &["**/node_modules", "**/![.pnpm]/*"])
.max_depth(6)
Expand All @@ -66,7 +67,6 @@ pub fn get_dir_names(path: &Path) -> Vec<PathBuf> {

for file in walker {
let path_string = file.path().display().to_string();
let node_modules_regex = Regex::new(r"node_modules").unwrap();

let mut count = 0;
let mut start = 0;
Expand Down
4 changes: 2 additions & 2 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
"fullscreen": false,
"resizable": true,
"title": "pulsar",
"width": 800,
"height": 600
"minWidth": 1000,
"minHeight": 800
}
]
}
Expand Down
50 changes: 24 additions & 26 deletions src/components/results-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,38 @@ function deleteNodeModules(path: string) {
const fileExists = await exists(path);

if (fileExists) {
const shouldDelete = await confirm(
`${path} will be DELETED.
Are you sure?
`,
{
kind: "warning",
title: "NON-REVERSIBLE ACTION",
okLabel: "DELETE",
}
);

if (shouldDelete) {
console.warn(":: deleting ::");
const rm = await remove(`${path}/node_modules`, { recursive: true });
console.log(rm);
return true;
}
console.warn(":: deleting ::");
await remove(`${path}/node_modules`, { recursive: true });
}

return false;
return true;
};
}

function TableRow(props: TRprops) {
const [shouldDelete, setDelete] = createSignal(false);

const [data, { mutate }] = createResource(
const [data] = createResource(
shouldDelete,
deleteNodeModules(props.directoryPrefix + props.directory)
deleteNodeModules(props.directoryPrefix + props.directory),
);

async function confirmDelete() {
const shouldDelete = await confirm(
`${props.directoryPrefix + props.directory} will be DELETED.
Are you sure?
`,
{
kind: "warning",
title: "NON-REVERSIBLE ACTION",
okLabel: "DELETE",
},
);

setDelete(shouldDelete);
}

return (
<Show when={!data()}>
<tr
Expand Down Expand Up @@ -82,9 +83,8 @@ function TableRow(props: TRprops) {
<li>
<button
type="button"
onClick={() => {
mutate(true);
setDelete(true);
onClick={async () => {
await confirmDelete();
}}
>
<Trashbin />
Expand All @@ -98,8 +98,6 @@ function TableRow(props: TRprops) {
}

export default function ResultsTable(props: ListProps) {
const [selected, setSelected] = createSignal([]);

return (
<table class="w-full text-center">
<thead class="sticky top-0 backdrop-blur-xl">
Expand Down

0 comments on commit 6b06428

Please sign in to comment.