Revert 173 revert 155 fix/useconfirm n tableofcont (#177)
* test * test * test * test * errorWhileRendering now generates 500 status code * build fix * debug cleanup
This commit is contained in:
parent
63c52ac6e4
commit
f2a5751f3e
|
@ -5,7 +5,14 @@ export default async function handler(req, res) {
|
||||||
|
|
||||||
const pageContext = await renderPage({ urlOriginal: url, cookies })
|
const pageContext = await renderPage({ urlOriginal: url, cookies })
|
||||||
|
|
||||||
const { httpResponse } = pageContext
|
const { httpResponse, errorWhileRendering } = pageContext
|
||||||
|
|
||||||
|
if (errorWhileRendering) {
|
||||||
|
console.error(errorWhileRendering)
|
||||||
|
res.statusCode = 500
|
||||||
|
res.end()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (!httpResponse) {
|
if (!httpResponse) {
|
||||||
res.statusCode = 200
|
res.statusCode = 200
|
||||||
|
|
|
@ -232,7 +232,7 @@ export const FullArticle = (props: Props) => {
|
||||||
</Show>
|
</Show>
|
||||||
</article>
|
</article>
|
||||||
<Show when={isDesktop() && body()}>
|
<Show when={isDesktop() && body()}>
|
||||||
<TableOfContents variant="article" parentSelector="#shoutBody" />
|
<TableOfContents variant="article" parentSelector="#shoutBody" body={body()} />
|
||||||
</Show>
|
</Show>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -248,7 +248,7 @@ export const Editor = (props: Props) => {
|
||||||
<>
|
<>
|
||||||
<div ref={(el) => (editorElRef.current = el)} id="editorBody" />
|
<div ref={(el) => (editorElRef.current = el)} id="editorBody" />
|
||||||
<Show when={isDesktop() && html()}>
|
<Show when={isDesktop() && html()}>
|
||||||
<TableOfContents variant="editor" parentSelector="#editorBody" />
|
<TableOfContents variant="editor" parentSelector="#editorBody" body={html()} />
|
||||||
</Show>
|
</Show>
|
||||||
<TextBubbleMenu
|
<TextBubbleMenu
|
||||||
isCommonMarkup={isCommonMarkup()}
|
isCommonMarkup={isCommonMarkup()}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { DEFAULT_HEADER_OFFSET } from '../../stores/router'
|
||||||
|
|
||||||
import { useLocalize } from '../../context/localize'
|
import { useLocalize } from '../../context/localize'
|
||||||
|
|
||||||
import { debounce } from 'debounce'
|
import debounce from 'debounce'
|
||||||
|
|
||||||
import { Icon } from '../_shared/Icon'
|
import { Icon } from '../_shared/Icon'
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ import styles from './TableOfContents.module.scss'
|
||||||
interface Props {
|
interface Props {
|
||||||
variant: 'article' | 'editor'
|
variant: 'article' | 'editor'
|
||||||
parentSelector: string
|
parentSelector: string
|
||||||
|
body: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const scrollToHeader = (element) => {
|
const scrollToHeader = (element) => {
|
||||||
|
@ -32,21 +33,34 @@ export const TableOfContents = (props: Props) => {
|
||||||
const [headings, setHeadings] = createSignal<Element[]>([])
|
const [headings, setHeadings] = createSignal<Element[]>([])
|
||||||
const [areHeadingsLoaded, setAreHeadingsLoaded] = createSignal<boolean>(false)
|
const [areHeadingsLoaded, setAreHeadingsLoaded] = createSignal<boolean>(false)
|
||||||
|
|
||||||
const [isVisible, setIsVisible] = createSignal<boolean>(true)
|
const [isVisible, setIsVisible] = createSignal<boolean>(props.variant === 'article')
|
||||||
const toggleIsVisible = () => {
|
const toggleIsVisible = () => {
|
||||||
setIsVisible((visible) => !visible)
|
setIsVisible((visible) => !visible)
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(() => {
|
const updateHeadings = () => {
|
||||||
const { parentSelector } = props
|
const { parentSelector } = props
|
||||||
|
|
||||||
// eslint-disable-next-line unicorn/prefer-spread
|
// eslint-disable-next-line unicorn/prefer-spread
|
||||||
setHeadings(Array.from(document.querySelector(parentSelector).querySelectorAll('h2, h3, h4')))
|
setHeadings(Array.from(document.querySelector(parentSelector).querySelectorAll('h2, h3, h4')))
|
||||||
|
|
||||||
setAreHeadingsLoaded(true)
|
setAreHeadingsLoaded(true)
|
||||||
})
|
}
|
||||||
|
|
||||||
|
const debouncedUpdateHeadings = debounce(updateHeadings, 500)
|
||||||
|
|
||||||
|
createEffect(
|
||||||
|
on(
|
||||||
|
() => props.body,
|
||||||
|
() => debouncedUpdateHeadings()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Show when={areHeadingsLoaded()}>
|
<Show
|
||||||
|
when={
|
||||||
|
areHeadingsLoaded() && (props.variant === 'article' ? headings().length > 2 : headings().length > 1)
|
||||||
|
}
|
||||||
|
>
|
||||||
<div
|
<div
|
||||||
class={clsx(styles.TableOfContentsFixedWrapper, {
|
class={clsx(styles.TableOfContentsFixedWrapper, {
|
||||||
[styles.TableOfContentsFixedWrapperLefted]: props.variant === 'editor'
|
[styles.TableOfContentsFixedWrapperLefted]: props.variant === 'editor'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user