-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from rust-dd/feature/new_exercise_07
feat: add new exercise
- Loading branch information
Showing
6 changed files
with
171 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
use leptos::*; | ||
use regex::Regex; | ||
use std::rc::Rc; | ||
|
||
use crate::context::{CodeSetter, Exercises, InputRef}; | ||
|
||
#[component] | ||
pub fn Component() -> impl IntoView { | ||
let CodeSetter(set_code) = expect_context::<CodeSetter>(); | ||
let InputRef(_ref) = expect_context::<InputRef>(); | ||
let Exercises { exercise_07, .. } = expect_context::<Exercises>(); | ||
let re = Regex::new(r"\d+\.").unwrap(); | ||
let exercise_07 = Rc::new(re.split(exercise_07).collect::<Vec<&str>>()); | ||
|
||
view! { | ||
<div class="flex flex-col gap-4 w-full text-white rounded-lg"> | ||
<div class="flex flex-col gap-2"> | ||
<h2 class="text-3xl font-bold">Learning by Structs and Operator Overloading</h2> | ||
<p class="text-gray-400"> | ||
{r#"In this exercise, we will define a Vec struct with x and y fields and implement the Add operator for it."#} | ||
</p> | ||
|
||
<div class="flex flex-col gap-1 mt-2"> | ||
<h3 class="text-xl font-bold">Step 1: Define the Vec struct</h3> | ||
<pre | ||
on:click={ | ||
let exercise_07 = exercise_07.clone(); | ||
move |_| { | ||
set_code(String::from(exercise_07[0])); | ||
_ref() | ||
.get() | ||
.expect("input_ref should be loaded by now") | ||
.focus() | ||
.unwrap(); | ||
} | ||
} | ||
class="p-4 whitespace-pre-wrap bg-black bg-opacity-30 rounded-lg transition duration-500 cursor-pointer hover:bg-black hover:bg-opacity-50" | ||
> | ||
<code class="font-mono text-sm text-yellow-500">{exercise_07[0]}</code> | ||
</pre> | ||
</div> | ||
|
||
<div class="flex flex-col gap-1"> | ||
<h3 class="text-xl font-bold">Step 2: Implement Add for Vec</h3> | ||
<pre | ||
on:click={ | ||
let exercise_07 = exercise_07.clone(); | ||
move |_| { | ||
set_code(String::from(exercise_07[1])); | ||
_ref() | ||
.get() | ||
.expect("input_ref should be loaded by now") | ||
.focus() | ||
.unwrap(); | ||
} | ||
} | ||
class="p-4 whitespace-pre-wrap bg-black bg-opacity-30 rounded-lg transition duration-500 cursor-pointer hover:bg-black hover:bg-opacity-50" | ||
> | ||
<code class="font-mono text-sm text-yellow-500">{exercise_07[1]}</code> | ||
</pre> | ||
</div> | ||
|
||
<div class="flex flex-col gap-1"> | ||
<h3 class="text-xl font-bold">Step 3: Declare v1</h3> | ||
<pre | ||
on:click={ | ||
let exercise_07 = exercise_07.clone(); | ||
move |_| { | ||
set_code(String::from(exercise_07[2])); | ||
_ref() | ||
.get() | ||
.expect("input_ref should be loaded by now") | ||
.focus() | ||
.unwrap(); | ||
} | ||
} | ||
class="p-4 whitespace-pre-wrap bg-black bg-opacity-30 rounded-lg transition duration-500 cursor-pointer hover:bg-black hover:bg-opacity-50" | ||
> | ||
<code class="font-mono text-sm text-yellow-500">{exercise_07[2]}</code> | ||
</pre> | ||
</div> | ||
|
||
<div class="flex flex-col gap-1"> | ||
<h3 class="text-xl font-bold">Step 4: Declare v2</h3> | ||
<pre | ||
on:click={ | ||
let exercise_07 = exercise_07.clone(); | ||
move |_| { | ||
set_code(String::from(exercise_07[3])); | ||
_ref() | ||
.get() | ||
.expect("input_ref should be loaded by now") | ||
.focus() | ||
.unwrap(); | ||
} | ||
} | ||
class="p-4 whitespace-pre-wrap bg-black bg-opacity-30 rounded-lg transition duration-500 cursor-pointer hover:bg-black hover:bg-opacity-50" | ||
> | ||
<code class="font-mono text-sm text-yellow-500">{exercise_07[3]}</code> | ||
</pre> | ||
</div> | ||
|
||
<div class="flex flex-col gap-1"> | ||
<h3 class="text-xl font-bold">Step 5: Add v1 and v2</h3> | ||
<pre | ||
on:click={ | ||
let exercise_07 = exercise_07.clone(); | ||
move |_| { | ||
set_code(String::from(exercise_07[4])); | ||
_ref() | ||
.get() | ||
.expect("input_ref should be loaded by now") | ||
.focus() | ||
.unwrap(); | ||
} | ||
} | ||
class="p-4 whitespace-pre-wrap bg-black bg-opacity-30 rounded-lg transition duration-500 cursor-pointer hover:bg-black hover:bg-opacity-50" | ||
> | ||
<code class="font-mono text-sm text-left text-yellow-500"> | ||
{exercise_07[4]} | ||
</code> | ||
</pre> | ||
</div> | ||
<div class="flex flex-col gap-1"> | ||
<h3 class="text-xl font-bold">Step : Print v1, v2, and v3</h3> | ||
<pre | ||
on:click={ | ||
let exercise_07 = exercise_07.clone(); | ||
move |_| { | ||
set_code(String::from(exercise_07[5])); | ||
_ref() | ||
.get() | ||
.expect("input_ref should be loaded by now") | ||
.focus() | ||
.unwrap(); | ||
} | ||
} | ||
class="p-4 whitespace-pre-wrap bg-black bg-opacity-30 rounded-lg transition duration-500 cursor-pointer hover:bg-black hover:bg-opacity-50" | ||
> | ||
<code class="font-mono text-sm text-left text-yellow-500"> | ||
{move || String::from(exercise_07[5])} | ||
</code> | ||
</pre> | ||
</div> | ||
</div> | ||
</div> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters