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

Commit

Permalink
Merge pull request #1176 from ssbc/feature/content-warning-creation
Browse files Browse the repository at this point in the history
Create Content Warnings (WIP)
  • Loading branch information
cinnamon-bun committed Aug 23, 2019
2 parents 5866571 + 473aa52 commit 7df64e8
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 8 deletions.
52 changes: 45 additions & 7 deletions lib/depject/message/html/compose.js
@@ -1,6 +1,5 @@
const h = require('mutant/h')
const when = require('mutant/when')
const send = require('mutant/send')
const resolve = require('mutant/resolve')
const Value = require('mutant/value')
const computed = require('mutant/computed')
Expand Down Expand Up @@ -46,14 +45,17 @@ exports.create = function (api) {
'ev-dragover': onDragOver,
'ev-drop': onDrop,
'ev-input': function () {
hasContent.set(!!textArea.value)
refreshHasContent()
queueSave()
},
'ev-blur': () => {
clearTimeout(blurTimeout)
blurTimeout = setTimeout(() => focused.set(false), 200)
},
'ev-focus': send(focused.set, true),
'ev-focus': () => {
clearTimeout(blurTimeout)
focused.set(true)
},
'ev-paste': ev => {
const files = ev.clipboardData && ev.clipboardData.files
if (!files || !files.length) return
Expand All @@ -69,12 +71,32 @@ exports.create = function (api) {
placeholder
})

const contentWarningInput = h('input.contentWarning', {
placeholder: 'Write a content warning (optional)',
'ev-input': function () {
refreshHasContent()
queueSave()
},
'ev-blur': () => {
clearTimeout(blurTimeout)
blurTimeout = setTimeout(() => focused.set(false), 200)
},
'ev-focus': () => {
clearTimeout(blurTimeout)
focused.set(true)
}
})

if (draftKey) {
const draft = window.localStorage[`patchwork.drafts.${draftKey}`]
if (draft) {
textArea.value = draft
hasContent.set(!!textArea.value)
}
const draftCW = window.localStorage[`patchwork.drafts.contentWarning.${draftKey}`]
if (draftCW) {
contentWarningInput.value = draftCW
}
refreshHasContent()
}

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

const actions = h('section.actions', [
fileInput,
contentWarningInput,
h('div', [
when(hasContent, clearButton),
publishBtn
Expand All @@ -136,7 +159,7 @@ exports.create = function (api) {

composer.setText = function (value) {
textArea.value = value
hasContent.set(!!textArea.value)
refreshHasContent()
}

return composer
Expand All @@ -148,10 +171,15 @@ exports.create = function (api) {
return
}
textArea.value = ''
hasContent.set(!!textArea.value)
contentWarningInput.value = ''
refreshHasContent()
save()
}

function refreshHasContent () {
hasContent.set(!!textArea.value || !!contentWarningInput.value)
}

function queueSave () {
saveTimer = setTimeout(save, 1000)
}
Expand All @@ -164,6 +192,11 @@ exports.create = function (api) {
} else {
window.localStorage[`patchwork.drafts.${draftKey}`] = textArea.value
}
if (!contentWarningInput.value) {
delete window.localStorage[`patchwork.drafts.contentWarning.${draftKey}`]
} else {
window.localStorage[`patchwork.drafts.contentWarning.${draftKey}`] = contentWarningInput.value
}
}
}

Expand Down Expand Up @@ -245,6 +278,10 @@ exports.create = function (api) {
})
})

if (contentWarningInput.value) {
content.contentWarning = contentWarningInput.value
}

try {
if (typeof prepublish === 'function') {
content = prepublish(content)
Expand All @@ -271,7 +308,8 @@ exports.create = function (api) {
} else {
if (msg) {
textArea.value = ''
hasContent.set(!!textArea.value)
contentWarningInput.value = ''
refreshHasContent()
save()
}
if (cb) cb(null, msg)
Expand Down
11 changes: 10 additions & 1 deletion styles/base/compose.mcss
Expand Up @@ -60,7 +60,16 @@ Compose {
box-shadow: none
}
}

input.contentWarning {
border: 2px solid #ddd;
border-radius: 3px;
flex: 1;
font-size: 120%
margin-left: 5px;
margin-right: 5px;
min-width: 0;
padding: 5px 6px;
}
(button) {
-clear {
margin-right: 5px
Expand Down
14 changes: 14 additions & 0 deletions styles/dark/compose.mcss
Expand Up @@ -41,6 +41,20 @@ Compose {
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"/>"
}
}
input.contentWarning {
background-color: #2d2c2c;
border: 2px solid #2d2c2c;
color: #ccc
[disabled] {
opacity: 0.5
}
:focus {
outline: 0
}
::-webkit-input-placeholder {
color: #757474
}
}
(button) {
:hover {
background: #6a9fba
Expand Down
3 changes: 3 additions & 0 deletions styles/light/compose.mcss
Expand Up @@ -49,6 +49,9 @@ Compose {
content: '📎 Attach File'
}
}
input.contentWarning {
border: 2px solid #dedede8c;
}
}
-expanded {
textarea {
Expand Down

0 comments on commit 7df64e8

Please sign in to comment.