Skip to content

Commit

Permalink
feat: sort bucket files by modified time(desc)
Browse files Browse the repository at this point in the history
  • Loading branch information
msyfls123 committed Apr 14, 2024
1 parent 366f91c commit 0f9c094
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ wasm-bindgen-futures = "0.4.29"
yew-router = "0.18.0"
serde = "1.0.136"
serde-wasm-bindgen = "0.6.5"
chrono = { version = "0.4.37", features = ["wasmbind", "js-sys"] }

[dependencies.web-sys]
version = "0.3.57"
Expand Down
18 changes: 17 additions & 1 deletion client/src/component/bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ use yew::{prelude::function_component, Html, html, use_context, use_state, use_e
use web_sys::{console};
use serde_wasm_bindgen::from_value;
use serde::{Deserialize};
use chrono::{Utc, DateTime};

use crate::constants::app::AppContext;

#[derive(Deserialize, PartialEq, Clone)]
pub struct File {
Key: Value,
Size: Value,
LastModified: Value,
}

#[derive(Deserialize)]
Expand Down Expand Up @@ -51,8 +53,13 @@ pub fn bucket(props: &BucketProps) -> Html {
let promise = Promise::from(result);
let data = JsFuture::from(promise).await.unwrap();
console::log_2(&JsValue::from_str("data"), &data);

let info: BucketInfo = from_value(data).unwrap();
list_clone.set(Some(info.Contents));
let mut contents = info.Contents;
contents.sort_by_key(|file| file.LastModified.as_str().unwrap().parse::<DateTime<Utc>>().unwrap());
contents.reverse();
list_clone.set(Some(contents));

fetched_clone.set(1);
is_loading_clone.set(false);
});
Expand Down Expand Up @@ -85,6 +92,7 @@ pub fn bucket(props: &BucketProps) -> Html {
<tr>
<th>{"File"}</th>
<th>{"Size (bytes)"}</th>
<th>{"Modified Time"}</th>
</tr>
</thead>
<tbody>
Expand All @@ -107,6 +115,11 @@ fn file_item(file: &File) -> Html {
let file_size = file.Size.as_str().unwrap();
let href = format!("https://cdn.ebichu.cc/{}", file.Key.as_str().unwrap());
let file_key2 = file.Key.clone();

let time = file.LastModified.as_str().unwrap();
let time_parsed: DateTime<Utc> = time.parse().unwrap();
let time_display = format!("{}", time_parsed.format("%Y-%m-%d %H:%M:%S"));

html! { <tr>
<td>
<a href={href.to_owned()} target="_blank">
Expand All @@ -116,5 +129,8 @@ fn file_item(file: &File) -> Html {
<td>
{file_size}
</td>
<td>
{time_display}
</td>
</tr> }
}
7 changes: 7 additions & 0 deletions client/src/css/index.styl
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@ nav

.hidden
display: none

@font-face
font-family: Yuewen Font
src: url('https://stawritecdn.yuewen.com/assets/design/fonts/YuewenFont-Regular.678a92.otf') format('opentype')

body
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica Neue, Helvetica, Arial, PingFang SC, Hiragino Sans GB, STHeiti, Droid Sans Fallback, Droid Sans, Microsoft YaHei, Source Han Sans SC, Noto Sans CJK SC, WenQuanYi Micro Hei, sans-serif

0 comments on commit 0f9c094

Please sign in to comment.