Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ axum = "0.8"
cfg-if = "1.0"
chrono = { version = "0.4", features = ["serde"] }
dotenvy = "0.15"
rapidfuzz = "0.5"
rs-fsrs = "1.2"
serde = { version = "1.0", features = ["derive"] }
server_fn = { version = "0.8", default-features = false, features = ["axum", "reqwest"] }
Expand All @@ -22,6 +23,7 @@ thiserror = "2.0"
tokio = { version = "1.48", features = ["full"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
uuid = { version = "1.20", features = ["v4"] }
xilem = { git = "https://github.com/linebender/xilem" }

kreqo-core = { path = "./core" }
Expand Down
15 changes: 9 additions & 6 deletions apps/learn/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use kreqo_core::User;
use kreqo_ui::component::{AsyncList, UserStorage};
use kreqo_ui::component::AsyncList;
use kreqo_ui::theme::BACKGROUND_COLOR;
use kreqo_ui::user_list::UserStorage;
use xilem::core::map_state;
use xilem::masonry::layout::AsUnit;
use xilem::masonry::layout::{AsUnit, Dim};
use xilem::style::Style;
use xilem::view::{FlexExt, MainAxisAlignment, flex_col, flex_row, sized_box};
use xilem::view::{FlexExt, MainAxisAlignment, flex_col, flex_row, portal, sized_box};
use xilem::{WindowId, WindowView, window};

pub struct AppState {
Expand All @@ -18,7 +19,7 @@ impl Default for AppState {
Self {
running: true,
main_window_id: WindowId::next(),
user_list: Default::default(),
user_list: AsyncList::new(true, true),
}
}
}
Expand All @@ -33,14 +34,16 @@ impl AppState {
pub fn logic(&mut self) -> impl Iterator<Item = WindowView<AppState>> + use<> {
let user_list = flex_row(sized_box(self.user_list.view()).width(600.px()))
.main_axis_alignment(MainAxisAlignment::Center)
.flex(1.);
.width(Dim::Stretch)
.padding(15.);
let error = self.user_list.error_view().map(|error_view| {
flex_row(error_view)
.main_axis_alignment(MainAxisAlignment::Center)
.padding(15.)
});
let portal = portal(user_list).flex(1.);
let content = map_state(
flex_col((user_list, error)).gap(0.px()),
flex_col((portal, error)).gap(0.px()),
|state: &mut AppState, ()| &mut state.user_list,
);
std::iter::once(
Expand Down
18 changes: 18 additions & 0 deletions server/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ use server_fn_macro_default::server;
pub async fn get_users() -> Result<Vec<User>, ServerError> {
let pool = &*DB;

#[cfg(debug_assertions)]
std::thread::sleep(std::time::Duration::from_millis(500));

Ok(sqlx::query_as!(User, "SELECT * FROM users")
.fetch_all(pool)
.await?)
Expand All @@ -24,6 +27,9 @@ pub async fn get_users() -> Result<Vec<User>, ServerError> {
pub async fn get_user(id: i64) -> Result<User, ServerError> {
let pool = &*DB;

#[cfg(debug_assertions)]
std::thread::sleep(std::time::Duration::from_millis(500));

Ok(
sqlx::query_as!(User, "SELECT * FROM users WHERE id = $1", id)
.fetch_one(pool)
Expand All @@ -35,6 +41,9 @@ pub async fn get_user(id: i64) -> Result<User, ServerError> {
pub async fn get_user_from_username(username: String) -> Result<User, ServerError> {
let pool = &*DB;

#[cfg(debug_assertions)]
std::thread::sleep(std::time::Duration::from_millis(500));

Ok(
sqlx::query_as!(User, "SELECT * FROM users WHERE username = $1", username)
.fetch_one(pool)
Expand All @@ -46,6 +55,9 @@ pub async fn get_user_from_username(username: String) -> Result<User, ServerErro
pub async fn create_user(username: String, password: String) -> Result<User, ServerError> {
let pool = &*DB;

#[cfg(debug_assertions)]
std::thread::sleep(std::time::Duration::from_millis(500));

let salt = SaltString::generate(&mut OsRng);
let password_hashed = Argon2::default()
.hash_password(password.as_bytes(), &salt)?
Expand All @@ -69,6 +81,9 @@ pub async fn create_user(username: String, password: String) -> Result<User, Ser
pub async fn update_user_username(id: i64, username: String) -> Result<User, ServerError> {
let pool = &*DB;

#[cfg(debug_assertions)]
std::thread::sleep(std::time::Duration::from_millis(500));

let id = sqlx::query_scalar!(
"UPDATE users SET username = $2 WHERE id = $1 RETURNING id",
id,
Expand All @@ -86,6 +101,9 @@ pub async fn update_user_username(id: i64, username: String) -> Result<User, Ser
pub async fn delete_user(id: i64) -> Result<i64, ServerError> {
let pool = &*DB;

#[cfg(debug_assertions)]
std::thread::sleep(std::time::Duration::from_millis(500));

Ok(
sqlx::query_scalar!("DELETE FROM users WHERE id = $1 RETURNING id", id)
.fetch_one(pool)
Expand Down
3 changes: 3 additions & 0 deletions ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ version = "0.0.0"
edition.workspace = true

[dependencies]
rapidfuzz.workspace = true
server_fn.workspace = true
thiserror.workspace = true
uuid.workspace = true
xilem.workspace = true

kreqo-core.workspace = true
Expand Down
1 change: 0 additions & 1 deletion ui/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ pub mod list;
pub use error::ErrorView;
pub use form::Form;
pub use list::AsyncList;
pub use list::user_item::*;
Loading