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

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
raisfeld-ori committed Mar 5, 2024
2 parents 06155ce + f86dedc commit 6589718
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 40 deletions.
108 changes: 75 additions & 33 deletions src-tauri/src/fs/fake.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

use serde::{Serialize, Deserialize};
use tauri::api::file;

pub static mut FS: Home = Home::new();

Expand All @@ -18,48 +19,43 @@ pub struct Directory{
// impl for Directory with function that only Directory have.
impl Directory {
fn new(name: String) -> Self{Self{name, directories: Box::new(Vec::new()), files: Vec::new()}}

}
// impl the directory trait for Directory struct because he needs these commands.
impl DirTrait for Directory{
fn mkdir(&mut self, dir: String) {self.directories.push(Directory::new(dir))}

fn rmdir(&mut self, dir: String) -> Result<(), Option<String>> {
let index = self.directories.iter().position(|d| d.name == dir);
match index {
Some(idx) => {
self.directories.remove(idx);
Ok(())
},
None => Err(Some(format!("Directory '{}' not found", dir)))
}
fn find_file(&self, file_name: &str) -> Option<&File> {
self.files.iter().find(|file| file.name == file_name)
}
fn cd(&mut self, dir: String) -> Result<&Directory, String> {
for directory in &mut self.directories.iter() {
if directory.name == dir {
return Ok(directory);
}
}
Err(format!("Directory '{}' not found", dir))
fn add_file(&mut self, file_name: String, content: Vec<u8>) -> Option<()> {
let extension = self.get_file_extension(&file_name).unwrap_or("".to_string());
let new_file = File {
name: file_name,
extension: extension,
data: content,
};
self.files.push(new_file);
Some(())
}
fn get_file_extension(&self,file_name: &str) -> Option<String> {
let last_period_pos = file_name.rfind('.')?;
Some(file_name[last_period_pos + 1..].to_string())
}
}

// impl the directory trait for Directory struct because he needs these commands.

#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize, Deserialize)]
pub struct Home{
pub directories: Vec<Directory>,
pub files: Vec<File>,
pub path: String,
pub current_dir: String,
}
// impl for home with functions that only Home have.
impl Home{
pub const fn new() -> Self{Self { directories: Vec::new(), files: Vec::new(), path: String::new()}}
pub const fn new() -> Self{Self { directories: Vec::new(), files: Vec::new(), path: String::new(), current_dir: String::new()}}
pub fn name(&self) -> String {String::from("Home")}
pub fn pwd(&self) -> String{"Home".to_string() + self.path.as_str()}
}
// impl the directory trait for Home because Home needs these commands.
impl DirTrait for Home {
fn mkdir(&mut self, dir: String) {self.directories.push(Directory::new(dir))}

fn rmdir(&mut self, dir: String) -> Result<(), Option<String>> {
let index = self.directories.iter().position(|d| d.name == dir);
match index{
Expand All @@ -74,24 +70,59 @@ impl DirTrait for Home {
}

}
fn cd(&mut self, dir: String) -> Result<&Directory, String> {
fn cd(&mut self, dir: String) -> Option<&Directory> {
for directory in &mut self.directories.iter() {
if directory.name == dir{
Some(directory);
self.path += "/";
self.path += directory.name.as_str();
return Ok(directory);
self.current_dir = directory.name.clone();
}
}
Err(format!("Directory '{}' not found", dir))
None
}
fn cat(&mut self, file_name: String, content: Option<String>) -> Option<()> {
if let Some(content) = content {
self.add_file(file_name, content.into_bytes().to_vec());
Some(())
} else {
match self.find_file(&file_name) {
Some(file) => {
let content = String::from_utf8(file.data.clone()).unwrap();
println!("{}", content);
Some(())
},
None => None,
}
}
}
fn add_file(&mut self, file_name: String, content: Vec<u8>) -> Option<()> {
self.directories.iter_mut().find(|dir| dir.name == self.current_dir.clone())
.map(|dir| dir.add_file(file_name.clone(), content.clone()))
.unwrap_or_else(|| {
self.directories.push(Directory::new(self.current_dir.clone()));
let mut new_dir = Directory::new(self.current_dir.clone());
new_dir.add_file(file_name, content);
Some(())
})
}
fn find_file(&self, file_name: &str) -> Option<&File> {
for directory in &self.directories {
if let Some(file) = directory.find_file(file_name) {
return Some(file);
}
}
None
}
}
// Trait with commands for all directory structs.
trait DirTrait {
fn mkdir(&mut self, dir: String);
fn rmdir(&mut self, dir: String) -> Result<(), Option<String>>;
fn cd(&mut self, dir: String) -> Result<&Directory, String>;

fn cd(&mut self, dir: String) -> Option<&Directory>;
fn cat(&mut self, file_name: String, content: Option<String>) -> Option<()>;
fn add_file(&mut self, file_name: String, content: Vec<u8>) -> Option<()>;
fn find_file(&self, file_name: &str) -> Option<&File>;
}

// Testing the directory.
Expand All @@ -103,10 +134,21 @@ fn test_directory(){
home.mkdir(dir_name.clone());
assert!(home.rmdir(dir_name.clone()).is_ok());
assert!(home.rmdir(dir_name.clone()).is_err());
match home.cd(dir_name) {
Ok(dir) => println!("Successfully changed to directory: {}", dir.name),
Err(e) => println!("Error {}", e)
}
home.cd(dir_name);
println!("{}", home.pwd());

}
#[test]
fn test_cat() {
let mut home = Home::new();
let file_name = String::from("avivs.txt");
let dir_name = String::from("digma");
let content = None;
home.mkdir(dir_name.clone());
home.cd(dir_name);
home.cat(file_name.clone(), Some(String::from("hello, world")));
println!("{}", file_name);
home.cat(file_name, content);
println!("{}", home.pwd());

}
Binary file added src/assets/OK-I-PULL-UP.ogg
Binary file not shown.
Binary file added src/assets/Okiupp.mp3
Binary file not shown.
Binary file added src/assets/alpha.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/daddyishome.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 24 additions & 3 deletions src/pages/login/loading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { invoke } from '@tauri-apps/api';
import { useState } from 'react';
// import { useNavigate } from 'react-router-dom';
import { useLocation } from 'react-router-dom';
import miku from '../../assets/alpha.png';
import pullup from '../../assets/Okiupp.mp3';
import okpullup from '../../assets/OK-I-PULL-UP.ogg';


// loading the page requires a username and a password
function loading(){
Expand All @@ -11,13 +15,30 @@ function loading(){
if (!location.state){return <h1>DONT ACCESS THIS PAGE WITHOUT LOGGING IN</h1>}
document.addEventListener('rust_event', () => {invoke("printf", {value: "yiipee"})});
function run_loading(){invoke("load_user", location.state);}

Check failure on line 17 in src/pages/login/loading.tsx

View workflow job for this annotation

GitHub Actions / build (windows-latest)

'run_loading' is declared but its value is never read.
document.addEventListener('rust_event', () => {});
invoke("user_", location.state);


return <div id='background'>

<div className='triangle down'></div>
<div className='triangle left'></div>
<div id='user'>
<p>{value}</p>
<h1>welcome {location.state.name}!</h1>
<p>pfp will be here</p>
<button onClick={run_loading} className='upperbutton'>start loading</button>
<progress max={10} value={1}></progress>

<div className="dot">
<img src={miku} alt="Descriptive text" />
</div>
<h1>kys</h1>
<progress className='rotating' max={10} value={1}></progress>
<p id='melody'>enjoy this melody while ori is fixing the progress bar</p>
<audio controls autoPlay>
<source src={okpullup} type="audio/ogg" />
<source src={pullup} type="audio/mpeg" />
Your browser does not support the audio element.
</audio>

</div>
</div>
}
Expand Down
80 changes: 76 additions & 4 deletions src/pages/login/login.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,19 @@
height: 0;
position: absolute;
z-index: -1;

}
animation-duration: 2s;
animation-name: slidein;
}

@keyframes slidein {
from {
margin-right: 100%;
}
to {
margin-right: 0%;
}
}


.left{
right: 0;
Expand All @@ -29,14 +40,29 @@
z-index: -2;
}




.down{
position: absolute;
left: -10svw;
border-left: 40svh solid transparent;
border-right: 40svh solid transparent;
border-top: 110svh solid #4359CD;
z-index: -2;
}
animation-duration: 2s;
animation-name: turtle;
}

@keyframes turtle {
from {
margin-left: 100%;
}
to {
margin-left: 0%;
}
}


.dot {
height: 170px;
Expand Down Expand Up @@ -70,7 +96,7 @@
#form{
display: block;
font-family: 'Ubuntu Mono';
margin-top: 13svh;
margin-top: 12svh;
}


Expand Down Expand Up @@ -153,6 +179,13 @@
font-size: 2svh;
}

#melody {
font-weight: bold;
margin-top: 10svh;
color: #0f0000;
font-size: 2svh;
}

/* --------------------- SIGNUP ---------------------*/

.input {
Expand Down Expand Up @@ -280,3 +313,42 @@
color: #fff;
}





@-webkit-keyframes rotating /* Safari and Chrome */ {
from {
-webkit-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
}
to {
-webkit-transform: rotate(360deg);
-o-transform: rotate(360deg);
transform: rotate(360deg);
}
}
@keyframes rotating {
from {
-ms-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-webkit-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
}
to {
-ms-transform: rotate(360deg);
-moz-transform: rotate(360deg);
-webkit-transform: rotate(360deg);
-o-transform: rotate(360deg);
transform: rotate(360deg);
}
}
.rotating {
-webkit-animation: rotating 2s linear infinite;
-moz-animation: rotating 2s linear infinite;
-ms-animation: rotating 2s linear infinite;
-o-animation: rotating 2s linear infinite;
animation: rotating 2s linear infinite;
}

0 comments on commit 6589718

Please sign in to comment.