Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aviary #17

Merged
merged 15 commits into from
Sep 22, 2024
10 changes: 9 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ jobs:
- uses: Swatinem/rust-cache@v2
with:
cache-all-crates: "true"
cache-on-failure: "true"

- name: Install npm
uses: actions/setup-node@v4

- name: npm install
working-directory: app
run: npm ci;

# dotenvy requires this
- run: cp .env.example .env
Expand All @@ -40,4 +48,4 @@ jobs:
run: cargo +nightly fmt --all -- --check

- name: cargo clippy
run: cargo +stable clippy --all --all-features -- -D warnings
run: cargo +stable clippy --all-features -- -D warnings
112 changes: 28 additions & 84 deletions Cargo.lock

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

4 changes: 1 addition & 3 deletions app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ dioxus = { workspace = true }
dioxus-logger = { workspace = true }
dioxus-sdk = { workspace = true }
dotenvy_macro = "0.15.7"
gloo-net = { version = "0.5.0", features = ["json"] }
gloo-net = { version = "0.6.0", features = ["json"] }
once_cell = "1.19.0"
postgrest = "1.6.0"
rand = "0.8.5"
reqwest = { version = "0.11.27", features = ["json"] }
serde = { workspace = true }
serde-querystring = "0.2.1"
serde_json = { workspace = true }
Expand Down
Binary file added app/assets/aviary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 30 additions & 4 deletions app/src/bird.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};

use crate::supabase::{self, Error, Result, SupabaseResource};

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, Eq)]
pub struct Bird {
pub id: u64,
pub common_name: String,
Expand All @@ -12,7 +12,7 @@ pub struct Bird {
pub sounds: Vec<Sound>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct Sound {
pub path: String,
pub default_: bool,
Expand All @@ -24,6 +24,12 @@ impl PartialEq for Bird {
}
}

impl std::hash::Hash for Bird {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.id.hash(state);
}
}

impl Bird {
/// Get image URL hosted by Supabase storage, e.g. http://127.0.0.1:54321/storage/v1/object/public/bird_images/cardinalis-cardinalis/unlicensed-optimized.jpg
pub fn image_url(&self) -> String {
Expand All @@ -33,6 +39,21 @@ impl Bird {
pub fn default_sound_url(&self) -> String {
supabase::storage_object_url(&self.sounds[0].path)
}

/// Query db for birds by id
// TODO: enforce global limit? I think supabase limits 1000 by default.
pub async fn fetch_by_ids<I>(ids: I) -> Result<Vec<Self>>
where
I: IntoIterator<Item = u64>,
{
Self::request().select("*").in_("id", ids).execute().await
}
}

impl SupabaseResource for Bird {
fn table_name() -> &'static str {
"birds_detailed"
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -68,12 +89,17 @@ impl BirdPack {
.ok_or_else(|| Error::from(format!("No pack found with id {id} 🙈")))
}

/// Query db for pack of the day (respects local time)
/// Query db for pack of today (respects local time)
pub async fn fetch_today() -> Result<Self> {
let day = chrono::offset::Local::now().date_naive();
Self::fetch_by_day(day).await
}

/// Query db for pack of a given day (respects local time)
pub async fn fetch_by_day(day: NaiveDate) -> Result<Self> {
Self::request()
.select("*")
.eq("day", day.format("%Y-%m-%d").to_string())
.eq("day", day.format("%Y-%m-%d"))
.execute()
.await?
.pop()
Expand Down
2 changes: 2 additions & 0 deletions app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ use tracing::Level;

mod bird;
mod conf;
mod pack;
mod stats;
mod supabase;
mod sync;
mod ui;
mod utils;

fn main() {
// Init storage
Expand Down
Loading
Loading