Skip to content

Commit

Permalink
Merge pull request #3 from akarsh1995/dev
Browse files Browse the repository at this point in the history
v0.3.0
  • Loading branch information
akarsh1995 authored Aug 10, 2023
2 parents c3dd527 + 6b072e0 commit e46b676
Show file tree
Hide file tree
Showing 30 changed files with 1,074 additions and 641 deletions.
17 changes: 12 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ All notable changes to this project will be documented in this file.
- Sort questions by:
- likes dislikes ratio.

- Filter

- Search feature.

- Scroll bar visible list

- Take input directly from the user lc session
Expand All @@ -22,17 +18,28 @@ All notable changes to this project will be documented in this file.

- Invalidate questions cache through `userSessionProgress`

## [0.2.1] - [Unreleased]
- Fix re-request when there's network error in fetching question.

## [0.2.1] - 2023-08-10

### Added

- Neetcode 75 question list.
- Search feature on keypress `/`

### Changed

- Not null constraints on the fields that are never null from the server.
- `QuestionModelContainer { question: RefCell<QuestionModel> }` changed to `Rc<RefCell<QuestionModel>>`
- As prior implemented hash. Hashables should not be mutable.
- Colorscheme as per tokyonight style.

### Fixed

- Some questions did not appear in "All" question list because they were not attached to any topic.
- To resolve Unknown topic tag is added to the questions which do not have any topic tag.
- App now successfully restores the terminal state. No residual prints on closing the app.
- High CPU usage due to 100ms tick interval. Now tick interval changed to 5 seconds.

## [0.2.0] - 2023-07-30

Expand Down
19 changes: 11 additions & 8 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "leetcode-tui-rs"
version = "0.2.0"
version = "0.3.0"
edition = "2021"
authors = ["Akarsh <[email protected]>"]
description = "Leetcode terminal UI. Helps you browse leetcode stats and manage your leetcode from terminal."
Expand All @@ -18,7 +18,7 @@ async-trait = "0.1.71"
crossbeam = "0.8.2"
crossterm = { version = "0.26.1", features = ["event-stream"] }
futures = "0.3.28"
futures-timer = "3.0.2"
fuzzy-matcher = "0.3.7"
html2text = "0.6.0"
indexmap = "2.0.0"
kdam = "0.3.0"
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Use Leetcode in your terminal.

![Demo](https://vhs.charm.sh/vhs-7mc1SjatwAFIfEpRjylgaO.gif)
![Demo](https://vhs.charm.sh/vhs-6HARsZDGe7mSVwTepHFUJv.gif)

### Why this TUI:

Expand Down Expand Up @@ -41,6 +41,8 @@ leetui
- Submit and run solution in multiple languages
- Read Stats of your performance
- Solved questions are marked with ✔️
- Neetcode 75
- For Fuzzy search questions in the question list use `/`

Few related projects:

Expand Down
60 changes: 45 additions & 15 deletions src/app_ui/app.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::app_ui::widgets::CommonStateManager;
use std::collections::VecDeque;
use std::rc::Rc;
use std::sync::atomic::AtomicBool;
use std::sync::Arc;

use super::async_task_channel::{ChannelRequestSender, ChannelResponseReceiver};
use super::async_task_channel::{ChannelRequestSender, TaskResponse};
use super::event::VimPingSender;
use super::widgets::help_bar::HelpBar;
use super::widgets::notification::{Notification, WidgetName, WidgetVariant};
Expand All @@ -14,6 +15,7 @@ use super::widgets::topic_list::TopicTagListWidget;
use super::widgets::Widget;
use crate::config::Config;
use crate::errors::AppResult;
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use indexmap::IndexMap;

/// Application.
Expand All @@ -28,8 +30,6 @@ pub struct App {

pub task_request_sender: ChannelRequestSender,

pub task_response_recv: ChannelResponseReceiver,

pub pending_notifications: VecDeque<Option<Notification>>,

pub(crate) popup_stack: Vec<Popup>,
Expand All @@ -45,7 +45,6 @@ impl App {
/// Constructs a new instance of [`App`].
pub fn new(
task_request_sender: ChannelRequestSender,
task_response_recv: ChannelResponseReceiver,
vim_tx: VimPingSender,
vim_running: Arc<AtomicBool>,
config: Rc<Config>,
Expand Down Expand Up @@ -82,7 +81,6 @@ impl App {
widget_map: IndexMap::from(order),
selected_wid_idx: 0,
task_request_sender,
task_response_recv,
pending_notifications: vec![].into(),
popup_stack: vec![],
vim_running,
Expand Down Expand Up @@ -158,7 +156,11 @@ impl App {
}

/// Handles the tick event of the terminal.
pub fn tick(&mut self) -> AppResult<()> {
pub fn tick(&mut self, task: Option<TaskResponse>) -> AppResult<()> {
if let Some(task) = task {
self.process_task(task)?;
}

if let Some(popup) = self.get_current_popup_mut() {
if !popup.is_active() {
self.popup_stack.pop();
Expand All @@ -177,19 +179,15 @@ impl App {
self.pending_notifications.push_back(Some(notif));
}
}

self.check_for_task()?;
self.process_pending_notification()?;
Ok(())
}

fn check_for_task(&mut self) -> AppResult<()> {
if let Ok(task_result) = self.task_response_recv.try_recv() {
self.widget_map
.get_mut(&task_result.get_widget_name())
.unwrap()
.process_task_response(task_result)?;
}
pub fn process_task(&mut self, task: TaskResponse) -> AppResult<()> {
self.widget_map
.get_mut(&task.get_widget_name())
.unwrap()
.process_task_response(task)?;
Ok(())
}

Expand Down Expand Up @@ -218,4 +216,36 @@ impl App {
pub fn quit(&mut self) {
self.running = false;
}

pub fn handle_key_events(&mut self, key_event: KeyEvent) -> AppResult<()> {
let mut p_notif = None;

// if ui has active popups then send only events registered with popup
if let Some(popup) = self.get_current_popup_mut() {
p_notif = popup.handler(key_event)?;
} else if self.get_current_widget().parent_can_handle_events() {
match key_event.code {
KeyCode::Left => p_notif = self.next_widget()?,
KeyCode::Right => p_notif = self.prev_widget()?,
KeyCode::Char('q') | KeyCode::Char('Q') => {
self.running = false;
}
KeyCode::Char('c') | KeyCode::Char('C') => {
if key_event.modifiers == KeyModifiers::CONTROL {
self.running = false;
}
}
_ => {
p_notif = self.get_current_widget_mut().handler(key_event)?;
}
}
} else {
p_notif = self.get_current_widget_mut().handler(key_event)?;
}

self.pending_notifications.push_back(p_notif);
self.tick(None)?;

Ok(())
}
}
5 changes: 0 additions & 5 deletions src/app_ui/async_task_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,3 @@ use super::widgets::notification::WidgetName;

pub type RequestSendError = tokio::sync::mpsc::error::SendError<TaskRequest>;
pub type RequestRecvError = tokio::sync::mpsc::error::TryRecvError;

pub type ResponseSendError = crossbeam::channel::SendError<TaskResponse>;
pub type ResponseReceiveError = crossbeam::channel::RecvError;

// pub type
Loading

0 comments on commit e46b676

Please sign in to comment.