Skip to content

Commit

Permalink
feat: delete dep
Browse files Browse the repository at this point in the history
  • Loading branch information
SilenLoc committed Jun 28, 2024
1 parent 95b7b2c commit 99b3417
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 18 deletions.
25 changes: 25 additions & 0 deletions src-tauri/src/entry_point/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,31 @@ pub async fn delete_local(app_handle: tauri::AppHandle) -> Result<(), ()> {
Ok(())
}

#[tauri::command]
pub async fn delete_local_and_memory_dep(
app_handle: tauri::AppHandle,
in_memory_store: State<'_, store::in_memory_store::ModelStore>,
dep_id: String,
) -> Result<(), ()> {
if let Ok(as_uuid) = dep_id.parse::<uuid::Uuid>() {
in_memory_store.delete(as_uuid);

let stores = app_handle.state::<tauri_plugin_store::StoreCollection<Wry>>();
let path = PathBuf::from("store.bin");

let _ = with_store(app_handle.to_owned(), stores, path, |store| {
store.delete(dep_id)?;
Ok(())
});

println!("deps deleted from local");
} else {
println!("could not parse UUID");
};

Ok(())
}

#[tauri::command]
pub async fn delete_memory(
in_memory_store: State<'_, store::in_memory_store::ModelStore>,
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/entry_point/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub fn start_app() {
commands::load_into_local,
commands::delete_local,
commands::delete_memory,
commands::delete_local_and_memory_dep,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
Expand Down
7 changes: 7 additions & 0 deletions src-tauri/src/store/in_memory_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,11 @@ impl ModelStore {

model.clear()
}

pub fn delete(&self, key: uuid::Uuid) {
let mut model = self.model.lock().unwrap();
if let Some(dep) = model.clone().iter().find(|a| a.uuid == key) {
model.remove(dep);
};
}
}
50 changes: 44 additions & 6 deletions src/FlatDep.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,52 @@
import { Box, Card, TextField } from "@mui/material";
import { DataGrid, type GridColDef } from "@mui/x-data-grid";
import DeleteIcon from "@mui/icons-material/Delete";
import { Box, Button, Card, TextField } from "@mui/material";
import {
DataGrid,
GridActionsCellItem,
type GridColDef,
GridRowModel,
GridRowSelectionModel,
} from "@mui/x-data-grid";
import { useFlatDeps } from "./FlatStore.ts";
import { type FlatDep, flatDepKey } from "./Represenation.ts";
import {
deleteLocalAndMemoryDep,
loadFromLocal,
loadFromStore,
} from "./commands.ts";

function FlatDepComp(props: {
value: string;
setSearchValue: (searchVal: string) => void;
}) {
const flats = useFlatDeps();
const flatsStore = useFlatDeps();

function deleteSelection(id: string) {
deleteLocalAndMemoryDep(id).then(() => {
loadFromLocal().then(() => {
loadFromStore("").then((flats) => flatsStore.setDeps(flats || []));
});
});
}

const actionCols: GridColDef<FlatDep> = {
field: "actions",
type: "actions",
headerName: "Actions",
width: 100,
cellClassName: "actions",
getActions: ({ id }) => {
return [
<GridActionsCellItem
icon={<DeleteIcon />}
key={id}
label="Delete"
onClick={() => deleteSelection(id.toString())}
color="inherit"
/>,
];
},
};

return (
<>
Expand All @@ -25,10 +64,9 @@ function FlatDepComp(props: {
</Box>
<Box sx={{ height: 700, width: "100%" }}>
<DataGrid
rows={flats.flats}
columns={columns}
rows={flatsStore.flats}
columns={columns.concat(actionCols)}
density="compact"
disableRowSelectionOnClick
getRowId={(row) => flatDepKey(row)}
/>
</Box>
Expand Down
22 changes: 10 additions & 12 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,29 @@ function asFlat(raw: string): FlatDep[] | undefined {
}

export async function loadIntoStore(sourcePath: string) {
const result = await invoke("load_into_store", { name: sourcePath });
console.log("result: ", result);
await invoke("load_into_store", { name: sourcePath });
}

export async function loadFromGithub(org: string, token: string) {
const result = await invoke("load_from_github", { org: org, token: token });
console.log("result: ", result);
await invoke("load_from_github", { org: org, token: token });
}

export async function loadIntoLocal() {
const result = await invoke("load_into_local");
console.log("result: ", result);
await invoke("load_into_local");
}

export async function loadFromLocal() {
const result = await invoke("load_from_local");
console.log("result: ", result);
await invoke("load_from_local");
}

export async function deleteLocal() {
const result = await invoke("delete_local");
console.log("result: ", result);
await invoke("delete_local");
}

export async function deleteMemory() {
const result = await invoke("delete_memory");
console.log("result: ", result);
await invoke("delete_memory");
}

export async function deleteLocalAndMemoryDep(key: string) {
await invoke("delete_local_and_memory_dep", { depId: key });
}

0 comments on commit 99b3417

Please sign in to comment.