This commit is contained in:
He4eT 2021-02-26 21:09:00 +05:00
commit 3cc2818f40
3 changed files with 21 additions and 13 deletions

View file

@ -7,6 +7,11 @@ module.exports = {
'standard', 'standard',
'standard-preact' 'standard-preact'
], ],
overrides: [
{
files: ['*.jsx', '*.js']
}
],
parserOptions: { parserOptions: {
ecmaVersion: 12, ecmaVersion: 12,
sourceType: 'module' sourceType: 'module'
@ -15,7 +20,7 @@ module.exports = {
}, },
settings: { settings: {
react: { react: {
version: 'latest', version: 'latest'
}, }
} }
} }

View file

@ -3,24 +3,27 @@ import { useState, useEffect } from 'preact/hooks'
const parseInbox = (inbox, currentWindow) => { const parseInbox = (inbox, currentWindow) => {
const currentInbox = const currentInbox =
inbox.find(({id}) => inbox.find(({ id }) =>
id === currentWindow.id) id === currentWindow.id)
if (!currentInbox) return { if (!currentInbox) {
clear: false, return {
incoming: []} clear: false,
incoming: []
}
}
const {clear, text: inboxMessagesRaw} = const { clear, text: inboxMessagesRaw } =
currentInbox currentInbox
const incoming = const incoming =
inboxMessagesRaw inboxMessagesRaw
/* Normalize. */ /* Normalize. */
.map(({content}) => .map(({ content }) =>
content || [{ style: 'emptyLine' }]) content || [{ style: 'emptyLine' }])
/* Flatten. */ /* Flatten. */
.reduce((acc, x) => .reduce((acc, x) =>
acc.concat(x), []) acc.concat(x), [])
/* Collapse empty lines. */ /* Collapse empty lines. */
.reduce((acc, x, i, xs) => { .reduce((acc, x, i, xs) => {
if (x.style !== 'emptyLine') return [...acc, x] if (x.style !== 'emptyLine') return [...acc, x]
@ -31,14 +34,14 @@ const parseInbox = (inbox, currentWindow) => {
: [...acc, x] : [...acc, x]
}, []) }, [])
return {clear, incoming} return { clear, incoming }
} }
export default function ({ inbox, currentWindow }) { export default function ({ inbox, currentWindow }) {
const [messages, setMessages] = useState([]) const [messages, setMessages] = useState([])
useEffect(() => { useEffect(() => {
const {incoming, clear} = const { incoming, clear } =
parseInbox(inbox, currentWindow) parseInbox(inbox, currentWindow)
setMessages(clear setMessages(clear
@ -48,7 +51,7 @@ export default function ({ inbox, currentWindow }) {
return ( return (
<div> <div>
{messages?.map(({text}) => {messages.map(({ text }) =>
(<div>{text}</div>))} (<div>{text}</div>))}
</div> </div>
) )

View file

@ -5,7 +5,7 @@ import UrlPlayer from '~/src/components/player/UrlPlayer'
const decode = encodedUrl => decodeURIComponent(encodedUrl) const decode = encodedUrl => decodeURIComponent(encodedUrl)
export default function ({setTheme, theme, encodedUrl}) { export default function ({ setTheme, theme, encodedUrl }) {
useEffect(() => setTheme(theme), [theme]) useEffect(() => setTheme(theme), [theme])
const [targetUrl, setTargetUrl] = useState(decode(encodedUrl)) const [targetUrl, setTargetUrl] = useState(decode(encodedUrl))