feat: scroll to current contact in sidebar by default

This commit is contained in:
Robert Perce 2026-04-07 10:49:04 -05:00
parent 0baf51646e
commit 62b0efac04
4 changed files with 36 additions and 7 deletions

View file

@ -61,6 +61,21 @@ fn human_delta(span: &jiff::Span) -> String {
mod get {
use super::*;
fn scroll_to(id: DbId) -> String {
format!(
"\
const top = document\
.getElementById('nav-link-{}')\
?.getBoundingClientRect()\
?.top;\
console.log({{ top }});\
top && document\
.getElementById('contacts-sidebar')\
.scrollTo({{top: top+window.innerHeight/2,left:0,behavior:'instant'}});",
id
)
}
pub async fn contact(
auth_session: AuthSession,
State(state): State<AppState>,
@ -125,7 +140,7 @@ mod get {
html! {
a href=(format!("/contact/{}/edit", contact_id)) { "Edit" }
div id="fields" {
div #fields x-init=(scroll_to(contact_id)) {
label { @if contact.names.len() > 1 { "names" } @else { "name" }}
div {
@for name in &contact.names {
@ -249,7 +264,7 @@ mod get {
div #error;
}
#fields x-data=(json!({ "status": contact.status() })){
#fields x-data=(json!({ "status": contact.status() })) x-init=(scroll_to(contact_id)) {
label { @if contact.names.len() > 1 { "names" } @else { "name" }}
div #names x-data=(format!("{{ names: {:?}, new_name: '' }}", &contact.names)) {
template x-for="(name, idx) in names" {