make categories global
This commit is contained in:
+7
-18
@@ -74,7 +74,7 @@ pub fn build_router(state: AppState) -> Router {
|
||||
.route("/lists/{list_id}/items/{item_id}/check", post(check_item))
|
||||
.route("/lists/{list_id}/items/{item_id}/edit", post(edit_item))
|
||||
.route("/lists/{list_id}/items/{item_id}/delete", post(delete_item))
|
||||
.route("/lists/{list_id}/categories", post(create_category))
|
||||
.route("/categories", post(create_category))
|
||||
.route("/invitations", post(create_invitation))
|
||||
.route("/lists/{list_id}/stream", get(list_stream))
|
||||
.route("/invite/{token}", get(invitation_page))
|
||||
@@ -361,7 +361,7 @@ async fn list_page(
|
||||
) -> Result<Response, AppError> {
|
||||
let access = require_list(&state, list_id).await?;
|
||||
let items = state.lists.items(list_id).await?;
|
||||
let categories = state.lists.categories(list_id).await?;
|
||||
let categories = state.lists.categories().await?;
|
||||
let presence = state.realtime.presence(list_id).await;
|
||||
Ok(html_response(views::list_page(
|
||||
&user.session.user,
|
||||
@@ -460,28 +460,17 @@ async fn delete_item(
|
||||
async fn create_category(
|
||||
State(state): State<AppState>,
|
||||
user: CurrentUser,
|
||||
Path(list_id): Path<i64>,
|
||||
LoggedForm(form): LoggedForm<CategoryForm>,
|
||||
) -> Result<Response, AppError> {
|
||||
verify_csrf(&user, &form.csrf)?;
|
||||
require_list(&state, list_id).await?;
|
||||
let name = form.name.trim().to_owned();
|
||||
if name.is_empty() || name.chars().count() > 60 {
|
||||
return Err(AppError::BadRequest(
|
||||
"Category names must be between 1 and 60 characters.".into(),
|
||||
));
|
||||
}
|
||||
state.lists.create_category(list_id, name).await?;
|
||||
|
||||
let access = require_list(&state, list_id).await?;
|
||||
let items = state.lists.items(list_id).await?;
|
||||
let categories = state.lists.categories(list_id).await?;
|
||||
Ok(html_response(views::category_created(
|
||||
&access,
|
||||
&items,
|
||||
&categories,
|
||||
&user.session.csrf_token,
|
||||
)))
|
||||
state.lists.create_category(name).await?;
|
||||
Ok(Redirect::to("/lists").into_response())
|
||||
}
|
||||
|
||||
async fn create_invitation(
|
||||
@@ -647,7 +636,7 @@ async fn websocket_snapshot(
|
||||
) -> Result<String, AppError> {
|
||||
let access = require_list(state, list_id).await?;
|
||||
let items = state.lists.items(list_id).await?;
|
||||
let categories = state.lists.categories(list_id).await?;
|
||||
let categories = state.lists.categories().await?;
|
||||
Ok(
|
||||
views::live_list_fragments(&access, &items, &categories, &user.session.csrf_token)
|
||||
.into_string()
|
||||
@@ -662,7 +651,7 @@ async fn websocket_list_update(
|
||||
) -> Result<String, AppError> {
|
||||
let access = require_list(state, list_id).await?;
|
||||
let items = state.lists.items(list_id).await?;
|
||||
let categories = state.lists.categories(list_id).await?;
|
||||
let categories = state.lists.categories().await?;
|
||||
Ok(
|
||||
views::live_list_fragments(&access, &items, &categories, &user.session.csrf_token)
|
||||
.into_string(),
|
||||
@@ -676,7 +665,7 @@ async fn list_fragment_response(
|
||||
) -> Result<Response, AppError> {
|
||||
let access = require_list(state, list_id).await?;
|
||||
let items = state.lists.items(list_id).await?;
|
||||
let categories = state.lists.categories(list_id).await?;
|
||||
let categories = state.lists.categories().await?;
|
||||
Ok(html_response(views::list_items_fragment(
|
||||
&access,
|
||||
&items,
|
||||
|
||||
Reference in New Issue
Block a user