From 6a465257af87768871b51970839591b794106391 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Thu, 22 Jun 2023 19:32:51 -0700 Subject: [PATCH] reply button adds a reply Still lots broken: - can't add more than one comment (not updating parent.replies) - not updating metadata on disk --- 0006-on.mouse_press | 7 ++++--- 0021-compute_layout | 7 +++++++ 0118-load_subtree | 17 ++++++----------- 0139-new_comment | 18 ++++++++++++++++++ 0140-next_comment | 5 +++++ 0141-indent | 3 +++ 0142-reply_button | 10 ++++++++++ 7 files changed, 53 insertions(+), 14 deletions(-) create mode 100644 0139-new_comment create mode 100644 0140-next_comment create mode 100644 0141-indent create mode 100644 0142-reply_button diff --git a/0006-on.mouse_press b/0006-on.mouse_press index 54aa45f..b751dee 100644 --- a/0006-on.mouse_press +++ b/0006-on.mouse_press @@ -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 \ No newline at end of file +end diff --git a/0021-compute_layout b/0021-compute_layout index db071e4..adc75da 100644 --- a/0021-compute_layout +++ b/0021-compute_layout @@ -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 diff --git a/0118-load_subtree b/0118-load_subtree index ade9c38..62fab08 100644 --- a/0118-load_subtree +++ b/0118-load_subtree @@ -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 diff --git a/0139-new_comment b/0139-new_comment new file mode 100644 index 0000000..6d3b503 --- /dev/null +++ b/0139-new_comment @@ -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 \ No newline at end of file diff --git a/0140-next_comment b/0140-next_comment new file mode 100644 index 0000000..6c33a02 --- /dev/null +++ b/0140-next_comment @@ -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 \ No newline at end of file diff --git a/0141-indent b/0141-indent new file mode 100644 index 0000000..f1daeb1 --- /dev/null +++ b/0141-indent @@ -0,0 +1,3 @@ +indent = function(depth) + return {type='rectangle', w=depth*Indent, h=0} +end \ No newline at end of file diff --git a/0142-reply_button b/0142-reply_button new file mode 100644 index 0000000..4609681 --- /dev/null +++ b/0142-reply_button @@ -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 \ No newline at end of file