11const h = require ( 'mutant/h' )
22const when = require ( 'mutant/when' )
3- const send = require ( 'mutant/send' )
43const resolve = require ( 'mutant/resolve' )
54const Value = require ( 'mutant/value' )
65const 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 : '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 )
0 commit comments