Skip to content

Commit

Permalink
win98
Browse files Browse the repository at this point in the history
  • Loading branch information
warycat committed Jan 24, 2022
1 parent e2e4a27 commit 4e5ce54
Show file tree
Hide file tree
Showing 50 changed files with 2,079 additions and 322 deletions.
14 changes: 14 additions & 0 deletions server/src/context/app.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use crate::context::*;

pub struct AppContext {
pub title: String,
pub tag: String,
}

impl AppContext {
pub fn new(data: Data<AppData>) -> Self {
let title = data.title.borrow().to_string();
let tag = data.tag.borrow().to_string();
AppContext { title, tag }
}
}
9 changes: 9 additions & 0 deletions server/src/context/find.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use crate::context::*;

#[derive(Template, new)]
#[template(path = "find.j2")]
pub struct FindContext {
pub app: AppContext,
pub session: SessionData,
pub path: String,
}
4 changes: 2 additions & 2 deletions server/src/context/google.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ pub struct GoogleIndexContext {
pub app: AppContext,
pub session: SessionData,
pub path: String,
pub codejam_rows: Vec<GoogleIndexRow>,
pub kickstart_rows: Vec<GoogleIndexRow>,
pub rows_codejam: Vec<GoogleIndexRow>,
pub rows_kickstart: Vec<GoogleIndexRow>,
}

#[derive(Template, new)]
Expand Down
13 changes: 0 additions & 13 deletions server/src/context/home.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
use crate::context::*;

pub struct AppContext {
pub title: String,
pub tag: String,
}

#[derive(Template, new)]
#[template(path = "home.j2")]
pub struct HomeContext {
pub app: AppContext,
pub session: SessionData,
pub path: String,
}

impl AppContext {
pub fn new(data: Data<AppData>) -> Self {
let title = data.title.borrow().to_string();
let tag = data.tag.borrow().to_string();
AppContext { title, tag }
}
}
4 changes: 3 additions & 1 deletion server/src/context/leetcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ pub struct LeetcodeIndexContext {
pub app: AppContext,
pub session: SessionData,
pub path: String,
pub rows: Vec<LeetcodeIndexRow>,
pub rows_easy: Vec<LeetcodeIndexRow>,
pub rows_medium: Vec<LeetcodeIndexRow>,
pub rows_hard: Vec<LeetcodeIndexRow>,
}

#[derive(Template, new)]
Expand Down
5 changes: 5 additions & 0 deletions server/src/context/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
mod adventofcode;
mod app;
mod find;
mod google;
mod home;
mod leetcode;
mod nes;
mod sitemap;

pub use adventofcode::*;
pub use app::*;
pub use find::*;
pub use google::*;
pub use home::*;
pub use leetcode::*;
Expand Down Expand Up @@ -52,6 +56,7 @@ impl_render_wrapper!(GoogleIndexContext);
impl_render_wrapper!(GoogleDetailContext);
impl_render_wrapper!(NesIndexContext);
impl_render_wrapper!(NesDetailContext);
impl_render_wrapper!(FindContext);

impl_txt_render_wrapper!(SitemapContext);
impl_txt_render_wrapper!(RobotsContext);
6 changes: 6 additions & 0 deletions server/src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ async fn data_files(req: HttpRequest) -> Result<NamedFile> {
let path: PathBuf = ["data", filename].iter().collect();
Ok(NamedFile::open(path)?)
}

