diff --git a/README.md b/README.md index c028cf9..0780430 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Sam's small image board. Currently a WIP. ## TODO -- [ ] Rename pool +- [ ] Show pool(s) in post - [ ] CSS - [ ] Logging, better errors... diff --git a/src/lib.rs b/src/lib.rs index 39c8e1d..77ad55d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -133,6 +133,7 @@ pub async fn get_router( .route_with_tsr("/pools/{page}", get(get_pools_page)) .route_with_tsr("/pool", post(create_pool)) .route_with_tsr("/pool/{pool_id}", get(view_pool)) + .route_with_tsr("/pool/{pool_id}/name", put(change_pool_name)) .route_with_tsr("/pool/{pool_id}/public", put(change_pool_visibility)) .route_with_tsr("/pool/{pool_id}/post", post(add_post_to_pool)) .route_with_tsr("/pool/{pool_id}/sort", put(sort_pool)) diff --git a/src/views.rs b/src/views.rs index 405140d..4ef8e51 100644 --- a/src/views.rs +++ b/src/views.rs @@ -785,6 +785,57 @@ pub(crate) async fn view_pool( )) } +#[derive(Debug, Deserialize)] +pub(crate) struct ChangePoolNameForm { + pool_name: String, +} + +#[derive(Template)] +#[template(path = "fragments/change_pool_name.html")] +struct ChangePoolNameTemplate { + pool_name: String, +} + +pub(crate) async fn change_pool_name( + State(AppState { db, .. }): State, + auth_session: AuthSession, + Path(pool_id): Path, + Form(body): Form, +) -> Result { + let pool = SameyPool::find_by_id(pool_id) + .one(&db) + .await? + .ok_or(SameyError::NotFound)?; + + let can_edit = match auth_session.user.as_ref() { + None => false, + Some(user) => user.is_admin || pool.uploader_id == user.id, + }; + + if !can_edit { + return Err(SameyError::Forbidden); + } + + if body.pool_name.trim().is_empty() { + return Err(SameyError::BadRequest("Pool name cannot be empty".into())); + } + + SameyPool::update(samey_pool::ActiveModel { + id: Set(pool.id), + name: Set(body.pool_name.clone()), + ..Default::default() + }) + .exec(&db) + .await?; + + Ok(Html( + ChangePoolNameTemplate { + pool_name: body.pool_name, + } + .render()?, + )) +} + #[derive(Debug, Deserialize)] pub(crate) struct ChangePoolVisibilityForm { is_public: Option, @@ -799,7 +850,7 @@ pub(crate) async fn change_pool_visibility( let pool = SameyPool::find_by_id(pool_id) .one(&db) .await? - .expect("Pool for samey_pool_post must exist"); + .ok_or(SameyError::NotFound)?; let can_edit = match auth_session.user.as_ref() { None => false, diff --git a/static/samey.css b/static/samey.css index e69de29..81e284b 100644 --- a/static/samey.css +++ b/static/samey.css @@ -0,0 +1,42 @@ +img { + max-width: none; +} + +div.center-item { + display: flex; + align-items: center; + justify-content: safe center; +} + +ul.reset, +ul.reset li, +ul.reset ul li { + margin: 0; + padding: 0; + text-indent: 0; + list-style-type: none; +} + +.flex { + display: flex; + flex-wrap: wrap; + align-items: center; + justify-content: center; + column-gap: 1rem; +} + +.flex-col { + flex-direction: column; +} + +ul.tags-autocomplete { + text-indent: 0; + list-style-type: none; + position: absolute; +} + +ul.tags-autocomplete li button { + --button-base: #dbdbdb; + --button-hover: #a9b1ba; + color: #040a0f; +} diff --git a/templates/fragments/change_pool_name.html b/templates/fragments/change_pool_name.html new file mode 100644 index 0000000..c0a4fdd --- /dev/null +++ b/templates/fragments/change_pool_name.html @@ -0,0 +1 @@ +

Pool - {{ pool_name }}

diff --git a/templates/fragments/common_headers.html b/templates/fragments/common_headers.html index cae428e..500dd9e 100644 --- a/templates/fragments/common_headers.html +++ b/templates/fragments/common_headers.html @@ -4,3 +4,4 @@ + diff --git a/templates/fragments/edit_post_details.html b/templates/fragments/edit_post_details.html index 39ba21b..6fdf1ed 100644 --- a/templates/fragments/edit_post_details.html +++ b/templates/fragments/edit_post_details.html @@ -2,7 +2,7 @@
{% let tags_value = tags %} {% include "fragments/tags_input.html" %} -
    +
      @@ -32,14 +32,14 @@ {% include "fragments/post_source.html" %} {% endfor %} - +
      - +
      - +
      diff --git a/templates/fragments/pool_posts.html b/templates/fragments/pool_posts.html index 395b97b..dec33fb 100644 --- a/templates/fragments/pool_posts.html +++ b/templates/fragments/pool_posts.html @@ -3,7 +3,7 @@ No posts in pool. {% else %}
        {% for post in posts %} -
      • +
      • -
        {{ post.rating | upper }}
        -
        {{ post.media_type }}
        +
        +
        {{ post.rating | upper }}
        +
        {{ post.media_type }}
        +
        {% if can_edit %} {% endif %}
      • diff --git a/templates/fragments/post_details.html b/templates/fragments/post_details.html index 35f5d29..51d6410 100644 --- a/templates/fragments/post_details.html +++ b/templates/fragments/post_details.html @@ -51,6 +51,6 @@ {{ post.uploaded_at }} {% if can_edit %} - + {% endif %} diff --git a/templates/fragments/post_source.html b/templates/fragments/post_source.html index cd1fc4f..d311176 100644 --- a/templates/fragments/post_source.html +++ b/templates/fragments/post_source.html @@ -6,6 +6,6 @@ value="{% if let Some(url) = source.url %}{{ url }}{% endif %}" /> diff --git a/templates/fragments/post_thumbnail.html b/templates/fragments/post_thumbnail.html new file mode 100644 index 0000000..7029080 --- /dev/null +++ b/templates/fragments/post_thumbnail.html @@ -0,0 +1,7 @@ + + +
        +
        {{ post.rating | upper }}
        +
        {{ post.media_type }}
        +
        +
        diff --git a/templates/fragments/select_tag.html b/templates/fragments/select_tag.html index bdd849a..8ded359 100644 --- a/templates/fragments/select_tag.html +++ b/templates/fragments/select_tag.html @@ -1,2 +1,5 @@ {% include "fragments/tags_input.html" %} -
          +
            diff --git a/templates/fragments/submit_post_details.html b/templates/fragments/submit_post_details.html index 7b57b79..567950a 100644 --- a/templates/fragments/submit_post_details.html +++ b/templates/fragments/submit_post_details.html @@ -1,14 +1,19 @@ {% include "fragments/post_details.html" %} {% if let Some(parent_post) = parent_post %} {% else %} diff --git a/templates/pages/create_pool.html b/templates/pages/create_pool.html index c9bf8f8..cfbc347 100644 --- a/templates/pages/create_pool.html +++ b/templates/pages/create_pool.html @@ -18,7 +18,7 @@ placeholder="Name" autofocus /> - + diff --git a/templates/pages/index.html b/templates/pages/index.html index dc29f04..2c15cf8 100644 --- a/templates/pages/index.html +++ b/templates/pages/index.html @@ -11,12 +11,12 @@

            Search

            {% let tags_value = "" %} {% include "fragments/tags_input.html" %} -
              +