Skip to content

Commit

Permalink
Remove unused syntax
Browse files Browse the repository at this point in the history
Refs #1817, #1834; reverts f256f32
  • Loading branch information
thewilkybarkid committed Aug 5, 2024
1 parent 0d1ebb4 commit 6dbe3a4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 52 deletions.
60 changes: 24 additions & 36 deletions src/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ export interface PageResponse {
readonly canonical?: string
readonly current?: Page['current']
readonly status: Status
readonly title: Page['title'] | ((lang: SupportedLocale) => Page['title'])
readonly description?: Page['description'] | ((lang: SupportedLocale) => Page['description'])
readonly nav?: Html | ((lang: SupportedLocale) => Html)
readonly main: Html | ((lang: SupportedLocale) => Html)
readonly title: Page['title']
readonly description?: Page['description']
readonly nav?: Html
readonly main: Html
readonly skipToLabel: 'form' | 'main' | 'prereview'
readonly extraSkipLink?: [Html, string] | ((lang: SupportedLocale) => [Html, string])
readonly extraSkipLink?: [Html, string]
readonly js: Required<Page>['js']
}

Expand All @@ -49,10 +49,10 @@ export interface StreamlinePageResponse {
readonly canonical?: string
readonly current?: Page['current']
readonly status: Status
readonly title: Page['title'] | ((lang: SupportedLocale) => Page['title'])
readonly description?: Page['description'] | ((lang: SupportedLocale) => Page['description'])
readonly nav?: Html | ((lang: SupportedLocale) => Html)
readonly main: Html | ((lang: SupportedLocale) => Html)
readonly title: Page['title']
readonly description?: Page['description']
readonly nav?: Html
readonly main: Html
readonly skipToLabel: 'form' | 'main'
readonly js: Required<Page>['js']
readonly allowRobots?: false
Expand All @@ -61,11 +61,11 @@ export interface StreamlinePageResponse {
export interface TwoUpPageResponse {
readonly _tag: 'TwoUpPageResponse'
readonly canonical: string
readonly title: Page['title'] | ((lang: SupportedLocale) => Page['title'])
readonly description?: Page['description'] | ((lang: SupportedLocale) => Page['description'])
readonly h1: Html | ((lang: SupportedLocale) => Html)
readonly aside: Html | ((lang: SupportedLocale) => Html)
readonly main: Html | ((lang: SupportedLocale) => Html)
readonly title: Page['title']
readonly description?: Page['description']
readonly h1: Html
readonly aside: Html
readonly main: Html
}

export interface RedirectResponse {
Expand Down Expand Up @@ -199,25 +199,18 @@ export const handlePageResponse = ({
templatePage({
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
locale: locale !== DefaultLocale ? locale : undefined,
title: typeof response.title === 'function' ? response.title(locale) : response.title,
description: typeof response.description === 'function' ? response.description(locale) : response.description,
title: response.title,
description: response.description,
content: html`
${response.nav
? html` <nav>${typeof response.nav === 'function' ? response.nav(locale) : response.nav}</nav>`
: ''}
${response.nav ? html` <nav>${response.nav}</nav>` : ''}
<main id="${response.skipToLabel}">
${message ? showFlashMessage(message, locale) : ''}
${typeof response.main === 'function' ? response.main(locale) : response.main}
${message ? showFlashMessage(message, locale) : ''} ${response.main}
</main>
`,
skipLinks: [
[rawHtml(translate(locale, 'skip-links', response.skipToLabel)()), `#${response.skipToLabel}`],
...(response._tag === 'PageResponse' && response.extraSkipLink
? typeof response.extraSkipLink === 'function'
? [response.extraSkipLink(locale)]
: [response.extraSkipLink]
: []),
...(response._tag === 'PageResponse' && response.extraSkipLink ? [response.extraSkipLink] : []),
],
current: response.current,
js: response.js.concat(...(message ? (['notification-banner.js'] as const) : [])),
Expand Down Expand Up @@ -288,19 +281,14 @@ const handleTwoUpPageResponse = ({
templatePage({
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
locale: locale !== DefaultLocale ? locale : undefined,
title: typeof response.title === 'function' ? response.title(locale) : response.title,
description: typeof response.description === 'function' ? response.description(locale) : response.description,
title: response.title,
description: response.description,
content: html`
<h1 class="visually-hidden">${typeof response.h1 === 'function' ? response.h1(locale) : response.h1}</h1>
<h1 class="visually-hidden">${response.h1}</h1>
<aside id="preprint-details" tabindex="0" aria-label="Preprint details">
${typeof response.aside === 'function' ? response.aside(locale) : response.aside}
</aside>
<aside id="preprint-details" tabindex="0" aria-label="Preprint details">${response.aside}</aside>
<main id="prereviews">
${message ? showFlashMessage(message, locale) : ''}
${typeof response.main === 'function' ? response.main(locale) : response.main}
</main>
<main id="prereviews">${message ? showFlashMessage(message, locale) : ''} ${response.main}</main>
`,
skipLinks: [
[html`Skip to preprint details`, '#preprint-details'],
Expand Down
23 changes: 7 additions & 16 deletions visual-regression/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { type Locator, test as baseTest } from '@playwright/test'
import path from 'path'
import { P, match } from 'ts-pattern'
import { type Html, html } from '../src/html.js'
import { DefaultLocale } from '../src/locales/index.js'
import { type Page, page as templatePage } from '../src/page.js'
import type { PageResponse, StreamlinePageResponse, TwoUpPageResponse } from '../src/response.js'

Expand Down Expand Up @@ -46,19 +45,15 @@ export const test = baseTest.extend<ShowPage>({
showPage: async ({ page, showHtml, templatePage }, use) => {
await use(async function showPage(response, extra = {}) {
const content = html`
${response.nav
? html` <nav>${typeof response.nav === 'function' ? response.nav(DefaultLocale) : response.nav}</nav>`
: ''}
${response.nav ? html` <nav>${response.nav}</nav>` : ''}
<main id="${response.skipToLabel}">
${typeof response.main === 'function' ? response.main(DefaultLocale) : response.main}
</main>
<main id="${response.skipToLabel}">${response.main}</main>
`

const pageHtml = templatePage({
...extra,
content,
title: typeof response.title === 'function' ? response.title(DefaultLocale) : response.title,
title: response.title,
js: response.js,
})

Expand All @@ -70,20 +65,16 @@ export const test = baseTest.extend<ShowPage>({
showTwoUpPage: async ({ page, showHtml, templatePage }, use) => {
await use(async response => {
const content = html`
<h1 class="visually-hidden">${typeof response.h1 === 'function' ? response.h1(DefaultLocale) : response.h1}</h1>
<h1 class="visually-hidden">${response.h1}</h1>
<aside id="preprint-details" tabindex="0" aria-label="Preprint details">
${typeof response.aside === 'function' ? response.aside(DefaultLocale) : response.aside}
</aside>
<aside id="preprint-details" tabindex="0" aria-label="Preprint details">${response.aside}</aside>
<main id="prereviews">
${typeof response.main === 'function' ? response.main(DefaultLocale) : response.main}
</main>
<main id="prereviews">${response.main}</main>
`

const pageHtml = templatePage({
content,
title: typeof response.title === 'function' ? response.title(DefaultLocale) : response.title,
title: response.title,
type: 'two-up',
})

Expand Down

0 comments on commit 6dbe3a4

Please sign in to comment.