diff --git a/index.html b/index.html index 51946f2..b660054 100644 --- a/index.html +++ b/index.html @@ -30,6 +30,7 @@ + @@ -67,7 +68,14 @@ - +
+
+
+

Font Size (in px)

+ +
+
+
diff --git a/libsnotes/src/lib.rs b/libsnotes/src/lib.rs index 421b5f4..0c1c487 100644 --- a/libsnotes/src/lib.rs +++ b/libsnotes/src/lib.rs @@ -2,6 +2,8 @@ use chrono::Local; use home::home_dir; use rusqlite::{Connection, Result}; use serde_json::json; +use std::fs; +use std::path::PathBuf; pub struct Note { id: i32, @@ -10,9 +12,19 @@ pub struct Note { tag: String, } +fn get_db_dir() -> PathBuf { + let dir = home_dir().unwrap().join(".snotes-data"); + dbg!(&dir); + if !&dir.exists() { + fs::create_dir(&dir).unwrap(); + } + + dir.join(".snotes.db") +} + pub fn init_db() -> Result<()> { - let home = home_dir().unwrap().join(".snotes.db"); - let connection = Connection::open(home)?; + let db = get_db_dir(); + let connection = Connection::open(db)?; let query_table = " CREATE TABLE IF NOT EXISTS notes ( @@ -32,8 +44,8 @@ pub fn init_db() -> Result<()> { } pub fn create_note(content: &String, tag: &String) -> Result<()> { - let home = home_dir().unwrap().join(".snotes.db"); - let connection = Connection::open(home)?; + let db = get_db_dir(); + let connection = Connection::open(db)?; let date = Local::now(); let date_string = date.format("%m-%d-%y %H:%M").to_string(); let tag_string = if *tag == String::new() { @@ -53,8 +65,8 @@ pub fn create_note(content: &String, tag: &String) -> Result<()> { } pub fn show_notes(all: bool, tag: &str) -> Result { - let home = home_dir().unwrap().join(".snotes.db"); - let connection = Connection::open(home).unwrap(); + let db = get_db_dir(); + let connection = Connection::open(db).unwrap(); let mut query = "SELECT * FROM notes LIMIT 10".to_string(); @@ -98,8 +110,8 @@ pub fn show_notes(all: bool, tag: &str) -> Result { } pub fn delete_latest_note() -> Result<(), String> { - let home = home_dir().unwrap().join(".snotes.db"); - let connection = Connection::open(home).map_err(|e| format!("Database Error: {e}"))?; + let db = get_db_dir(); + let connection = Connection::open(db).map_err(|e| format!("Database Error: {e}"))?; let query = String::from("DELETE FROM NOTES WHERE nid = (SELECT MAX(nid) FROM notes)"); @@ -113,8 +125,8 @@ pub fn delete_latest_note() -> Result<(), String> { } pub fn delete_specific_note(id: i32) -> Result<(), String> { - let home = home_dir().unwrap().join(".snotes.db"); - let connection = Connection::open(home).map_err(|e| format!("Database Error: {e}"))?; + let db = get_db_dir(); + let connection = Connection::open(db).map_err(|e| format!("Database Error: {e}"))?; let query = "DELETE FROM notes WHERE nid = ?1"; match connection.execute(query, [id]) { @@ -125,8 +137,8 @@ pub fn delete_specific_note(id: i32) -> Result<(), String> { } pub fn edit_specific_note(id: i32, tag: &str, content: &str) -> Result<(), String> { - let home = home_dir().unwrap().join(".snotes.db"); - let connection = Connection::open(home).map_err(|e| format!("Database Error: {}", e))?; + let db = get_db_dir(); + let connection = Connection::open(db).map_err(|e| format!("Database Error: {}", e))?; let query = "UPDATE notes SET tag = ?1, content = ?2 WHERE nid = ?3"; match connection.execute(query, [&tag, &content, &id.to_string().as_str()]) { @@ -138,8 +150,8 @@ pub fn edit_specific_note(id: i32, tag: &str, content: &str) -> Result<(), Strin /// Looks for matches in both content and tag. pub fn search_notes(query: &str) -> Result { - let home = home_dir().unwrap().join(".snotes.db"); - let connection = Connection::open(home).map_err(|e| format!("Database Error: {}", e))?; + let db = get_db_dir(); + let connection = Connection::open(db).map_err(|e| format!("Database Error: {}", e))?; let query = format!( "SELECT * FROM notes WHERE nid LIKE '%{}%' OR content LIKE '%{}%' OR tag LIKE '%{}%'", @@ -183,8 +195,8 @@ pub fn search_notes(query: &str) -> Result { /// get latest note /// Returns a json array string of size 1 pub fn get_latest_note() -> Result { - let home = home_dir().unwrap().join(".snotes.db"); - let connection = Connection::open(home).map_err(|e| format!("Database Error: {}", e))?; + let db = get_db_dir(); + let connection = Connection::open(db).map_err(|e| format!("Database Error: {}", e))?; let query = "SELECT * FROM notes WHERE ROWID IN (SELECT max(ROWID) FROM notes); " @@ -224,8 +236,8 @@ pub fn get_latest_note() -> Result { } pub fn get_note_by_id(id: u32) -> Result { - let home = home_dir().unwrap().join(".snotes.db"); - let connection = Connection::open(home).map_err(|e| format!("Database Error: {}", e))?; + let db = get_db_dir(); + let connection = Connection::open(db).map_err(|e| format!("Database Error: {}", e))?; let query = format!("SELECT * FROM notes WHERE nid IS {};", id.to_string()); let mut prepare = connection diff --git a/src/main.ts b/src/main.ts index 0c35e6c..368b205 100644 --- a/src/main.ts +++ b/src/main.ts @@ -145,6 +145,10 @@ window.addEventListener("DOMContentLoaded", async () => { e.preventDefault(); exportNote(createNoteContentEl ? createNoteContentEl.value : null); }) + document.querySelector('#settings-button')?.addEventListener("click", (e) => { + e.preventDefault(); + handleOpenSettingsModal(); + }) // Pressing TAB should insert intends in the editor. // This could potentially cause issues later... @@ -611,3 +615,14 @@ async function exportNote(contents: string | null) { } } +function handleOpenSettingsModal() { + const modalBg = document.getElementById("id-modal-bg"); + const setingsModalContainer = document.getElementById("settings-modal-container"); + const settingsFontsizeInput = document.getElementById("fontsize-setting-input"); + if (modalBg && setingsModalContainer && settingsFontsizeInput) { + console.log("settings") + } else { + console.error("Failed to get Settings Modal elements."); + } +} + diff --git a/src/styles.css b/src/styles.css index ffa7e96..80e0ba6 100644 --- a/src/styles.css +++ b/src/styles.css @@ -264,6 +264,17 @@ button { z-index: 3; } +#settings-modal-container { + display: none; + + position: fixed; + + margin-top: 20%; + margin-left: 50%; + + z-index: 4; +} + /* MISC */ /* Fancier Scrollbar */