Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Eason0729/mdoj
Browse files Browse the repository at this point in the history
  • Loading branch information
Eason0729 committed Aug 23, 2024
2 parents 8edcb52 + ae4015f commit 51a12a2
Show file tree
Hide file tree
Showing 45 changed files with 1,033 additions and 201 deletions.
42 changes: 42 additions & 0 deletions Cargo.lock

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

11 changes: 11 additions & 0 deletions backend/src/endpoint/contest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ impl Contest for ArcServer {
let (auth, req) = self.rate_limit(req).in_current_span().await?;

req.get_or_insert(|req| async move {
let txn = self.db.begin().await?;

let result = Entity::delete_by_id(req.id)
.with_auth(&auth)
.write()?
Expand All @@ -246,6 +248,15 @@ impl Contest for ArcServer {
.await
.map_err(Into::<Error>::into)?;

problem::Entity::update_many()
.col_expr(problem::Column::ContestId, Expr::value(Value::Int(None)))
.filter(crate::entity::testcase::Column::ProblemId.eq(req.id))
.exec(&txn)
.instrument(info_span!("remove_child"))
.await?;

txn.commit().await.map_err(|_| Error::Retry)?;

if result.rows_affected == 0 {
return Err(Error::NotInDB);
}
Expand Down
22 changes: 20 additions & 2 deletions frontend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ turf = "0.9.2"
leptos_animated_for = "0.4.7"
num-traits = "0.2.19"
lol_alloc = "0.4.1"
leptos_query = "0.5.3"
cookie = "0.18.1"
leptos_query_devtools = "0.1.3"

[dependencies.uuid]
version = "1.7.0"
Expand Down Expand Up @@ -79,8 +82,22 @@ features = ["prost"]
workspace = true

[features]
csr = ["leptos/csr", "leptos_meta/csr", "leptos_router/csr", "uuid/js"]
hydrate = ["leptos/hydrate", "leptos_meta/hydrate", "leptos_router/hydrate"]
csr = [
"leptos/csr",
"leptos_meta/csr",
"leptos_router/csr",
"uuid/js",
"leptos_query/csr",
"leptos_query_devtools/csr",
]
hydrate = [
"leptos/hydrate",
"leptos_meta/hydrate",
"leptos_router/hydrate",
"leptos_query/hydrate",
# This is intended, hydrate feature for devtool is csr
"leptos_query_devtools/csr",
]
ssr = [
"dep:actix-files",
"dep:actix-web",
Expand All @@ -93,6 +110,7 @@ ssr = [
"leptos_router/ssr",
"leptos-use/ssr",
"leptos-use/actix",
"leptos_query/ssr",
]
compress = []

Expand Down
21 changes: 0 additions & 21 deletions frontend/LICENSE

This file was deleted.

25 changes: 15 additions & 10 deletions frontend/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
use leptos::*;
use leptos_meta::*;
use leptos_query_devtools::LeptosQueryDevtools;
use leptos_router::*;

use crate::{components::*, config::ProvideConfig, pages::Pages};
use crate::{
components::*,
pages::Pages,
utils::{config::ProvideConfig, *},
};
// use tracing_subscriber::fmt::format::Pretty;
// use tracing_subscriber::prelude::*;
// use tracing_web::{performance_layer, MakeWebConsoleWriter};
Expand All @@ -11,20 +16,20 @@ use crate::{components::*, config::ProvideConfig, pages::Pages};
pub fn App() -> impl IntoView {
// Provides context that manages stylesheets, titles, meta tags, etc.
provide_meta_context();
provide_query_service();

view! {
<Stylesheet id="leptos" href="/pkg/mdoj.css" />
<Title text="MDOJ" />
<ProvideConfig>
<ProvideToast>
<Router>
<Stylesheet id="leptos" href="/pkg/mdoj.css"/>
<Title text="MDOJ"/>

<div class="bg-black-950 w-full min-h-dvh flex flex-col text-text">
<Navbar/>
<Pages/>
</div>
</Router>
<div class="bg-black-950 w-full min-h-dvh flex flex-col text-text">
<Router>
<Pages />
</Router>
</div>
</ProvideToast>
</ProvideConfig>
<LeptosQueryDevtools />
}
}
13 changes: 6 additions & 7 deletions frontend/src/components/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use leptos::*;
use wasm_bindgen::prelude::*;
use web_sys::Event;

use crate::config::frontend_config;
use crate::utils::*;

#[wasm_bindgen]
extern "C" {
Expand Down Expand Up @@ -69,18 +69,17 @@ pub fn Editor(
let c = Object::new();
let paths = Object::new();
Reflect::set(
&*paths,
&paths,
&"vs".into(),
&"https://cdn.jsdelivr.net/npm/monaco-editor@0.50.0/min/vs".into(),
)
.unwrap();
Reflect::set(&*c, &"paths".into(), &*paths).unwrap();
Reflect::set(&c, &"paths".into(), &paths).unwrap();
loader_config(c);

let config = Object::new();
Reflect::set(&*config, &"theme".into(), &"vs-dark".into()).unwrap();
Reflect::set(&*config, &"automaticLayout".into(), &true.into())
.unwrap();
Reflect::set(&config, &"theme".into(), &"vs-dark".into()).unwrap();
Reflect::set(&config, &"automaticLayout".into(), &true.into()).unwrap();

let init_monaco = Closure::once_into_js(move || {
let editor = MONACO.editor().create_editor(
Expand All @@ -98,7 +97,7 @@ pub fn Editor(

create_effect(move |_| {
editor_ref.with(|editor| {
let Some(model) = editor.as_ref().map(|e| e.get_model()).flatten()
let Some(model) = editor.as_ref().and_then(|e| e.get_model())
else {
return;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use leptos::*;

use super::{Error, ErrorKind, InternalServerError, NotFound};
use super::*;
use crate::utils::*;

#[component]
pub fn ErrorFallback(children: Children) -> impl IntoView {
Expand All @@ -12,13 +13,13 @@ fn fallback(errors: RwSignal<Errors>) -> impl IntoView {
errors().into_iter().next().map(|(_, err)| {
let err: Error = err.into();
match err.kind {
ErrorKind::NotFound => view! { <NotFound/> }.into_view(),
ErrorKind::NotFound => view! { <NotFound /> }.into_view(),
ErrorKind::RateLimit => todo!(),
ErrorKind::Unauthenticated => todo!(),
ErrorKind::OutOfRange => view! { <NotFound/> }.into_view(),
ErrorKind::OutOfRange => view! { <NotFound /> }.into_view(),
ErrorKind::Network => todo!(),
ErrorKind::Internal => {
view! { <InternalServerError/> }.into_view()
view! { <InternalServerError /> }.into_view()
}
ErrorKind::PermissionDenied => todo!(),
ErrorKind::Browser => todo!(),
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/components/errors/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mod error_fallback;
mod internal_server_error;
mod not_found;
pub use error_fallback::*;
pub use internal_server_error::*;
pub use not_found::*;
File renamed without changes.
3 changes: 1 addition & 2 deletions frontend/src/components/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ pub fn Highlight() -> impl IntoView {
logging::log!("change");
set_value(event_target_value(&e));
}
>
</textarea>
></textarea>
<div inner_html=html></div>
</div>
}
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/components/mod.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
pub mod badge;
pub mod button;
pub mod editor;
pub mod errors;
pub mod footer;
pub mod highlight;
pub mod input;
pub mod input_number;
pub mod markdown;
pub mod modal;
pub mod navbar;
pub mod paginate_navbar;
pub mod paginate_table;
pub mod redirect_if;
pub mod search_bar;
pub mod select;
pub mod toast;
pub mod toggle;

pub use badge::Badge;
pub use button::{Button, ButtonVariant};
pub use editor::{create_editor_ref, Editor};
pub use errors::*;
pub use footer::Footer;
pub use highlight::Highlight;
pub use input::{Input, InputVariant};
pub use input_number::InputNumber;
pub use markdown::Markdown;
pub use modal::{Modal, ModalLevel};
pub use navbar::Navbar;
pub use paginate_navbar::PaginateNavbar;
pub use paginate_table::PaginateTable;
pub use redirect_if::RedirectIf;
pub use search_bar::SearchBar;
pub use select::{Select, SelectOption};
pub use toast::{use_toast, ProvideToast, ToastVariant};
6 changes: 3 additions & 3 deletions frontend/src/components/navbar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use leptos::*;
use leptos_router::*;
use leptos_use::*;

use crate::session::use_token;
use crate::utils::*;

#[component]
pub fn Navbar() -> impl IntoView {
Expand All @@ -11,7 +11,7 @@ pub fn Navbar() -> impl IntoView {
<nav class="bg-black-900 sticky top-0 p-2 flex flex-row justify-between border-b-2 border-black-400 z-10">
<div class="flex flex-row flex-nowrap">
<A href="/">
<img src="https://placehold.co/100" class="h-12 aspect-square mx-5"/>
<img src="https://placehold.co/100" class="h-12 aspect-square mx-5" />
</A>
<ul class="flex flex-row flex-nowrap justify-between items-center text-base">
<NavbarLink href="/problems">Problems</NavbarLink>
Expand All @@ -33,7 +33,7 @@ pub fn Navbar() -> impl IntoView {
}
>

<img src="https://placehold.co/100" class="h-12 aspect-square mx-5"/>
<img src="https://placehold.co/100" class="h-12 aspect-square mx-5" />
</Show>
</div>
</nav>
Expand Down
Loading

0 comments on commit 51a12a2

Please sign in to comment.