Skip to content
This repository has been archived by the owner on Aug 24, 2024. It is now read-only.

Commit

Permalink
Migration (#81)
Browse files Browse the repository at this point in the history
* return an Element instead LazyNodes

* migrate props and make code more readable

* migrate props

* migrate props and use i18n directly as values

* migrate props, use i18n directly and remove duplicated code

* migrate dioxus, use i18n directly and remove duplicated code

* migrate dioxus

* migrate dioxus and use i18n directly as values (#77)

* update dependencies (#71)

* remove duplicated logger

* feat: register as guest

* Room interaction (#66)

* feat: room interaction

* resolve conflict

* minor change
  • Loading branch information
b-avb authored Apr 10, 2024
1 parent 156092d commit 9afdbbf
Show file tree
Hide file tree
Showing 101 changed files with 4,194 additions and 4,818 deletions.
842 changes: 681 additions & 161 deletions Cargo.lock

Large diffs are not rendered by default.

46 changes: 38 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,60 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
dioxus = "0.4"
dioxus-web = "0.4"
dioxus-router = "0.4.0"
dioxus = { version = "0.5.0", features = ["web"] }
dioxus-router = "0.5.0"
dioxus-logger = "0.4.1"
dioxus-std = { git = "https://github.com/DioxusLabs/dioxus-std", branch = "master", features = [
"i18n",
] }

futures-util = "0.3.27"
futures = "0.3"
gloo = "0.8.0"
log = "0.4.17"
matrix-sdk = { version = "0.6.2", default-features = false, features = ["js", "native-tls", "e2e-encryption", "indexeddb", "experimental-timeline"] }
matrix-sdk = { version = "0.6.2", default-features = false, features = [
"js",
"native-tls",
"e2e-encryption",
"indexeddb",
"experimental-timeline",
] }
tokio = "1.27.0"
url = "2.3.1"
web-sys = {version = "0.3.61", features = ["Document", "Element", "HtmlElement", "HtmlBodyElement", "Node", "NodeList", "Window", "console", "CssStyleDeclaration", "Location", "Navigator"]}
web-sys = { version = "0.3.61", features = [
"Document",
"Element",
"HtmlElement",
"HtmlBodyElement",
"Node",
"NodeList",
"Window",
"console",
"CssStyleDeclaration",
"Location",
"Navigator",
] }
time = "0.3.22"
anyhow = "1"
serde = { version = "1.0.96", features = ["derive"] }
mime = "0.3.17"
js-sys = "0.3.64"
wasm-bindgen = "0.2.55"
dioxus-std = { version = "0.4.0", features = ["i18n"] }
serde_json = "1.0.103"
chrono = "0.4.26"
infer = "0.15.0"
ruma = { version = "0.7.4", features = ["unstable-sanitize", "unstable-msc2677", "unstable-msc3440", "client", "events"] }
ruma = { version = "0.7.4", features = [
"unstable-sanitize",
"unstable-msc2677",
"unstable-msc3440",
"client",
"events",
] }
uuid = "0.8"
unic-langid = "0.9.1"
reqwest = "0.11"
http = "0.2"

log = "0.4.19"
console_error_panic_hook = "0.1.7"
wasm-logger = "0.2.0"
format = "0.2.4"
62 changes: 30 additions & 32 deletions src/components/atoms/attach.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,56 @@ use crate::{
utils::get_element::GetElement,
};

pub enum AttachType<'a> {
#[derive(PartialEq, Debug, Clone)]
pub enum AttachType {
Button,
Avatar(Element<'a>),
Avatar(Element),
}

#[derive(Debug)]
#[derive(PartialEq, Debug, Clone)]
pub struct AttachEvent {
pub value: Vec<u8>,
}

#[derive(Props)]
pub struct AttachProps<'a> {
#[derive(PartialEq, Props, Clone)]
pub struct AttachProps {
#[props(default = AttachType::Button)]
atype: AttachType<'a>,
on_click: EventHandler<'a, Event<FormData>>,
atype: AttachType,
on_click: EventHandler<Event<FormData>>,
}

pub fn Attach<'a>(cx: Scope<'a, AttachProps<'a>>) -> Element<'a> {
pub fn Attach(props: AttachProps) -> Element {
let on_handle_attach = move |_| {
let element = GetElement::<web_sys::HtmlInputElement>::get_element_by_id("input_file");

element.click();
};

cx.render(rsx!(
match &cx.props.atype {
AttachType::Button =>
rsx!(
button {
class: "attach attach--button",
onclick: on_handle_attach,
Icon {
stroke: "var(--icon-white)",
icon: Attachment
}
rsx!(
match &props.atype {
AttachType::Button => rsx!(
button {
class: "attach attach--button",
onclick: on_handle_attach,
Icon {
stroke: "var(--icon-white)",
icon: Attachment
}
),
AttachType::Avatar(element) =>
rsx!(
button {
class: "attach attach--avatar",
onclick: on_handle_attach,
element
}
),
}

}
),
AttachType::Avatar(element) => rsx!(
button {
class: "attach attach--avatar",
onclick: on_handle_attach,
{element}
}
),
},
input {
r#type: "file",
id: "input_file",
class: "attach__input",
oninput: move |event| cx.props.on_click.call(event)
oninput: move |event| props.on_click.call(event)
}
))
)
}
55 changes: 26 additions & 29 deletions src/components/atoms/avatar.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use dioxus::prelude::*;

#[derive(PartialEq)]
#[derive(PartialEq, Clone)]
pub enum Variant {
Round,
SemiRound,
}

#[derive(PartialEq, Props)]
#[derive(PartialEq, Props, Clone)]
pub struct AvatarProps {
name: String,
size: u8,
Expand All @@ -16,39 +16,36 @@ pub struct AvatarProps {
variant: Variant,
}

pub fn Avatar(cx: Scope<AvatarProps>) -> Element {
let size_avatar = format!("--avatar-size: {}px;", cx.props.size);
pub fn Avatar(props: AvatarProps) -> Element {
let size_avatar = format!("--avatar-size: {}px;", props.size);
let avatar_style = format!("{}", size_avatar);

let variant = match cx.props.variant {
let variant = match props.variant {
Variant::Round => "avatar--round",
Variant::SemiRound => "avatar--semi-round",
};

cx.render(rsx! {
match &cx.props.uri {
Some(uri)=> rsx!(
img {
class: "avatar {variant}",
style: "{avatar_style}",
src: "{uri}"
}
),
None=>{
let initial: Vec<char> = cx.props.name.chars().collect();
let initial = initial[0].to_uppercase();

rsx!(
div{
class: "avatar {variant}",
style: "{avatar_style}",
span{
class: "avatar--initial",
"{initial}"
rsx! {
match &props.uri {
Some(uri) => rsx!(
img {
class: "avatar {variant}",
style: "{avatar_style}",
src: "{uri}"
}
}
)
}
),
None => {
let initial: Vec<char> = props.name.chars().collect();
let initial = initial[0].to_uppercase();

rsx!(
div{
class: "avatar {variant}",
style: "{avatar_style}",
span{ class: "avatar--initial", "{initial}" }
}
)
}
}
})
}
}
45 changes: 20 additions & 25 deletions src/components/atoms/button.rs
Original file line number Diff line number Diff line change
@@ -1,61 +1,56 @@
use dioxus::prelude::*;

#[derive(PartialEq, Clone)]
pub enum Variant {
Primary,
Secondary,
Tertiary,
}

#[derive(Props)]
pub struct ButtonProps<'a> {
text: &'a str,
#[props(default = &Variant::Primary)]
variant: &'a Variant,
#[derive(PartialEq, Props, Clone)]
pub struct ButtonProps {
text: String,
#[props(default = Variant::Primary)]
variant: Variant,
#[props(default = false)]
disabled: bool,
on_click: EventHandler<'a, MouseEvent>,
on_click: EventHandler<MouseEvent>,
#[props(!optional)]
status: Option<String>,
}

pub fn Button<'a>(cx: Scope<'a, ButtonProps<'a>>) -> Element<'a> {
let variant = match cx.props.variant {
pub fn Button(props: ButtonProps) -> Element {
let variant = match props.variant {
Variant::Primary => "button--primary",
Variant::Secondary => "button--secondary",
Variant::Tertiary => "button--tertiary",
};

let disabled = if cx.props.disabled {
let disabled = if props.disabled {
"button--disabled"
} else {
""
};

let loading = if cx.props.status.is_some() {
let loading = if props.status.is_some() {
"button--loading"
} else {
""
};

match &cx.props.status {
match &props.status {
Some(s) => {
render!(rsx!(
button {
class: "button {variant} {loading}",
disabled: true,
"{s}"
}
))
rsx!( button { class: "button {variant} {loading}", disabled: true, "{s}" } )
}
None => {
render!(rsx!(
rsx!(
button {
class: "button {variant} {disabled}",
disabled: cx.props.disabled,
onclick: move |event| cx.props.on_click.call(event),
"{cx.props.text}"
}
))
class: "button {variant} {disabled}",
disabled: props.disabled,
onclick: move |event| props.on_click.call(event),
"{props.text}"
}
)
}
}
}
33 changes: 12 additions & 21 deletions src/components/atoms/card.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,24 @@
use crate::components::atoms::{Close, Icon};
use dioxus::prelude::*;

#[derive(Props)]
pub struct CardProps<'a> {
file: &'a str,
on_click: EventHandler<'a, MouseEvent>,
#[derive(PartialEq, Props, Clone)]
pub struct CardProps {
file: String,
on_click: EventHandler<MouseEvent>,
}

pub fn Card<'a>(cx: Scope<'a, CardProps<'a>>) -> Element<'a> {
cx.render(rsx!(
section {
class: "card",
onclick: move |event| cx.props.on_click.call(event),
div {
class: "card-container",
img {
class: "card__media",
src: "{cx.props.file}"
}
pub fn Card(props: CardProps) -> Element {
rsx!(
section { class: "card", onclick: move |event| props.on_click.call(event),
div { class: "card-container",
img { class: "card__media", src: "{props.file}" }

button {
class: "card__cta",
onclick: move |event| {cx.props.on_click.call(event)},
Icon {
stroke: "var(--text-1)",
icon: Close
}
onclick: move |event| { props.on_click.call(event) },
Icon { stroke: "var(--text-1)", icon: Close }
}
}
}
))
)
}
Loading

0 comments on commit 9afdbbf

Please sign in to comment.