Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.

Commit 7df64e8

Browse files
authored
Merge pull request #1176 from ssbc/feature/content-warning-creation
Create Content Warnings (WIP)
2 parents 5866571 + 473aa52 commit 7df64e8

File tree

4 files changed

+72
-8
lines changed

4 files changed

+72
-8
lines changed

lib/depject/message/html/compose.js

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const h = require('mutant/h')
22
const when = require('mutant/when')
3-
const send = require('mutant/send')
43
const resolve = require('mutant/resolve')
54
const Value = require('mutant/value')
65
const computed = require('mutant/computed')
@@ -46,14 +45,17 @@ exports.create = function (api) {
4645
'ev-dragover': onDragOver,
4746
'ev-drop': onDrop,
4847
'ev-input': function () {
49-
hasContent.set(!!textArea.value)
48+
refreshHasContent()
5049
queueSave()
5150
},
5251
'ev-blur': () => {
5352
clearTimeout(blurTimeout)
5453
blurTimeout = setTimeout(() => focused.set(false), 200)
5554
},
56-
'ev-focus': send(focused.set, true),
55+
'ev-focus': () => {
56+
clearTimeout(blurTimeout)
57+
focused.set(true)
58+
},
5759
'ev-paste': ev => {
5860
const files = ev.clipboardData && ev.clipboardData.files
5961
if (!files || !files.length) return
@@ -69,12 +71,32 @@ exports.create = function (api) {
6971
placeholder
7072
})
7173

74+
const contentWarningInput = h('input.contentWarning', {
75+
placeholder: 'Write a content warning (optional)',
76+
'ev-input': function () {
77+
refreshHasContent()
78+
queueSave()
79+
},
80+
'ev-blur': () => {
81+
clearTimeout(blurTimeout)
82+
blurTimeout = setTimeout(() => focused.set(false), 200)
83+
},
84+
'ev-focus': () => {
85+
clearTimeout(blurTimeout)
86+
focused.set(true)
87+
}
88+
})
89+
7290
if (draftKey) {
7391
const draft = window.localStorage[`patchwork.drafts.${draftKey}`]
7492
if (draft) {
7593
textArea.value = draft
76-
hasContent.set(!!textArea.value)
7794
}
95+
const draftCW = window.localStorage[`patchwork.drafts.contentWarning.${draftKey}`]
96+
if (draftCW) {
97+
contentWarningInput.value = draftCW
98+
}
99+
refreshHasContent()
78100
}
79101

80102
const warningMessage = Value(null)
@@ -113,6 +135,7 @@ exports.create = function (api) {
113135

114136
const actions = h('section.actions', [
115137
fileInput,
138+
contentWarningInput,
116139
h('div', [
117140
when(hasContent, clearButton),
118141
publishBtn
@@ -136,7 +159,7 @@ exports.create = function (api) {
136159

137160
composer.setText = function (value) {
138161
textArea.value = value
139-
hasContent.set(!!textArea.value)
162+
refreshHasContent()
140163
}
141164

142165
return composer
@@ -148,10 +171,15 @@ exports.create = function (api) {
148171
return
149172
}
150173
textArea.value = ''
151-
hasContent.set(!!textArea.value)
174+
contentWarningInput.value = ''
175+
refreshHasContent()
152176
save()
153177
}
154178

179+
function refreshHasContent () {
180+
hasContent.set(!!textArea.value || !!contentWarningInput.value)
181+
}
182+
155183
function queueSave () {
156184
saveTimer = setTimeout(save, 1000)
157185
}
@@ -164,6 +192,11 @@ exports.create = function (api) {
164192
} else {
165193
window.localStorage[`patchwork.drafts.${draftKey}`] = textArea.value
166194
}
195+
if (!contentWarningInput.value) {
196+
delete window.localStorage[`patchwork.drafts.contentWarning.${draftKey}`]
197+
} else {
198+
window.localStorage[`patchwork.drafts.contentWarning.${draftKey}`] = contentWarningInput.value
199+
}
167200
}
168201
}
169202

@@ -245,6 +278,10 @@ exports.create = function (api) {
245278
})
246279
})
247280

281+
if (contentWarningInput.value) {
282+
content.contentWarning = contentWarningInput.value
283+
}
284+
248285
try {
249286
if (typeof prepublish === 'function') {
250287
content = prepublish(content)
@@ -271,7 +308,8 @@ exports.create = function (api) {
271308
} else {
272309
if (msg) {
273310
textArea.value = ''
274-
hasContent.set(!!textArea.value)
311+
contentWarningInput.value = ''
312+
refreshHasContent()
275313
save()
276314
}
277315
if (cb) cb(null, msg)

styles/base/compose.mcss

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,16 @@ Compose {
6060
box-shadow: none
6161
}
6262
}
63-
63+
input.contentWarning {
64+
border: 2px solid #ddd;
65+
border-radius: 3px;
66+
flex: 1;
67+
font-size: 120%
68+
margin-left: 5px;
69+
margin-right: 5px;
70+
min-width: 0;
71+
padding: 5px 6px;
72+
}
6473
(button) {
6574
-clear {
6675
margin-right: 5px

styles/dark/compose.mcss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ Compose {
4141
content: "<path d="M13 14c0 2.21-1.79 4-4 4s-4-1.79-4-4V3c0-1.66 1.34-3 3-3s3 1.34 3 3v9c0 1.1-.9 2-2 2s-2-.9-2-2V4h1v8c0 .55.45 1 1 1s1-.45 1-1V3c0-1.1-.9-2-2-2s-2 .9-2 2v11c0 1.66 1.34 3 3 3s3-1.34 3-3V4h1v10z"/>"
4242
}
4343
}
44+
input.contentWarning {
45+
background-color: #2d2c2c;
46+
border: 2px solid #2d2c2c;
47+
color: #ccc
48+
[disabled] {
49+
opacity: 0.5
50+
}
51+
:focus {
52+
outline: 0
53+
}
54+
::-webkit-input-placeholder {
55+
color: #757474
56+
}
57+
}
4458
(button) {
4559
:hover {
4660
background: #6a9fba

styles/light/compose.mcss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ Compose {
4949
content: '📎 Attach File'
5050
}
5151
}
52+
input.contentWarning {
53+
border: 2px solid #dedede8c;
54+
}
5255
}
5356
-expanded {
5457
textarea {

0 commit comments

Comments
 (0)