Skip to content

Commit

Permalink
fix: Problems' description (pick, edit) (#163)
Browse files Browse the repository at this point in the history
* fix: daily problem parsing

Changed a key to fix parsing daily problem request.
Fixed when id for daily problem should be fetched. Before, it will
always be fetched for the `pick` option regardless of the existence of
the `-d` option

* fix: comment problem desc

Changed desc comment to render Question.content instead of
Question.t_content, which was empty.
  • Loading branch information
tripercy authored Aug 24, 2024
1 parent d1fd7fc commit 9903a60
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion src/cache/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl Question {
}

pub fn desc_comment(&self, conf: &Config) -> String {
let desc = self.t_content.render();
let desc = self.content.render();

let mut res = desc.lines().fold("\n".to_string(), |acc, e| {
acc + "" + conf.code.comment_leading.as_str() + " " + e + "\n"
Expand Down
2 changes: 1 addition & 1 deletion src/cache/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub fn tags(v: Value) -> Option<Vec<String>> {
pub fn daily(v: Value) -> Option<i32> {
trace!("Parse daily...");
let v_obj = v.as_object()?.get("data")?.as_object()?;
match v_obj.get("dailyQuestionRecord") {
match v_obj.get("activeDailyCodingChallengeQuestion") {
// Handle on leetcode-com
Some(v) => v,
// Handle on leetcode-cn
Expand Down
7 changes: 6 additions & 1 deletion src/cmds/pick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,12 @@ impl Command for PickCommand {
crate::helper::filter(&mut problems, query.to_string());
}

let daily_id = if m.contains_id("daily") {
let daily = match m.get_one::<bool>("daily") {
Some(x) => x,
None => &false,
};

Check warning on line 136 in src/cmds/pick.rs

View workflow job for this annotation

GitHub Actions / clippy

this pattern reimplements `Option::unwrap_or`

warning: this pattern reimplements `Option::unwrap_or` --> src/cmds/pick.rs:133:21 | 133 | let daily = match m.get_one::<bool>("daily") { | _____________________^ 134 | | Some(x) => x, 135 | | None => &false, 136 | | }; | |_________^ help: replace with: `m.get_one::<bool>("daily").unwrap_or(&false)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_unwrap_or = note: `#[warn(clippy::manual_unwrap_or)]` on by default

let daily_id = if *daily {
Some(cache.get_daily_problem_id().await?)
} else {
None
Expand Down

0 comments on commit 9903a60

Please sign in to comment.