Skip to content

Commit

Permalink
Fix UI
Browse files Browse the repository at this point in the history
  • Loading branch information
windoze committed Jan 5, 2024
1 parent 14c43fc commit a2423f1
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@
"cSpell.words": [
"arboard",
"clipsync",
"dioxus",
"evenodd",
"Freqs",
"gethostname",
"jieba",
"libxcb",
"Mmap",
"mqtt",
"oninput",
"onsubmit",
"rumqttc",
"rustls",
"stylesheet",
"tungstenite",
"webbrowser",
"xfixes"
Expand Down
2 changes: 1 addition & 1 deletion 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 Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "clip-sync"
authors = ["Chen Xu <[email protected]>"]
version = "0.2.0"
version = "0.2.1"
edition = "2021"
description = "A clipboard sync tool"
rust-version = "1.75.0"
Expand Down
2 changes: 1 addition & 1 deletion clip-sync-ui/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "clip-sync-ui"
version = "0.1.0"
version = "0.2.1"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
22 changes: 9 additions & 13 deletions clip-sync-ui/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
use std::time::Duration;
use chrono::{Utc, TimeZone};
use dioxus::{
html::GlobalAttributes,
prelude::*,
};
use chrono::{TimeZone, Utc};
use dioxus::{html::GlobalAttributes, prelude::*};
use gloo_timers::future::sleep;
use log::LevelFilter;
use serde::{Deserialize, Serialize};
use gloo_timers::future::sleep;
use std::time::Duration;

pub static BASE_API_URL: &str = "/api";

Expand All @@ -17,7 +14,7 @@ pub fn base_url() -> String {
#[derive(Clone, PartialEq, Eq, Deserialize, Serialize, Debug)]
pub struct ClipboardEntry {
pub source: String,
pub data: String,
pub text: String,
pub timestamp: i64,
}

Expand Down Expand Up @@ -57,7 +54,7 @@ pub fn CopyButton(cx: Scope, text: String) -> Element {
fn Entry(cx: Scope, entry: ClipboardEntry) -> Element {
let ClipboardEntry {
source,
data,
text,
timestamp,
} = entry;
let datetime = Utc.timestamp_opt(*timestamp, 0).unwrap();
Expand All @@ -72,11 +69,11 @@ fn Entry(cx: Scope, entry: ClipboardEntry) -> Element {
class: "min-w-0 flex-auto",
pre {
class: "my_pre",
"{data}"
"{text}"
}
span {
class: "inline-flex items-center px-2 py-1 text-xs font-medium text-gray-600",
CopyButton { text: data.clone() }
CopyButton { text: text.clone() }
}
span {
class: "inline-flex items-center rounded-md bg-yellow-50 px-2 py-1 text-xs font-medium text-yellow-800 ring-1 ring-inset ring-yellow-600/20",
Expand Down Expand Up @@ -136,7 +133,7 @@ pub fn app(cx: Scope) -> Element {
class: "w-5 h-5",
path {
d: "M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"
}
}
}
}
}
Expand Down Expand Up @@ -174,7 +171,6 @@ pub fn app(cx: Scope) -> Element {
value: "{search_input}",
placeholder: "Search for text...",
oninput: move |evt| { search_input.set(evt.value.clone()); entries.restart(); },
// onkeydown: move |evt| { if evt.key() == Key::Enter {} }
}
}
match entries.value() {
Expand Down
27 changes: 26 additions & 1 deletion src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,15 @@ struct ClipboardMessage {
timestamp: i64,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct ServerClipboardData {
pub source: String,
#[serde(flatten)]
pub content: ServerClipboardContent,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum ServerClipboardContent {
Text(String),
ImageUrl(String),
Expand Down Expand Up @@ -395,3 +397,26 @@ pub async fn server_main(mut args: ServerConfig) -> Result<(), std::io::Error> {
}
Ok(())
}

#[cfg(test)]
mod tests {
#[test]
fn test_serde() {
use super::{ServerClipboardContent, ServerClipboardData};
let data = ServerClipboardData {
source: "test".to_string(),
content: ServerClipboardContent::Text("test".to_string()),
};
let json = serde_json::to_string(&data).unwrap();
println!("{}", json);
let data2: ServerClipboardData = serde_json::from_str(&json).unwrap();
assert_eq!(data, data2);

let msg = super::ClipboardMessage {
entry: data,
timestamp: 0,
};
let json = serde_json::to_string(&msg).unwrap();
println!("{}", json);
}
}

0 comments on commit a2423f1

Please sign in to comment.