Skip to content

Commit

Permalink
now if you drag and drop a task into a new location (group), it stays…
Browse files Browse the repository at this point in the history
… there even when you close and open the app
  • Loading branch information
Piyuuussshhh committed Jul 2, 2024
1 parent 1a8b966 commit ceda259
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src-tauri/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,20 @@ pub mod ops {
}
}

#[tauri::command(rename_all = "snake_case")]
pub fn update_item(table: &str, id: u64, new_parent_group_id: u64) {
let db = DB_SINGLETON.lock().unwrap();

if let Some(conn) = &db.db_conn {
let command = format!("UPDATE {table} SET parent_group_id=(?1) WHERE id=(?2)");

match conn.execute(&command, params![new_parent_group_id, id]) {
Ok(_) => (),
Err(err) => println!("[ERROR] Could not update task: {}", err.to_string()),
}
}
}

/* ----------------------------------------------------------------------------- */
/* -------------------------------HELPER FUNCTIONS------------------------------ */
/* ----------------------------------------------------------------------------- */
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ fn main() {
ops::commands::add_item,
ops::commands::delete_item,
ops::commands::edit_item,
ops::commands::update_item,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
Expand Down
2 changes: 2 additions & 0 deletions src/Constants.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const TAURI_FETCH_TASKS_VIEW = "get_tasks_view";
const TAURI_ADD_ITEM = "add_item";
const TAURI_DELETE_ITEM = "delete_item";
const TAURI_EDIT_ITEM = "edit_item";
const TAURI_UPDATE_ITEM = "update_item";

export {
// Table names
Expand All @@ -32,4 +33,5 @@ export {
TAURI_ADD_ITEM,
TAURI_DELETE_ITEM,
TAURI_EDIT_ITEM,
TAURI_UPDATE_ITEM,
};
9 changes: 8 additions & 1 deletion src/views/TasksView/DragDropContext.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { createContext, useEffect, useState } from "react";
import { invoke } from "@tauri-apps/api";

import { addItem, removeItem } from "../../utility/AddRemoveUpdateItems";
import { TASKS_VIEW } from "../../Constants";
import { TODAY, TASKS_VIEW, TAURI_UPDATE_ITEM } from "../../Constants";

const DragDropContext = createContext();

Expand All @@ -25,6 +26,12 @@ const DragDropProvider = ({ children, item }) => {
// basically event.dataTransfer.getData() always returns a string.
const droppedItemId = Number(event.dataTransfer.getData("text/plain"));

invoke(TAURI_UPDATE_ITEM, {
table: TODAY,
id: droppedItemId,
new_parent_group_id: targetId,
});

setStructure((prevStructure) => {
const newStructure = JSON.parse(JSON.stringify(prevStructure));
removeItem(droppedItemId, newStructure);
Expand Down

0 comments on commit ceda259

Please sign in to comment.