Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ gloo-utils = "0.1.4"
js-sys = "0.3.61"
log = { version = "0.4", features = ["max_level_info"] }
pyth-sdk-solana = "0.7.1"
regex = "1.8.1"
reqwest = { version = "0.11.16", features = ["blocking", "json"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1.0"
Expand Down
39 changes: 39 additions & 0 deletions src/components/cron_tab.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use dioxus::{html::input_data::keyboard_types::Key, prelude::*};

use crate::utils::CronAnalyzer;

pub fn CronTab(cx: Scope) -> Element {
let cron_state = use_state(cx, || "0 30 9,12,15 1,15 May-Aug Mon,Wed,Fri 2018/2".to_owned());
let cron_result = use_state(cx, || "".to_owned());
let expr = cron_state.get();

// Move the focus to the search bar.
// autofocus property on input is having issues: https://github.com/DioxusLabs/dioxus/issues/725

cx.render(rsx! {
input {
class: "rounded bg-[#0e0e10] border-2 border-white focus:border-0 text-slate-100 p-5 w-full focus:ring-0 focus:outline-0 text-base",
id: "cron-tab",
r#type: "text",
placeholder: "Enter 7 field cron expression e.g */10 * * * * * *",
value: "{expr}",
oninput: move |e| {
// v = e.value.clone().as_str().to_string();
cron_state.set(e.value.clone().as_str().to_string());
},
onclick: move |e| e.stop_propagation(),
onkeydown: move |e| {
if e.key() == Key::Enter {
let analysis = match CronAnalyzer::from_expr(expr.clone()) {
Ok(analysis) => analysis,
Err(e) => format!("{e}")
};
cron_result.set(analysis)
}
},
}
p {
"{cron_result.get()}"
}
})
}
2 changes: 2 additions & 0 deletions src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub mod blocks_table;
pub mod chat;
pub mod clock;
pub mod connect_button;
pub mod cron_tab;
pub mod markets_table;
pub mod navbar;
pub mod page_control;
Expand All @@ -21,6 +22,7 @@ pub use blocks_table::*;
pub use chat::*;
pub use clock::*;
pub use connect_button::*;
pub use cron_tab::*;
pub use markets_table::*;
pub use navbar::*;
pub use page_control::*;
Expand Down
4 changes: 4 additions & 0 deletions src/components/navbar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ pub fn Navbar(cx: Scope) -> Element {
Logo {}
div {
class: "flex items-center space-x-4",
Link {
to: "/cron",
"Cron"
}
SearchButton {}
ConnectButton {}
}
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ fn App(cx: Scope) -> Element {
// Route { to: "/keys", KeysPage{} }
// Route { to: "/keys/new", NewKeyPage{} }
Route { to: "/", ProgramsPage{} }
Route { to: "/cron", CronPage{} }
Route { to: "/threads/:address", ThreadPage {} }
Route { to: "/transaction/:signature", TransactionPage {} }
Route { to: "", NotFoundPage{} }
Expand Down
22 changes: 22 additions & 0 deletions src/pages/cron.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use dioxus::prelude::*;

use crate::components::CronTab;

use super::Page;

pub fn CronPage(cx: Scope) -> Element {
cx.render(rsx! {
Page {
div {
class: "flex flex-col space-y-12",

h1 {
class: "text-2xl font-semibold mb-6",
"Cron Analyzer"
}

CronTab {}
}
}
})
}
2 changes: 2 additions & 0 deletions src/pages/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod account;
pub mod accounts;
pub mod cron;
pub mod files;
pub mod home;
pub mod keys;
Expand All @@ -13,6 +14,7 @@ pub mod transaction;

pub use account::*;
pub use accounts::*;
pub use cron::*;
pub use files::*;
pub use home::*;
pub use keys::*;
Expand Down
38 changes: 38 additions & 0 deletions src/utils/cron_analyzer/day_of_month.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use super::{field::Field, error::CronAnalyzerError};

pub struct DayOfMonthField {
pub raw: String,
}

impl<'a> Field<'a> for DayOfMonthField {
fn raw(&self) -> String {
self.raw.clone()
}

fn name(&self) -> String {
"day-of-month".to_owned()
}
fn min(&self) -> usize {
1
}
fn max(&self) -> usize {
31
}
fn selection(&self) -> Option<Vec<&'a str>> {
None
}

fn convert_if_word(&self, input: &str) -> String {
input.to_owned()
}

fn analyze(&self) -> Result<String, CronAnalyzerError> {
match self.raw.as_str() {
"*" => Ok(format!("")),
_ => match self.format_field(false) {
Ok(s) => Ok(format!("on {s}")),
Err(e) => Err(e),
},
}
}
}
55 changes: 55 additions & 0 deletions src/utils/cron_analyzer/day_of_week.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use super::{field::Field, error::CronAnalyzerError};

pub struct DayOfWeekField {
pub raw: String,
}

impl<'a> Field<'a> for DayOfWeekField {
fn raw(&self) -> String {
self.raw.clone()
}
fn name(&self) -> String {
"day-of-week".to_owned()
}
fn min(&self) -> usize {
1
}
fn max(&self) -> usize {
7
}
fn selection(&self) -> Option<Vec<&'a str>> {
Some(vec![
"",
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
])
}

fn convert_if_word(&self, input: &str) -> String {
match input.to_lowercase().as_str() {
"sun" | "sunday" => "1".to_owned(),
"mon" | "monday" => "2".to_owned(),
"tue" | "tues" | "tuesday" => "3".to_owned(),
"wed" | "wednesday" => "4".to_owned(),
"thu" | "thurs" | "thursday" => "5".to_owned(),
"fri" | "friday" => "6".to_owned(),
"sat" | "saturday" => "7".to_owned(),
_ => input.to_owned(),
}
}

fn analyze(&self) -> Result<String, CronAnalyzerError> {
match self.raw.as_str() {
"*" => Ok(format!("")),
_ => match self.format_field(true) {
Ok(s) => Ok(format!("on {s}")),
Err(e) => Err(e),
},
}
}
}
21 changes: 21 additions & 0 deletions src/utils/cron_analyzer/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use std::{error, fmt };

#[derive(Debug)]
pub struct CronAnalyzerError {
msg: String,
}

impl CronAnalyzerError {
pub fn new(msg: String) -> Self {
CronAnalyzerError { msg }
}
}

impl error::Error for CronAnalyzerError {}

impl fmt::Display for CronAnalyzerError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.msg)
}
}

Loading