Skip to content

Commit

Permalink
Handle uppercase characters in barcodes correctly (#19)
Browse files Browse the repository at this point in the history
Instead of ignoring the `Shift` modifier, we apply it correctly, which allows us to remove the `lower()` call from the database query, which should improve the query performance by now being able to take advantage of the primary key index.
  • Loading branch information
Turbo87 authored Feb 9, 2025
1 parent 2d34ae4 commit 7c5ca48
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl Article {
r#"
SELECT id, designation, prices
FROM articles
WHERE lower(id) = lower($1)
WHERE id = $1
"#,
)
.bind(barcode)
Expand Down
15 changes: 10 additions & 5 deletions src/running.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl RunningClubFridge {

pub fn subscription(&self) -> Subscription<Message> {
let mut subscriptions = vec![
iced::keyboard::on_key_press(|key, _modifiers| Some(Message::KeyPress(key))),
iced::keyboard::on_key_press(|key, modifiers| Some(Message::KeyPress(key, modifiers))),
iced::time::every(SELF_UPDATE_INTERVAL).map(|_| Message::SelfUpdate),
];

Expand Down Expand Up @@ -307,12 +307,17 @@ impl RunningClubFridge {
Task::none()
});
}
Message::KeyPress(Key::Character(c)) => {
Message::KeyPress(Key::Character(c), modifiers) => {
let mut c = c.chars().next().unwrap();
if modifiers.shift() {
c = c.to_ascii_uppercase();
}

debug!("Key pressed: {c:?}");
self.input.push_str(c.as_str());
self.input.push(c);
self.hide_popup();
}
Message::KeyPress(Key::Named(Named::Enter)) => {
Message::KeyPress(Key::Named(Named::Enter), _) => {
debug!("Key pressed: Enter");
let input = mem::take(&mut self.input);
let pool = self.pool.clone();
Expand All @@ -334,7 +339,7 @@ impl RunningClubFridge {
};
}
#[cfg(debug_assertions)]
Message::KeyPress(Key::Named(Named::Control)) => {
Message::KeyPress(Key::Named(Named::Control), _) => {
use rust_decimal_macros::dec;

let task = if self.user.is_some() {
Expand Down
4 changes: 2 additions & 2 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::database;
use crate::running::RunningClubFridge;
use crate::setup::Setup;
use crate::starting::StartingClubFridge;
use iced::keyboard::Key;
use iced::keyboard::{Key, Modifiers};
use iced::{application, window, Subscription, Task};
use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions};
use sqlx::SqlitePool;
Expand Down Expand Up @@ -139,7 +139,7 @@ pub enum Message {
SelfUpdateResult(Result<self_update::Status, Arc<anyhow::Error>>),
LoadFromVF,
UploadSalesToVF,
KeyPress(Key),
KeyPress(Key, Modifiers),
FindMemberResult {
input: String,
result: Result<Option<database::Member>, Arc<sqlx::Error>>,
Expand Down

0 comments on commit 7c5ca48

Please sign in to comment.