reply button adds a reply
Still lots broken: - can't add more than one comment (not updating parent.replies) - not updating metadata on disk
This commit is contained in:
parent
5cf3d9bc2c
commit
6a465257af
|
@ -29,10 +29,11 @@ on.mouse_press = function(x,y, mouse_button)
|
|||
end
|
||||
local button = on_button(x,y)
|
||||
if button then
|
||||
-- HERE
|
||||
button.bg = {r=1,g=0,b=0}
|
||||
table.insert(Global_state.thread.data,
|
||||
button.item_index+1,
|
||||
new_comment(button.name, button.depth))
|
||||
A()
|
||||
end
|
||||
-- pan surface
|
||||
Pan = {x=Viewport.x+x/Viewport.zoom,y=Viewport.y+y/Viewport.zoom}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,11 @@
|
|||
compute_layout = function(node, x,y, nodes_to_render, preserve_screen_top_of_cursor_node)
|
||||
--[[ --debug prints when modifying the DOM
|
||||
if node.type == 'rows' or node.type == 'cols' then
|
||||
print(node.type, node.button, #node.data)
|
||||
else
|
||||
print(node.type, node.button)
|
||||
end
|
||||
--]]
|
||||
-- append to nodes_to_render flattened instructions to render a hierarchy of nodes
|
||||
-- return x,y rendered until (surface coordinates)
|
||||
if node.type == 'text' then
|
||||
|
|
|
@ -2,22 +2,17 @@ load_subtree = function(filename, out, depth)
|
|||
-- load a file and recursively all replies to it
|
||||
-- print('load_subtree', filename)
|
||||
local item = initialize_item(filename, depth)
|
||||
-- every item is a row consisting of two columns:
|
||||
-- one column of padding and another of text
|
||||
-- every item renders to a row consisting of two
|
||||
-- columns: padding and 'item stuff'
|
||||
local row = cols(Inter_comment_spacing)
|
||||
table.insert(out, row)
|
||||
table.insert(row.data,
|
||||
{type='rectangle', w=depth*Indent, h=0})
|
||||
table.insert(row.data, indent(depth))
|
||||
-- item stuff consists of text and a reply button
|
||||
local item_stuff = rows()
|
||||
table.insert(row.data, item_stuff)
|
||||
table.insert(item_stuff.data, item)
|
||||
table.insert(item_stuff.data, {
|
||||
type='text', data={{data='reply'}},
|
||||
button=true, name=filename,
|
||||
margin=20,
|
||||
bg=Reply_button_color,
|
||||
border=Reply_button_border_color,
|
||||
})
|
||||
table.insert(item_stuff.data,
|
||||
reply_button(filename, #out, depth))
|
||||
for i,reply_id in ipairs(item.metadata.replies) do
|
||||
local reply = load_subtree(reply_id, out, depth+1)
|
||||
end
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
new_comment = function(parent_id, depth)
|
||||
local comment = {
|
||||
type='text',
|
||||
filename=full_path(next_comment(parent_id)),
|
||||
data={{data=''}},
|
||||
width=Width,
|
||||
depth=depth+1,
|
||||
metadata={replies={}},
|
||||
border=Border_color,
|
||||
}
|
||||
local result = cols(20)
|
||||
table.insert(result.data, indent(depth+1))
|
||||
local item_stuff = rows()
|
||||
table.insert(result.data, item_stuff)
|
||||
table.insert(item_stuff.data, comment)
|
||||
table.insert(item_stuff.data, reply_button(comment.filename, 0, depth+1))
|
||||
return result
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
next_comment = function(id)
|
||||
local num_replies = #load_metadata(id).replies
|
||||
local corename = id:gsub('%.md$', '')
|
||||
return ('%s-%d.md'):format(corename, num_replies)
|
||||
end
|
|
@ -0,0 +1,3 @@
|
|||
indent = function(depth)
|
||||
return {type='rectangle', w=depth*Indent, h=0}
|
||||
end
|
|
@ -0,0 +1,10 @@
|
|||
reply_button = function(filename, index, depth)
|
||||
return {
|
||||
type='text', data={{data='reply'}},
|
||||
button=true, margin=20,
|
||||
name=filename, item_index=index,
|
||||
depth=depth,
|
||||
bg=Reply_button_color,
|
||||
border=Reply_button_border_color,
|
||||
}
|
||||
end
|
Loading…
Reference in New Issue