Skip to content

Commit

Permalink
Fix home screen selection
Browse files Browse the repository at this point in the history
  • Loading branch information
iankressin committed Mar 9, 2021
1 parent e4735c7 commit 595d6b0
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src-tauri/Cargo.lock

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/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ serde_json = "1.0"
serde = { version = "1.0", features = [ "derive" ] }
tauri = { version = "0.11", features = [ "all-api" ] }
sha-1 = "0.9.3"
hana-server = "0.1.5"
hana-server = "0.1.6"
hana-client = "0.1.2"
hana-types = "0.1.0"
regex = "1"
Expand Down
5 changes: 5 additions & 0 deletions src-tauri/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,9 @@ pub enum Cmd {
callback: String,
error: String,
},

HasDirs {
callback: String,
error: String,
}
}
15 changes: 15 additions & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,21 @@ fn main() {
callback,
error,
),

HasDirs {
callback,
error,
} => tauri::execute_promise(
_webview,
move || {
match meta_handler::MetaHandler::has_dirs() {
Ok(dirs) => Ok(dirs),
Err(err) => Err(err.into()),
}
},
callback,
error,
),
}
Ok(())
}
Expand Down
19 changes: 12 additions & 7 deletions src-tauri/src/meta_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,25 @@ impl MetaHandler {
Ok(records)
}

pub fn update(path: &str) -> Result<(), std::io::Error> {
let json = serde_json::to_string(&MetaHandler::get_folder_metada(path).unwrap())?;
fs::write(&format!("{}/.hana/metadata.json", path), &json).unwrap();

Ok(())
}

pub fn get_dirs_record_as_vec() -> Result<Vec<(String, String)>, Error> {
let dirs = MetaHandler::get_dirs_record().unwrap();
let dirs = dirs.into_iter().map(|(name, path)| (name, path)).collect();

Ok(dirs)
}

pub fn has_dirs() -> Result<bool, Error> {
let dirs = MetaHandler::get_dirs_record().unwrap();
Ok(!dirs.is_empty())
}

pub fn update(path: &str) -> Result<(), std::io::Error> {
let json = serde_json::to_string(&MetaHandler::get_folder_metada(path).unwrap())?;
fs::write(&format!("{}/.hana/metadata.json", path), &json).unwrap();

Ok(())
}

pub fn get_metadata(path: &str) -> Result<Vec<Metadata>, Error> {
let bytes = fs::read(&format!("{}/.hana/metadata.json", path)).unwrap();
let json = String::from_utf8_lossy(&bytes);
Expand Down
24 changes: 20 additions & 4 deletions src/config/Routes.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
import React from "react";
import React, { useState, useEffect } from "react";
import { BrowserRouter as Router, Switch, Route } from "react-router-dom";
import { message } from "antd";
import { promisified } from "tauri/api/tauri";

import New from "../pages/New";
import FoldersList from "../pages/FoldersList";
import Folder from "../pages/Folder";

const Routes = () => {
const hasFolderSet = localStorage.getItem("hasFolder");
console.log(hasFolderSet);
const [hasDirs, setHasDirs] = useState(false);

useEffect(() => checkDirs(), []);

const checkDirs = async () => {
try {
const hasDirs = await promisified({
cmd: "hasDirs"
});
console.log("Has dirs: ", hasDirs);
setHasDirs(hasDirs);
} catch (error) {
message.error(error);
console.log(error);
}
};

return (
<Router>
Expand All @@ -24,7 +40,7 @@ const Routes = () => {
<FoldersList />
</Route>

<Route path="/">{hasFolderSet ? <FoldersList /> : <New />}</Route>
<Route path="/">{hasDirs ? <FoldersList /> : <New />}</Route>
</Switch>
</Router>
);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/New.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const New = () => {
<h1 className="text-8xl">🐶</h1>
<h1 className="text-6xl"> Welcome to Hana!</h1>
<h3 className="text-2xl mb-8">
First, lets pick a location to initialize as a Hana folder
First, let's pick a location to initialize as a Hana folder
</h3>
<NewFolderButton
size="w-80"
Expand Down

0 comments on commit 595d6b0

Please sign in to comment.