#[get("/favicon.ico")]
async fn favicon_file(_req: HttpRequest) -> Result<NamedFile> {
let path: PathBuf = ["static", "ico", "windows.ico"].iter().collect();
Ok(NamedFile::open(path)?)
}
4 changes: 3 additions & 1 deletion server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async fn main() -> std::io::Result<()> {
let tag = env::var("TAG").expect("TAG");
let turn_static_auth_secret =
env::var("TURN_STATIC_AUTH_SECRET").expect("TURN_STATIC_AUTH_SECRET");
let title = "RUST GYM".to_string();
let title = "Rust Gym".to_string();
info!("{} {}", title, tag);
let app_data = AppData::new(tag, title, turn_static_auth_secret);
let search_addr = SearchAgent::new(pool.clone()).start();
Expand All @@ -54,6 +54,7 @@ async fn main() -> std::io::Result<()> {
.data(registry_addr.clone())
.data(uap_addr.clone())
.service(routes::home::home)
.service(routes::find::find)
.service(routes::nes_index::nes_index)
.service(routes::nes_detail::nes_detail)
.service(routes::leetcode_index::leetcode_index)
Expand All @@ -67,6 +68,7 @@ async fn main() -> std::io::Result<()> {
.service(files::client_files)
.service(files::static_files)
.service(files::data_files)
.service(files::favicon_file)
.service(web::resource("/ws/").to(agents::websocket::ws_index))
})
.bind("127.0.0.1:8080")?
Expand Down
19 changes: 19 additions & 0 deletions server/src/routes/find.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use crate::app_data::AppData;
use crate::context::*;
use crate::session_data::update_session;
use actix_session::Session;
use actix_web::get;
use actix_web::web;
use actix_web::Error;
use actix_web::HttpRequest;
use actix_web::HttpResponse;

#[get("/find")]
pub async fn find(
req: HttpRequest,
data: web::Data<AppData>,
session: Session,
) -> Result<HttpResponse, Error> {
let session_data = update_session(session)?;
FindContext::new(AppContext::new(data), session_data, req.path().to_string()).render_wrapper()
}
24 changes: 23 additions & 1 deletion server/src/routes/leetcode_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,33 @@ pub async fn leetcode_index(
.order(schema::leetcode_question::dsl::id)
.load(&conn)
.map_err(ErrorNotFound)?;

let mut rows_easy = vec![];
let mut rows_medium = vec![];
let mut rows_hard = vec![];
for row in rows {
match row.level {
1 => {
rows_easy.push(row);
}
2 => {
rows_medium.push(row);
}
3 => {
rows_hard.push(row);
}
_ => {
panic!();
}
}
}
LeetcodeIndexContext::new(
AppContext::new(data),
session_data,
req.path().to_string(),
rows,
rows_easy,
rows_medium,
rows_hard,
)
.render_wrapper()
}
1 change: 1 addition & 0 deletions server/src/routes/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod adventofcode_detail;
pub mod adventofcode_index;
pub mod find;
pub mod google_detail;
pub mod google_index;
pub mod home;
Expand Down
66 changes: 43 additions & 23 deletions server/templates/adventofcode-detail.j2
Original file line number Diff line number Diff line change
@@ -1,33 +1,53 @@
{% extends "home.j2" %}
{% extends "desktop.j2" %}

{% block title %}
{{app.title}} AdventOfCode {{description.year}} Day {{description.day}} {{description.title}} Rust Solution
{% endblock %}

{% block content %}
<div>{{description.html|safe}}</div>
<h2>Rust Solution</h2>
<pre><code class="rust">{{solution.source}}</code></pre>

<div class="grid grid-cols-2 flex justify-between">
<div class="flex">
<a target="_blank" href="{{description.practice_url()}}">
<button type="button" class="border border-green-500 bg-green-500 text-white rounded-md px-4 py-2 m-2 transition duration-500 ease select-none hover:bg-green-500 focus:outline-none focus:shadow-outline">Practice</button>
</a>
</div>

<div class="flex justify-end">
<a target="_blank" href="http://twitter.com/share?text={{app.title}} AdventOfCode {{description.year}} Day {{description.day}} {{description.title}} Rust Solution&url=https://rustgym.com{{description.href()}}&hashtags=rustgym,adventofcode,rust">
<button type="button" class="border border-blue-400 bg-blue-400 text-white rounded-md px-4 py-2 m-2 transition duration-500 ease select-none hover:bg-blue-500 focus:outline-none focus:shadow-outline">Tweet</button>
</a>
<a target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=rustgym.com{{description.href()}}" >
<button type="button" class="border border-blue-600 bg-blue-600 text-white rounded-md px-4 py-2 m-2 transition duration-500 ease select-none hover:bg-blue-700 focus:outline-none focus:shadow-outline">Facebook</button>
</a>
</div>
</div>
<div class="component">
<div class="window" >
<div class="title-bar">
<div class="title-bar-text">{{description.title}}</div>
<div class="title-bar-controls">
<button aria-label="Minimize"></button>
<button aria-label="Maximize"></button>
<button aria-label="Close"></button>
</div>
</div>
<div class="window-body">
<div>{{description.html|safe}}</div>
<section class="field-row" style="justify-content: flex-end">
<a target="_blank" href="{{description.practice_url()}}">
<button>Practice</button>
</a>
<a target="_blank" href="http://twitter.com/share?text={{app.title}} AdventOfCode {{description.year}} Day {{description.day}} {{description.title}} Rust Solution&url=https://rustgym.com{{description.href()}}&hashtags=rustgym,adventofcode,rust">
<button>Tweet</button>
</a>
<a target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=rustgym.com{{description.href()}}" >
<button>Facebook</button>
</a>
<a target="_blank" href="https://github.com/warycat/rustgym/issues/new?title=AdventOfCode {{description.year}} Day {{description.day}} {{description.title}}">
<button type="button">Issue</button>
</a>
</section>
</div>
</div>

<div class="window" >
<div class="title-bar">
<div class="title-bar-text">{{description.title}}</div>
<div class="title-bar-controls">
<button aria-label="Minimize"></button>
<button aria-label="Maximize"></button>
<button aria-label="Close"></button>
</div>
</div>
<div class="window-body">
<pre><code class="rust">{{solution.source}}</code></pre>
</div>
</div>

<div>
<p>Having problems with this solution? <a href="https://github.com/warycat/rustgym/issues/new?title=AdventOfCode {{description.year}} Day {{description.day}} {{description.title}}">Click here</a> to submit an issue on github.</p>
</div>
{% endblock %}

67 changes: 41 additions & 26 deletions server/templates/adventofcode-index.j2
Original file line number Diff line number Diff line change
@@ -1,32 +1,47 @@
{% extends "home.j2" %}
{% extends "desktop.j2" %}

{% block title %}
{{app.title}} AdventOfCode Rust Solutions
{% endblock %}

{% block content %}
<table class="table-auto">
<thead>
<tr>
<th>Year</th>
<th>Day</th>
<th>AdventOfCode {{rows.len()}} Rust Solutions</th>
</tr>
</thead>
<tbody>
{% for row in rows %}
<tr>
<td>
{{row.year}}
</td>
<td>
{{row.day}}
</td>
<td>
<a href="{{row.href()}}"> {{row.title}}</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
<div class="component">
<div class="window" >
<div class="title-bar">
<div class="title-bar-text">AdventOfCode Solutions</div>
<div class="title-bar-controls">
<button aria-label="Minimize"></button>
<button aria-label="Maximize"></button>
<button aria-label="Close"></button>
</div>
</div>
<div class="window-body">
<table class="table-auto">
<thead>
<tr>
<th>Year</th>
<th>Day</th>
<th>AdventOfCode {{rows.len()}} Rust Solutions</th>
</tr>
</thead>
<tbody>
{% for row in rows %}
<tr>
<td>
{{row.year}}
</td>
<td>
{{row.day}}
</td>
<td>
<a href="{{row.href()}}"> {{row.title}}</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
{% endblock %}

Loading

0 comments on commit 4e5ce54

Please sign in to comment.