comparison src/delete.js.luan @ 42:0c1b820fff34

use push
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 08 Nov 2022 14:02:28 -0700
parents bff178656073
children
comparison
equal deleted inserted replaced
41:acb730710328 42:0c1b820fff34
1 local Luan = require "luan:Luan.luan" 1 local Luan = require "luan:Luan.luan"
2 local error = Luan.error 2 local error = Luan.error
3 local Io = require "luan:Io.luan" 3 local Io = require "luan:Io.luan"
4 local output_of = Io.output_of or error()
4 local Http = require "luan:http/Http.luan" 5 local Http = require "luan:http/Http.luan"
5 local Post = require "site:/lib/Post.luan" 6 local Post = require "site:/lib/Post.luan"
6 local Db = require "site:/lib/Db.luan" 7 local Shared = require "site:/lib/Shared.luan"
8 local base_url = Shared.base_url or error()
7 9
8 10
9 return function() 11 return function()
10 local post = Http.request.parameters.post or error() 12 local post = Http.request.parameters.post or error()
11 Db.run_in_transaction( function() 13 post = Post.get_by_id(post) or error()
12 post = Post.get_by_id(post) or error() 14 local root_id = post.root_id
13 post.author_is_current() or error() 15 post.delete()
14 post.is_deleted = true 16 local js = output_of(function()
15 post.save()
16 end )
17 Io.stdout = Http.response.text_writer()
18 %> 17 %>
19 let postDiv = document.querySelector('[post="<%=post.id%>"]'); 18 deleted( '<%=post.id%>', <%=Post.thread_size(root_id)%> );
20 postDiv.querySelector('[output]').innerHTML = 'deleted';
21 <% 19 <%
20 end)
21 local url = base_url().."/thread.html?root="..root_id
22 Http.push(url,js)
22 end 23 end