Skip to content

Commit a896f94

Browse files
committed
[ post editing ] editing kinda works.
1 parent c987edc commit a896f94

4 files changed

Lines changed: 30 additions & 20 deletions

File tree

lib/depject/message/html/actions.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,17 @@ exports.gives = nest("message.html.actions");
2323
exports.create = (api) => {
2424
const i18n = api.intl.sync.i18n;
2525

26-
return nest("message.html.actions", function like(msg, opts) {
26+
return nest("message.html.actions", function like(msg, opts = {}) {
2727
const liked = api.message.obs.doesLike(msg.key);
2828

2929
const customActions = [];
3030

31-
if (typeof opts === undefined || !opts?.onEdited) {
32-
onEdited = (msg) => {
33-
console.log(`message edited`, msg);
34-
};
31+
let onEdited = (msg) => {
32+
console.log(`message edited`, msg);
33+
};
34+
35+
if (Object.hasOwn(opts, "onEdited")) {
36+
onEdited = opts.onEdited;
3537
}
3638

3739
if (isFeatureEnabled("custom-scripts")) {

lib/depject/message/html/layout/default.js

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const nest = require("depnest");
33
const ref = require("ssb-ref");
44
const ExpanderHook = require("../../../../expander-hook");
55
const timestamp = require("../../../../message/html/timestamp");
6+
const crypto = require("crypto");
67

78
exports.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
}

lib/depject/message/obs/edits.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ exports.gives = nest("message.obs.edits");
1010
exports.create = function (api) {
1111
return nest("message.obs.edits", function (key, hintMessage = null) {
1212
if (!ref.isMsg(key)) throw new Error("a msg id must be specified");
13-
const edited = Value(false);
13+
const edited = MutantArray([]);
1414

1515
onceTrue(api.sbot.obs.connection, (sbot) => {
1616
pull(

lib/depject/sheet/editPost.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ exports.create = function (api) {
118118
revisionBranch: revisionBranch(),
119119
};
120120

121-
console.log("post-edit obj", obj);
122-
123121
api.sbot.async.publish(obj, done);
124122

125123
function done(err, msg) {
@@ -134,7 +132,6 @@ exports.create = function (api) {
134132
detail: err.message,
135133
});
136134
} else {
137-
console.log(msg);
138135
callback(msg);
139136
}
140137
}

0 commit comments

Comments
 (0)