@@ -3,6 +3,7 @@ const nest = require("depnest");
33const ref = require ( "ssb-ref" ) ;
44const ExpanderHook = require ( "../../../../expander-hook" ) ;
55const timestamp = require ( "../../../../message/html/timestamp" ) ;
6+ const crypto = require ( "crypto" ) ;
67
78exports . needs = nest ( {
89 "profile.html.person" : "first" ,
@@ -57,19 +58,20 @@ exports.create = function (api) {
5758 const needsExpand = Value ( false ) ;
5859 const expanded = Value ( false ) ;
5960 const contentToShow = Value ( content ) ;
61+ const hasEdits = Value ( false ) ;
6062
61- let edits = Value ( false ) ;
63+ let edits = MutantArray ( [ ] ) ;
64+ let showing = Value ( - 1 ) ;
6265
6366 if ( msg ?. value ?. content ?. type === "post" && msg ?. key ) {
64- edits = api . message . obs . edits ( msg . key ) ;
67+ const newEdits = api . message . obs . edits ( msg . key ) ;
68+ newEdits ( ( es ) => {
69+ edits . set ( es ) ;
70+ hasEdits . set ( true ) ;
71+ } ) ;
6572 }
6673
67- onEdited = ( msg ) => {
68- // edits = api.message.obs.edits(msg.key);
69- const md = api . message . html . markdown ( msg . value . content . text ) ;
70- contentToShow . set ( md ) ;
71- console . log ( "edited" , md ) ;
72- } ;
74+ let uuid = crypto . randomUUID ( ) ;
7375
7476 // new message previews shouldn't contract
7577 if ( ! msg . key ) expanded . set ( true ) ;
@@ -133,6 +135,7 @@ exports.create = function (api) {
133135 h ( "section.content" , {
134136 classList : [ when ( expanded , "-expanded" ) ] ,
135137 hooks : [ ExpanderHook ( needsExpand ) ] ,
138+ id : uuid ,
136139 } , contentToShow ) ,
137140 computed ( msg . key , ( key ) => {
138141 if ( ref . isMsg ( key ) ) {
@@ -149,7 +152,16 @@ exports.create = function (api) {
149152 ] ) ,
150153 ) ,
151154 h ( "div.actions" , [
152- api . message . html . actions ( msg , { onEdited } ) ,
155+ api . message . html . actions ( msg , {
156+ onEdited : ( m ) => {
157+ // edits = api.message.obs.edits(msg.key);
158+ console . log ( edits ( ) ) ;
159+ edits . push ( m ) ;
160+ showing . set ( edits . getLength ( ) - 1 ) ;
161+ console . log ( edits ( ) ) ;
162+ console . log ( showing ( ) ) ;
163+ } ,
164+ } ) ,
153165 ] ) ,
154166 ] ) ;
155167 }
@@ -161,7 +173,6 @@ exports.create = function (api) {
161173 // scoped
162174
163175 function editControl ( ) {
164- let showing = Value ( - 1 ) ;
165176 edits ( ( es ) => {
166177 showing . set ( es . length - 1 ) ;
167178 } ) ;
@@ -252,7 +263,7 @@ exports.create = function (api) {
252263 h ( "div.meta" , [
253264 additionalMeta ,
254265 api . message . html . metas ( msg ) ,
255- when ( edits , editControl ( ) ) ,
266+ when ( hasEdits , editControl ( ) ) ,
256267 ] ) ,
257268 ] ) ;
258269 }
0 commit comments