Better handle exists error, prefer webp to png, jpg, banner to jpg, icon to png

This commit is contained in:
asonix 2021-01-06 13:50:44 -06:00
parent 5c280ef6f6
commit c6562da430
2 changed files with 42 additions and 27 deletions

View file

@ -215,23 +215,34 @@ async fn do_create_handle(
let domain = state.domain.clone(); let domain = state.domain.clone();
let handle = form.handle.clone(); let handle = form.handle.clone();
use hyaenidae_profiles::apub::actions::CreateProfile; let exists = state
let res = state
.profiles .profiles
.run(&CreateProfile::from_local(user_id, handle, domain)) .store
.await; .profiles
.by_handle(&handle, &domain)?
.is_some();
let error = match res { let error = if !exists {
Ok(Some(id)) => { use hyaenidae_profiles::apub::actions::CreateProfile;
session
.set("current-profile", CurrentProfile { id }) let res = state
.ok() .profiles
.req()?; .run(&CreateProfile::from_local(user_id, handle, domain))
return Ok(to_bio()); .await;
match res {
Ok(Some(id)) => {
session
.set("current-profile", CurrentProfile { id })
.ok()
.req()?;
return Ok(to_bio());
}
Ok(None) => None,
Err(e) => Some(e.to_string()),
} }
Ok(None) => None, } else {
Err(e) => Some(e.to_string()), Some("Handle already in use".to_owned())
}; };
let mut handle_input = hyaenidae_toolkit::TextInput::new("handle"); let mut handle_input = hyaenidae_toolkit::TextInput::new("handle");

View file

@ -6,14 +6,14 @@
<div class="profile-view--banner"> <div class="profile-view--banner">
@if let Some(banner) = profile.banner_key() { @if let Some(banner) = profile.banner_key() {
<picture> <picture>
<source
type="image/jpeg"
srcset="@banner_srcset(banner, ImageType::Jpeg)"
/>
<source <source
type="image/webp" type="image/webp"
srcset="@banner_srcset(banner, ImageType::Webp)" srcset="@banner_srcset(banner, ImageType::Webp)"
/> />
<source
type="image/jpeg"
srcset="@banner_srcset(banner, ImageType::Jpeg)"
/>
<img <img
href="@largest_banner(banner, ImageType::Jpeg)" href="@largest_banner(banner, ImageType::Jpeg)"
title="@profile.name()'s banner" title="@profile.name()'s banner"
@ -29,16 +29,16 @@
<div class="profile-view--icon"> <div class="profile-view--icon">
@if let Some(icon) = profile.icon_key() { @if let Some(icon) = profile.icon_key() {
<picture> <picture>
<source
type="image/jpeg"
srcset="@icon_srcset(icon, ImageType::Jpeg)"
/>
<source <source
type="image/webp" type="image/webp"
srcset="@icon_srcset(icon, ImageType::Webp)" srcset="@icon_srcset(icon, ImageType::Webp)"
/> />
<source
type="image/png"
srcset="@icon_srcset(icon, ImageType::Png)"
/>
<img <img
href="@largest_icon(icon, ImageType::Jpeg)" href="@largest_icon(icon, ImageType::Png)"
title="@profile.name()'s icon" title="@profile.name()'s icon"
alt="@profile.name()'s icon" alt="@profile.name()'s icon"
/> />
@ -46,10 +46,14 @@
} }
</div> </div>
<div class="profile-view--meta"> <div class="profile-view--meta">
@if let Some(name) = profile.display_name() { <div class="profile-view--meta--display">
<span class="profile-view--meta--display">@name</span> @if let Some(name) = profile.display_name() {
} @name
<span class="profile-view--meta--handle">@@@profile.full_handle()</span> } else {
&nbsp;
}
</div>
<div class="profile-view--meta--handle">@@@profile.full_handle()</div>
</div> </div>
</div> </div>
@if let Some(description) = profile.description() { @if let Some(description) = profile.description() {