Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Eason0729 committed Jun 30, 2024
2 parents 07638bb + 9222580 commit 1da7bcd
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 72 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"Frontend",
"Backend",
"Judger",
"Testsuit"
"Testsuit",
"Grpc"
],
}
9 changes: 4 additions & 5 deletions frontend/src/components/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ pub fn Button(
disabled=disabled
id=id
on:click=move |e| {
on_click
.map(|f| {
e.stop_propagation();
f(e);
});
if let Some(f) = on_click {
e.stop_propagation();
f(e);
}
}
>

Expand Down
2 changes: 2 additions & 0 deletions frontend/src/components/modal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ pub fn Modal(
#[prop(into, optional)] on_close: Option<Callback<MouseEvent>>,
children: Children,
) -> impl IntoView {
// FIXME: what is level for? color?
let _level = level;
view! {
<dialog open>
{children()}
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/components/select.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use leptos::*;

use crate::components::Merge;

#[derive(Debug, Clone, PartialEq, Eq)]
struct SelectedValue(ReadSignal<String>);

Expand All @@ -15,7 +17,7 @@ pub fn Select(
provide_context(SelectedValue(get));
view! {
<select
class="text-text bg-background rounded-md p-2"
class=Merge(class, "text-text bg-background rounded-md p-2")
id=id
on:change=move |e| set(event_target_value(&e))
>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/text_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub fn TextInput(
class,
"text-text outline-none p-2 bg-background border-2 rounded-md border-background focus:border-primary transition-colors duration-300",
)

id=id
type=kind
prop:value=get
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/components/toggle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ pub fn Toggle(
) -> impl IntoView {
let (get, set) = value.split();
view! {
<label class=Merge(class,"inline-flex items-center cursor-pointer")>
<label class=Merge(class, "inline-flex items-center cursor-pointer")>
<input
type=kind
id=id
prop:value=get
class="sr-only peer"
on:input=move |e| set(event_target_value(&e)=="true")
type=kind
id=id
prop:value=get
class="sr-only peer"
on:input=move |e| set(event_target_value(&e) == "true")
/>
<div class="relative w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-blue-300 dark:peer-focus:ring-blue-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-blue-600"></div>
</label>
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#[cfg(feature = "ssr")]
use std::sync::OnceLock;

use cfg_if::cfg_if;
use leptos::*;
use leptos_use::{utils::JsonCodec, *};
use serde::{Deserialize, Serialize};
use tonic::{IntoRequest, Request};

use crate::{error::*, grpc};

#[cfg(feature = "ssr")]
use std::sync::OnceLock;
#[cfg(feature = "ssr")]
static CONFIG: OnceLock<GlobalConfig> = OnceLock::new();

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/problem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn Problem() -> impl IntoView {
});

let submit_langs =
create_resource(id_and_token, |(id, token)| async move {
create_resource(id_and_token, |(_id, token)| async move {
let mut client = submit_set_client::SubmitSetClient::new(
grpc::new_client().await?,
);
Expand Down
136 changes: 83 additions & 53 deletions frontend/src/pages/problems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ pub fn ProblemSearch() -> impl IntoView {
let start_from_end = create_rw_signal(false);
let sort_by = create_rw_signal((ProblemSortBy::AcRate as i32).to_string());

let submit = Memo::new(move |_| {
// FIXME: What is this?
let _submit = Memo::new(move |_| {
let start_from_end = start_from_end.get();
let text = filter_text.get();
let sort_by: ProblemSortBy = sort_by
Expand Down Expand Up @@ -337,7 +338,7 @@ pub fn ProblemSearch() -> impl IntoView {
<SelectOption value="4">Difficulty</SelectOption>
<SelectOption value="6">Public</SelectOption>
</Select>
// a form with a text input and a dropdown list and a toggle
// a form with a text input and a dropdown list and a toggle

</div>
}
Expand All @@ -351,9 +352,12 @@ pub fn ProblemList() -> impl IntoView {
_ => "red",
};
view! {
<span class=format!("bg-{} text-{} text-xs font-medium me-2 px-2.5 py-0.5 rounded border border-{}", color, color, color)>
{difficulty}
</span>
<span class=format!(
"bg-{} text-{} text-xs font-medium me-2 px-2.5 py-0.5 rounded border border-{}",
color,
color,
color,
)>{difficulty}</span>
}
}

Expand All @@ -364,59 +368,85 @@ pub fn ProblemList() -> impl IntoView {
<Transition fallback=move || {
view! { <p>Loading</p> }
}>
{move || {
r.get()
.map(|v| v.map(|v|view!{
<div class="table w-full table-auto">
<div class="table-header-group text-left">
<div class="table-row">
<div class="table-cell">Title</div>
<div class="hidden md:table-cell">AC Rate</div>
<div class="hidden md:table-cell">Attempt</div>
<div class="table-cell">Difficulty</div>
</div>
</div>
<div class="table-row-group" style="line-height: 3rem">
{
v.list.into_iter().map(|info| {
{move || {
r.get()
.map(|v| {
v
.map(|v| {
view! {
<div class="table-row odd:bg-gray">
<div class="w-2/3 truncate table-cell">
<A href=format!("/problem/{}", info.id.id)>{info.title}</A>
<div class="table w-full table-auto">
<div class="table-header-group text-left">
<div class="table-row">
<div class="table-cell">Title</div>
<div class="hidden md:table-cell">AC Rate</div>
<div class="hidden md:table-cell">Attempt</div>
<div class="table-cell">Difficulty</div>
</div>
</div>
<div class="table-row-group" style="line-height: 3rem">

{v
.list
.into_iter()
.map(|info| {
view! {
<div class="table-row odd:bg-gray">
<div class="w-2/3 truncate table-cell">
<A href=format!("/problem/{}", info.id.id)>{info.title}</A>
</div>
<div class="text-center hidden md:table-cell">
{info.ac_rate} %
</div>
<div class="text-center hidden md:table-cell">
{info.submit_count}
</div>
<div class="table-cell">
{difficulty_color(info.difficulty)}
</div>
</div>
}
})
.collect_view()}

</div>
<div class="text-center hidden md:table-cell">{info.ac_rate} %</div>
<div class="text-center hidden md:table-cell">{info.submit_count}</div>
<div class="table-cell">{difficulty_color(info.difficulty)}</div>
</div>
<ul>

{v
.previous_queries
.into_iter()
.enumerate()
.map(|(n, query)| {
view! {
<li>
<A href=format!("/problems{}", query)>back {n + 1} page</A>
</li>
}
})
.collect_view()}

</ul>
<ul>

{v
.next_queries
.into_iter()
.enumerate()
.map(|(n, query)| {
view! {
<li>
<A href=format!("/problems{}", query)>next {n + 1} page</A>
</li>
}
})
.collect_view()}

</ul>
}
})
.collect_view()
}
</div>
</div>
<ul>
{
v.previous_queries.into_iter().enumerate()
.map(|(n,query)|view!{
<li>
<A href=format!("/problems{}", query)>back {n+1} page</A>
</li>
}).collect_view()
}
</ul>
<ul>
{
v.next_queries.into_iter().enumerate()
.map(|(n,query)|view!{
<li>
<A href=format!("/problems{}", query)>next {n+1} page</A>
</li>
}).collect_view()
}
</ul>
}))
}
}
})
}}

</Transition>
</div>
}
Expand Down
3 changes: 1 addition & 2 deletions grpc/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ fn main() {
.file_descriptor_set_path(&descriptor_file)
.compile(&["proto/backend.proto", "proto/judger.proto"], &["proto"])
.unwrap();
#[cfg(feature = "serde")]
#[cfg(feature = "wkt")]
#[cfg(all(feature = "wkt", feature = "serde"))]
{
use prost_wkt_build::*;
let descriptor_bytes = std::fs::read(descriptor_file).unwrap();
Expand Down
3 changes: 3 additions & 0 deletions grpc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
#[cfg(feature = "wkt")]
#[allow(clippy::all, non_local_definitions)]
pub mod backend {
tonic::include_proto!("oj.backend");
}

#[cfg(feature = "backend")]
#[cfg(not(feature = "wkt"))]
#[allow(clippy::all, non_local_definitions)]
pub mod backend {
tonic::include_proto!("oj.backend");
}

#[cfg(feature = "backend")]
#[allow(clippy::all, non_local_definitions)]
pub mod judger {
tonic::include_proto!("oj.judger");
}

0 comments on commit 1da7bcd

Please sign in to comment.