Skip to content

Commit

Permalink
WIP editing poll flow when editing post
Browse files Browse the repository at this point in the history
  • Loading branch information
leafo committed Jun 7, 2024
1 parent 7f74c10 commit d8289e8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
17 changes: 17 additions & 0 deletions community/flows/posts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,26 @@ do
end
end)() or nil)
})
table.insert(v, {
"poll",
types.empty + types.table
})
end
local post_update = assert_valid(self.params.post, types.params_shape(v))
post_update.body = assert_error(Posts:filter_body(post_update.body, post_update.body_format))
local poll_flow
if post_update.poll then
local PollsFlow = require("community.flows.topic_polls")
poll_flow = PollsFlow(self)
local poll_edit
poll_edit = assert_valid(self.params.topic, types.params_shape({
{
"poll",
poll_flow:validate_params_shape()
}
})).poll
post_update.poll = poll_edit
end
if opts and opts.before_edit_callback then
opts.before_edit_callback(post_update)
end
Expand Down
15 changes: 15 additions & 0 deletions community/flows/posts.moon
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,25 @@ class PostsFlow extends Flow

-- this treats nil and not provided and does not action
table.insert v, {"tags", types.nil + types.empty / (-> {}) + types.limited_text(240) / (category and category\parse_tags or nil) }
table.insert v, {"poll", types.empty + types.table}


post_update = assert_valid @params.post, types.params_shape v
post_update.body = assert_error Posts\filter_body post_update.body, post_update.body_format

local poll_flow
if post_update.poll
PollsFlow = require "community.flows.topic_polls"
poll_flow = PollsFlow @

-- we do validation in separate step to have better error messages
{poll: poll_edit} = assert_valid @params.topic, types.params_shape {
{"poll", poll_flow\validate_params_shape!}
}

post_update.poll = poll_edit


if opts and opts.before_edit_callback
opts.before_edit_callback post_update

Expand Down
2 changes: 1 addition & 1 deletion community/flows/topics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ do
"poll",
poll_flow:validate_params_shape()
}
})).new_poll
})).poll
new_topic.poll = new_poll
assert_error(self.category:allowed_to_create_poll(self.current_user), "you can't create a poll in this category")
end
Expand Down
2 changes: 1 addition & 1 deletion community/flows/topics.moon
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class TopicsFlow extends Flow

if new_topic.poll
-- we do validation like this so we can have nice error messages
{:new_poll} = assert_valid @params.topic, types.params_shape {
{poll: new_poll} = assert_valid @params.topic, types.params_shape {
{"poll", poll_flow\validate_params_shape!}
}

Expand Down

0 comments on commit d8289e8

Please sign in to comment.