Skip to content

Commit

Permalink
Add total days without APLang
Browse files Browse the repository at this point in the history
  • Loading branch information
vbe0201 committed Aug 8, 2023
1 parent ea1293f commit bd52b23
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ pub fn _setup_console_error() {
}

#[wasm_bindgen]
pub async fn fetch_latest_commit(repo: &str) -> Result<JsValue, JsValue> {
pub async fn fetch_latest_commit(repo: &str, start: f64) -> Result<JsValue, JsValue> {
let mut opts = RequestInit::new();
opts.method("GET");
opts.mode(RequestMode::Cors);

let url = format!("https://api.github.com/repos/{repo}/commits");
let url = format!("https://api.github.com/repos/{repo}/commits?per_page=1");
let request = Request::new_with_str_and_init(&url, &opts)?;
request
.headers()
Expand All @@ -36,10 +36,10 @@ pub async fn fetch_latest_commit(repo: &str) -> Result<JsValue, JsValue> {
let response: Response = response.dyn_into().unwrap();

let json = JsFuture::from(response.json()?).await?;
extract_first_commit_info(json)
extract_first_commit_info(json, start)
}

fn extract_first_commit_info(json: JsValue) -> Result<JsValue, JsValue> {
fn extract_first_commit_info(json: JsValue, start: f64) -> Result<JsValue, JsValue> {
let first = Reflect::get_u32(&json, 0)?;

let sha = Reflect::get(&first, &JsValue::from_str("sha"))?;
Expand All @@ -48,10 +48,10 @@ fn extract_first_commit_info(json: JsValue) -> Result<JsValue, JsValue> {
let date = Reflect::get(&author, &JsValue::from_str("date"))?;

let date = Date::new(&date).get_time();
let days = utils::get_elapsed_days_since(date);

js_object! {
sha: sha,
days: days.into(),
days: utils::get_elapsed_days_since(date).into(),
daysTotal: utils::get_elapsed_days_since(start).into(),
}
}
6 changes: 4 additions & 2 deletions www/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as aplang from "areweaplangyet-wasm";

const REPO = "APLanguage/aplang-rs";
const START_TIME = 1613750769000.0;

function getPhrase(days) {
if (days == 0) {
Expand All @@ -11,12 +12,13 @@ function getPhrase(days) {
}

async function renderProgress() {
const res = await aplang.fetch_latest_commit(REPO);
const res = await aplang.fetch_latest_commit(REPO, START_TIME);

const commit = `https://github.com/${REPO}/commit/${res.sha}`;
const phrase = getPhrase(res.days);

const fmt = `It's been ${res.days} days since the last <a href="${commit}">commit</a>. ${phrase}!`;
const fmt = `${res.daysTotal} days without APLang, ${res.days} days since the last \
<a href="${commit}">commit</a>. ${phrase}!`;
document.getElementById("aplang-info").innerHTML = fmt;
}

Expand Down
6 changes: 3 additions & 3 deletions www/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -749,9 +749,9 @@ ee-first@1.1.1:
integrity sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==

electron-to-chromium@^1.4.477:
version "1.4.486"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.486.tgz#11bc573ecf245c183f55cfe32ba209a22a96237a"
integrity sha512-9zn9/2lbMGY/mFhoUymD9ODYdLY3zjUW/IW9ihU/sJVeIlD70m2aAb86S35aRGF+iwqLuQP25epruayZjKNjBw==
version "1.4.487"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.487.tgz#e2ef8b15f2791bf68fa6f38f2656f1a551d360ae"
integrity sha512-XbCRs/34l31np/p33m+5tdBrdXu9jJkZxSbNxj5I0H1KtV2ZMSB+i/HYqDiRzHaFx2T5EdytjoBRe8QRJE2vQg==

encodeurl@~1.0.2:
version "1.0.2"
Expand Down

0 comments on commit bd52b23

Please sign in to comment.