Skip to content
This repository has been archived by the owner on Jan 14, 2025. It is now read-only.

Commit

Permalink
fixed the file uploading
Browse files Browse the repository at this point in the history
  • Loading branch information
raisfeld-ori committed Mar 25, 2024
1 parent 40ed743 commit c8c5b24
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src-tauri/src/fs/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ impl Home{
#[tauri::command]
pub fn mkdir(name: String) {unsafe{FS.current_dir.files.push(DirectoryItems::Directory(Directory::new(name)))};}
#[tauri::command]
pub fn mk(name: &str, password: &str, file_name: String) -> Result<(), String> {
let new_file = File::new(name, password, file_name, unsafe{&FS.current_dir});
pub fn mk(name: &str, password: &str, fileName: String) -> Result<(), String> {
let new_file = File::new(name, password, fileName, unsafe{&FS.current_dir});
if new_file.is_none() {return Err(String::from("a file with this name already exists"));}
unsafe{FS.current_dir.files.push(DirectoryItems::File(new_file.unwrap()))};
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ async fn close_app<R: Runtime>(window: tauri::Window<R>) -> tauri::Result<()> {w
fn main() {
tauri::Builder::default().invoke_handler(tauri::generate_handler![
first_init, console, user_get, authenticate_user, save_user, user_exists, load_user, ls, pwd, cd, create_user,
create_value, mkdir, system_get, system_make, user_make, close_app,
create_value, mkdir, system_get, system_make, user_make, close_app, mk
]).run(tauri::generate_context!()).expect("failed to run the code");
}
11 changes: 5 additions & 6 deletions src/pages/main_page/internal_apps/apps/file_system.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import img from '../../assets/terminal.png';
import { open } from '@tauri-apps/api/dialog';

async function upload_file(update_fs: () => Promise<void>, set_files: React.Dispatch<React.SetStateAction<React.JSX.Element[]>>){
let name: string = await invoke('system_get', {key: 'name'});
let password: string = await invoke('system_get', {key: 'password'});
let file_selected = await open({});
if (Array.isArray(file_selected)){
for (let i = 0; i < file_selected.length;i++){
Expand All @@ -15,9 +17,7 @@ async function upload_file(update_fs: () => Promise<void>, set_files: React.Disp
}
else if (file_selected == null){return;}
else{
console.log('test');
//@ts-expect-error
set_files(files => [...files, <File name={file_selected} key={files.length + 1}/>]);
make_file(name, password, file_selected, FileType.File);
await update_fs();
}
}
Expand All @@ -39,7 +39,7 @@ enum FileType{
async function make_file(name: string, password: string, file: string, type: FileType){
switch (type){
case FileType.Directory: {await invoke('mkdir', {name: file});break;}
case FileType.File: {await invoke('mk', {name, password, file});break;}
case FileType.File: {await invoke('mk', {name, password, fileName: file});break;}
}
}

Expand All @@ -53,7 +53,7 @@ function file_system() : [JSX.Element, React.Dispatch<React.SetStateAction<strin
let pwd: string = await invoke('pwd', {});
let files_divs = [];
for (let i = 0;i < files.length;i++){
files_divs.push(<File name={files[i]} key={'f' + i}/>);
files_divs.push(<File name={files[i]} key={i}/>);
}
set_files(files_divs);
set_location(pwd);
Expand All @@ -74,7 +74,6 @@ function file_system() : [JSX.Element, React.Dispatch<React.SetStateAction<strin
const done_editing = async (e: any) => {
e.preventDefault();
set_editing('none');
console.log(e);
let name: string = await invoke('system_get', {key: 'name'});
let password: string = await invoke('system_get', {key: 'password'});
await make_file(name, password, text, file_type);
Expand Down

0 comments on commit c8c5b24

Please sign in to comment.