1
0
Fork 0

Finally revisiting this CW thing

Respect reading:expand:spoilers and reading:expand:media but differently than Mastodon's logic
This commit is contained in:
Lim Chee Aun 2023-12-24 21:07:46 +08:00
parent 088d795595
commit 6dd54633e0
4 changed files with 134 additions and 102 deletions

View file

@ -499,28 +499,25 @@
padding-bottom: 10px; padding-bottom: 10px;
} }
.status .content-container.has-spoiler .spoiler { .status
.content-container.has-spoiler
:is(.spoiler-button, .spoiler-media-button):not([hidden]) {
margin: 4px 0; margin: 4px 0;
font-size: 90%; font-size: 90%;
border: 1px dashed var(--button-bg-color); border: 1px dashed var(--button-bg-color);
display: flex; display: flex;
gap: 8px; gap: 4px;
align-items: center; align-items: center;
} }
.status .status .content-container.has-spoiler:not(.show-spoiler) .spoiler-button {
.content-container.has-spoiler:not(.show-spoiler) ~ *:not(
.spoiler .media-container,
~ *:not(.media-container, .card, .media-figure-multiple), .card,
.status .media-figure-multiple,
.content-container.has-spoiler:not(.show-spoiler) .spoiler-media-button
.spoiler ),
~ .card ~ .card .meta-container,
.meta-container, ~ :is(.media-container, .media-figure-multiple) figcaption {
.status
.content-container.has-spoiler:not(.show-spoiler)
.spoiler
~ :is(.media-container, .media-figure-multiple)
figcaption {
filter: blur(5px) invert(0.5); filter: blur(5px) invert(0.5);
image-rendering: crisp-edges; image-rendering: crisp-edges;
image-rendering: pixelated; image-rendering: pixelated;
@ -529,46 +526,42 @@
contain: layout; contain: layout;
transform: scale(0.97); transform: scale(0.97);
transition: transform 0.1s ease-in-out; transition: transform 0.1s ease-in-out;
} }
.status
.content-container.has-spoiler:not(.show-spoiler) /* ~ :is(.media-container, .media-figure-multiple) .media > *, */
.spoiler ~ .card > img {
~ :is(.media-container, .media-figure-multiple)
.media
> *,
.status
.content-container.has-spoiler:not(.show-spoiler)
.spoiler
~ .card
> img {
filter: blur(32px); filter: blur(32px);
image-rendering: crisp-edges; image-rendering: crisp-edges;
image-rendering: pixelated; image-rendering: pixelated;
animation: none !important; animation: none !important;
}
} }
.status .content-container.show-spoiler .spoiler { .status .content-container.has-spoiler:not(.show-media) .spoiler-media-button {
~ :is(.media-container, .media-figure-multiple) .media > * {
filter: blur(32px);
image-rendering: crisp-edges;
image-rendering: pixelated;
animation: none !important;
}
}
.status
.content-container.show-spoiler
:is(.spoiler-button, .spoiler-media-button).spoiling {
border-style: dotted; border-style: dotted;
} }
/* .status
.content-container.show-spoiler .status .content-container .spoiler-divider {
.spoiler display: flex;
~ *:not(.media-container, .card), align-items: center;
.status .content-container.show-spoiler .spoiler ~ .card .meta-container { gap: 4px;
filter: none !important; color: var(--text-insignificant-color);
transform: none; text-transform: uppercase;
pointer-events: auto; font-size: 0.8em;
user-select: auto; margin-top: 0.25em;
text-rendering: auto; margin-bottom: 1em;
image-rendering: auto; padding-block: 0.25em;
border-bottom: 1px dashed var(--divider-color);
} }
.status .content-container.show-spoiler .spoiler ~ .media-container .media > *,
.status .content-container.show-spoiler .spoiler ~ .card > img {
filter: none;
image-rendering: auto;
} */
/* .status .content a:not(.mention):not(:has(span)) {
color: inherit;
} */
.status .content-comment-hint { .status .content-comment-hint {
margin-top: 0.25em; margin-top: 0.25em;

View file

@ -275,8 +275,21 @@ function Status({
const prefs = store.account.get('preferences') || {}; const prefs = store.account.get('preferences') || {};
return !!prefs['reading:expand:spoilers']; return !!prefs['reading:expand:spoilers'];
}, []); }, []);
const readingExpandMedia = useMemo(() => {
// default | show_all | hide_all
// Ignore hide_all because it means hide *ALL* media including non-sensitive ones
const prefs = store.account.get('preferences') || {};
return prefs['reading:expand:media'] || 'default';
}, []);
// FOR TESTING:
// const readingExpandSpoilers = true;
// const readingExpandMedia = 'show_all';
const showSpoiler = const showSpoiler =
previewMode || readingExpandSpoilers || !!snapStates.spoilers[id] || false; previewMode || readingExpandSpoilers || !!snapStates.spoilers[id];
const showSpoilerMedia =
previewMode ||
readingExpandMedia === 'show_all' ||
!!snapStates.spoilersMedia[id];
if (reblog) { if (reblog) {
// If has statusID, means useItemID (cached in states) // If has statusID, means useItemID (cached in states)
@ -1078,11 +1091,19 @@ function Status({
); );
if (activeStatus) { if (activeStatus) {
const spoilerButton = activeStatus.querySelector( const spoilerButton = activeStatus.querySelector(
'button.spoiler:not(.spoiling)', '.spoiler-button:not(.spoiling)',
); );
if (spoilerButton) { if (spoilerButton) {
e.stopPropagation(); e.stopPropagation();
spoilerButton.click(); spoilerButton.click();
} else {
const spoilerMediaButton = activeStatus.querySelector(
'.spoiler-media-button:not(.spoiling)',
);
if (spoilerMediaButton) {
e.stopPropagation();
spoilerMediaButton.click();
}
} }
} }
}); });
@ -1487,7 +1508,9 @@ function Status({
<div <div
class={`content-container ${ class={`content-container ${
spoilerText || sensitive ? 'has-spoiler' : '' spoilerText || sensitive ? 'has-spoiler' : ''
} ${showSpoiler ? 'show-spoiler' : ''}`} } ${showSpoiler ? 'show-spoiler' : ''} ${
showSpoilerMedia ? 'show-media' : ''
}`}
data-content-text-weight={contentTextWeight ? textWeight() : null} data-content-text-weight={contentTextWeight ? textWeight() : null}
style={ style={
(isSizeLarge || contentTextWeight) && { (isSizeLarge || contentTextWeight) && {
@ -1508,27 +1531,36 @@ function Status({
<EmojiText text={spoilerText} emojis={emojis} /> <EmojiText text={spoilerText} emojis={emojis} />
</p> </p>
</div> </div>
{readingExpandSpoilers || previewMode ? (
<div class="spoiler-divider">
<Icon icon="eye-open" /> Content warning
</div>
) : (
<button <button
class={`light spoiler ${showSpoiler ? 'spoiling' : ''}`} class={`light spoiler-button ${
showSpoiler ? 'spoiling' : ''
}`}
type="button" type="button"
disabled={readingExpandSpoilers}
onClick={(e) => { onClick={(e) => {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
if (showSpoiler) { if (showSpoiler) {
delete states.spoilers[id]; delete states.spoilers[id];
if (!readingExpandSpoilers) {
delete states.spoilersMedia[id];
}
} else { } else {
states.spoilers[id] = true; states.spoilers[id] = true;
if (!readingExpandSpoilers) {
states.spoilersMedia[id] = true;
}
} }
}} }}
> >
<Icon icon={showSpoiler ? 'eye-open' : 'eye-close'} />{' '} <Icon icon={showSpoiler ? 'eye-open' : 'eye-close'} />{' '}
{readingExpandSpoilers {showSpoiler ? 'Show less' : 'Show content'}
? 'Content warning'
: showSpoiler
? 'Show less'
: 'Show more'}
</button> </button>
)}
</> </>
)} )}
{!!content && ( {!!content && (
@ -1632,22 +1664,28 @@ function Status({
text={getPostText(status)} text={getPostText(status)}
/> />
)} )}
{!spoilerText && sensitive && !!mediaAttachments.length && ( {!previewMode &&
sensitive &&
!!mediaAttachments.length &&
readingExpandMedia !== 'show_all' && (
<button <button
class={`plain spoiler ${showSpoiler ? 'spoiling' : ''}`} class={`plain spoiler-media-button ${
showSpoilerMedia ? 'spoiling' : ''
}`}
type="button" type="button"
hidden={!readingExpandSpoilers && !!spoilerText}
onClick={(e) => { onClick={(e) => {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
if (showSpoiler) { if (showSpoilerMedia) {
delete states.spoilers[id]; delete states.spoilersMedia[id];
} else { } else {
states.spoilers[id] = true; states.spoilersMedia[id] = true;
} }
}} }}
> >
<Icon icon={showSpoiler ? 'eye-open' : 'eye-close'} /> Sensitive <Icon icon={showSpoilerMedia ? 'eye-open' : 'eye-close'} />{' '}
content {showSpoilerMedia ? 'Show less' : 'Show media'}
</button> </button>
)} )}
{!!mediaAttachments.length && ( {!!mediaAttachments.length && (

View file

@ -203,7 +203,7 @@ textarea {
max-width: 100%; max-width: 100%;
} }
button, button:not([hidden]),
.button { .button {
display: inline-block; display: inline-block;
padding: 8px 12px; padding: 8px 12px;

View file

@ -29,6 +29,7 @@ const states = proxy({
counter: 0, counter: 0,
}, },
spoilers: {}, spoilers: {},
spoilersMedia: {},
scrollPositions: {}, scrollPositions: {},
unfurledLinks: {}, unfurledLinks: {},
statusQuotes: {}, statusQuotes: {},