Show contacts in personal page

O01eg
May 5, 2023, 10:29 AM
7QCJHYB6KSRBFEXLQ7E4ZSBNEZC35FZNLO3FX4IBXO66UJT7GVTAC

Dependencies

Change contents

  • edit in src/templates/my.html at line 29
    [2.833]
    [2.833]
    <table>
    <caption>Your contacts</caption>
    <thead>
    <tr>
    <th>Protocol</th>
    <th>Address</th>
    <th>Activity</th>
    <th>Created</th>
    <th>Deleted</th>
    </tr>
    </thead>
    <tbody>
    {{#each contacts as |contact|}}
    <tr>
    <td>{{ contact.protocol }}</td>
    <td>{{ contact.address }}</td>
    <td>{{#if contact.is_active}}Yes{{else}}No{{/if}}</td>
    <td>{{ contact.create_ts }}</td>
    <td>{{#if contact.delete_ts }} {{ contact.delete_ts }} {{/if}}</td>
    </tr>
    {{/each}}
    </tbody>
    </table>
  • edit in src/pages/my.rs at line 12
    [2.1321]
    [2.1321]
    contacts: Vec<ContactData>,
  • edit in src/pages/my.rs at line 22
    [2.1453]
    [2.1453]
    #[derive(serde_derive::Serialize)]
    struct ContactData {
    protocol: String,
    address: String,
    is_active: bool,
    create_ts: String,
    delete_ts: Option<String>,
    }
    fn naive_to_text(ts: chrono::NaiveDateTime) -> String {
    chrono::DateTime::<chrono::Utc>::from_utc(ts, chrono::Utc)
    .format("%Y %b %d %H:%M UTC")
    .to_string()
    }
  • edit in src/pages/my.rs at line 87
    [2.3217]
    [2.3217]
    });
    }
    let stmt = match dbclient
    .prepare("select protocol::text, address, is_active, create_ts, delete_ts from auth.contacts where player_name = $1;")
    .await
    {
    Ok(stmt) => stmt,
    Err(e) => {
    log::error!("{}", e);
    return HttpResponse::ServiceUnavailable().body(actix_web::body::None::new());
    }
    };
    let rows = match dbclient.query(&stmt, &[&user]).await {
    Ok(rows) => rows,
    Err(e) => {
    log::error!("{}", e);
    return HttpResponse::ServiceUnavailable().body(actix_web::body::None::new());
    }
    };
    let mut contacts = Vec::with_capacity(rows.len());
    for row in rows {
    contacts.push(ContactData {
    protocol: row.get::<_, String>(0),
    address: row.get::<_, String>(1),
    is_active: row.get::<_, bool>(2),
    create_ts: naive_to_text(row.get::<_, chrono::NaiveDateTime>(3)),
    delete_ts: row
    .get::<_, Option<chrono::NaiveDateTime>>(4)
    .map(naive_to_text),
  • edit in src/pages/my.rs at line 130
    [2.3427]
    [2.3427]
    contacts,