Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Special Error Page on Preact #1009

Merged
merged 53 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
1c4dd37
Start migration of SpecialErrorPage to preact
mgurgel Jul 29, 2024
9880fc8
New components, new data types
mgurgel Jul 31, 2024
22eb4b1
Migrated more Special Error components
mgurgel Aug 1, 2024
7fce929
Styling and more components
mgurgel Aug 1, 2024
c8f7f29
More tweaks
mgurgel Aug 2, 2024
36fdb75
Updated Schema
mgurgel Aug 5, 2024
769ec36
SSLErro and PhishingWarning components
mgurgel Aug 5, 2024
6182076
CSS vars
mgurgel Aug 5, 2024
0c984b0
Temporarily accept kind param on integration
mgurgel Aug 5, 2024
e9b3377
Added platform to initialSetup
mgurgel Aug 5, 2024
548164d
iOS layout
mgurgel Aug 6, 2024
6c7d9b6
Build inline
mgurgel Aug 6, 2024
9a09958
Component refactor
mgurgel Aug 7, 2024
1f05278
Tests
mgurgel Aug 8, 2024
53b88a4
More examples
mgurgel Aug 8, 2024
0162d0d
More tests
mgurgel Aug 8, 2024
969f489
Removed outdated sslerrorpage
mgurgel Aug 8, 2024
04778f5
Mild refactor
mgurgel Aug 9, 2024
59aa32a
CSS vars
mgurgel Aug 9, 2024
781083c
Background fixes
mgurgel Aug 9, 2024
c364c56
Button styling tweaks
mgurgel Aug 9, 2024
7950ec6
Locale string update
mgurgel Aug 9, 2024
95f9085
Fixes
mgurgel Aug 9, 2024
e6a8837
Styling tweaks
mgurgel Aug 9, 2024
897ab24
Special Error refactor
mgurgel Aug 12, 2024
c369a5c
Standard macOS dark button
mgurgel Aug 12, 2024
770004d
Strict spacing description
mgurgel Aug 12, 2024
7863eb8
Tests
mgurgel Aug 12, 2024
8bbca46
Dark mode fix
mgurgel Aug 12, 2024
25b03c0
Missing CSS vars
mgurgel Aug 14, 2024
6b366ea
don't inline
Aug 20, 2024
3aa61af
keep it inline
Aug 20, 2024
280253d
keep it as separate files again
Aug 20, 2024
4945600
add polish
Aug 21, 2024
f92162f
linting
Aug 21, 2024
e2ac185
add locale strings to message
Aug 21, 2024
fa8f4c7
bump
Aug 21, 2024
70edfb7
linting
Aug 21, 2024
7da13ae
trying a string
Aug 21, 2024
2025264
Added test for pl locale
Aug 22, 2024
b4adcb1
more langs
Aug 22, 2024
e2c4551
linting
Aug 22, 2024
56cbdef
Added remaining translations: bg + hr
mgurgel Aug 26, 2024
82bc38e
Advanced Info notification
mgurgel Aug 27, 2024
2127546
Advanced Info notification
mgurgel Aug 27, 2024
a23c021
Mitigating jumpiness when toggling Advanced Info on small screens
mgurgel Aug 28, 2024
12d2bba
Using onAnimationEnd
mgurgel Aug 28, 2024
5d0b90c
Event for advanced-info-animation-end
mgurgel Aug 28, 2024
19763ae
Local binding for spanRef
mgurgel Aug 28, 2024
54c1d20
Using AbortController
mgurgel Aug 28, 2024
d369df0
Review feedback
mgurgel Aug 29, 2024
f6c032f
No more Link component
mgurgel Aug 29, 2024
1f554f0
Cleaner animation-end handling. Author: @shakyShane
mgurgel Aug 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/special-pages/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ export const support = {
'apple': ['copy', 'inline-html'],
},
/** @type {Partial<Record<ImportMeta['injectName'], string[]>>} */
sslerrorpage: {
'integration': ['copy', 'build-js'],
'apple': ['copy', 'build-js', 'inline-html'],
},
/** @type {Partial<Record<ImportMeta['injectName'], string[]>>} */
onboarding: {
'integration': ['copy', 'build-js'],
'windows': ['copy', 'build-js'],
Expand All @@ -55,6 +50,11 @@ export const support = {
'integration': ['copy', 'build-js'],
'apple': ['copy', 'build-js'],
},
/** @type {Partial<Record<ImportMeta['injectName'], string[]>>} */
'special-error': {
'integration': ['copy', 'build-js'],
'apple': ['copy', 'build-js', 'inline-html'],
},
}

/** @type {{src: string, dest: string, injectName: string}[]} */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": ["locale", "env", "platform", "errorData"],
"properties": {
"locale": {
"type": "string"
},
"env": {
"type": "string",
"enum": ["development", "production"]
},
"platform": {
"type": "object",
"required": ["name"],
"properties": {
"name": {
"type": "string",
"enum": ["macos", "windows", "android", "ios"]
}
}
},
"errorData": {
"type": "object",
"oneOf": [
{
"type": "object",
"title": "Phishing",
"required": ["kind"],
"properties": {
"kind": {
"type": "string",
"const": "phishing"
}
}
}, {
"type": "object",
"title": "SSL Expired Certificate",
"required": ["kind", "errorType", "domain"],
"properties": {
"kind": {
"type": "string",
"const": "ssl"
},
"errorType": {
"type": "string",
"const": "expired"
},
"domain": {
"type": "string"
}
}
}, {
"type": "object",
"title": "SSL Invalid Certificate",
"required": ["kind", "errorType", "domain"],
"properties": {
"kind": {
"type": "string",
"const": "ssl"
},
"errorType": {
"type": "string",
"const": "invalid"
},
"domain": {
"type": "string"
}
}
}, {
"type": "object",
"title": "SSL Self Signed Certificate",
"required": ["kind", "errorType", "domain"],
"properties": {
"kind": {
"type": "string",
"const": "ssl"
},
"errorType": {
"type": "string",
"const": "selfSigned"
},
"domain": {
"type": "string"
}
}
}, {
"type": "object",
"title": "SSL Wrong Host",
"required": ["kind", "errorType", "domain", "eTldPlus1"],
"properties": {
"kind": {
"type": "string",
"const": "ssl"
},
"errorType": {
"type": "string",
"const": "wrongHost"
},
"domain": {
"type": "string"
},
"eTldPlus1": {
"type": "string"
}
}
}
]
},
"localeStrings": {
"type": "string",
"description": "Optional locale-specific strings"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"$schema": "http://json-schema.org/draft-07/schema#"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": ["message"],
"properties": {
"message": {
"type": "string"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": ["message"],
"properties": {
"message": {
"type": "string"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"$schema": "http://json-schema.org/draft-07/schema#"
}
4 changes: 3 additions & 1 deletion packages/special-pages/pages/example/app/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { callWithRetry } from '../../../shared/call-with-retry.js'
import { h, render } from 'preact'
import { EnvironmentProvider, UpdateEnvironment } from '../../../shared/components/EnvironmentProvider.js'

Expand All @@ -7,6 +6,9 @@ import { Components } from './components/Components.jsx'

import enStrings from '../src/locales/en/example.json'
import { TranslationProvider } from '../../../shared/components/TranslationsProvider.js'
import { callWithRetry } from '../../../shared/call-with-retry.js'

import '../../../shared/styles/global.css' // global styles

/**
* @param {import("../src/js/index.js").ExamplePage} messaging
Expand Down
21 changes: 19 additions & 2 deletions packages/special-pages/pages/example/src/js/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/**
* @module Example Page
* @category Special Pages
*
* @description
* Special Page example. Used as a template for new special pages.
*/

import { createTypedMessages } from '@duckduckgo/messaging'
import { Environment } from '../../../../shared/environment.js'
import { createSpecialPageMessaging } from '../../../../shared/create-special-page-messaging.js'
Expand All @@ -12,8 +20,17 @@ export class ExamplePage {
}

/**
* This will be sent if the application has loaded, but a client-side error
* has occurred that cannot be recovered from
* Sends an initial message to the native layer. This is the opportunity for the native layer
* to provide the initial state of the application or any configuration, for example:
*
* ```json
* {
* "env": "development",
* "locale": "en"
* }
* ```
*
* @returns {Promise<import('../../../../types/example').InitialSetupResponse>}
*/
initialSetup () {
return this.messaging.request('initialSetup')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function Components () {

<h2>Restart Button</h2>
<div>
<Button platform="apple">{t('restartToUpdate')}</Button>
<Button>{t('restartToUpdate')}</Button>
</div>
<hr/>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { h } from 'preact'
import { useRef, useEffect } from 'preact/hooks'
import { useTypedTranslation } from '../types'
import { Text } from '../../../../shared/components/Text/Text'
import { useMessaging } from '../providers/MessagingProvider'
import { useAdvancedInfoHeading, useAdvancedInfoContent } from '../hooks/ErrorStrings'

import styles from './AdvancedInfo.module.css'

function useScrollTarget() {
/** @type {import("preact/hooks").MutableRef<HTMLAnchorElement|null>} */
const linkRef = useRef(null)
return {
ref: linkRef,
trigger: () => {
linkRef.current?.scrollIntoView({ behavior: 'smooth' })
}
}
}

/**
* @param {object} props
* @param {import("preact/hooks").MutableRef<HTMLAnchorElement|null>} [props.elemRef]
*/
export function VisitSiteLink({ elemRef }) {
const { t } = useTypedTranslation();
const {messaging} = useMessaging();
return (
<a className={styles.visitSite} onClick={() => messaging?.visitSite()} ref={elemRef}>
{t('visitSiteButton')}
</a>
)
}

export function AdvancedInfoHeading() {
const heading = useAdvancedInfoHeading()

return (
<header className={styles.heading}>
<Text as="h2" variant="body">{heading}</Text>
</header>
)
}

export function AdvancedInfoContent() {
const content = useAdvancedInfoContent()

return (
<div className={styles.content}>
{content.map(text => <Text as="p" variant="body">{text}</Text>)}
</div>
)
}

export function AdvancedInfo() {
const { ref, trigger } = useScrollTarget();

return (
<div className={styles.wrapper}>
<div className={styles.container} onAnimationEnd={trigger}>
<AdvancedInfoHeading />

<AdvancedInfoContent />

<VisitSiteLink elemRef={ref}/>
</div>
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
.container {
align-items: flex-start;
display: flex;
flex-flow: column;
gap: var(--sp-4);
max-width: var(--ios-content-max-width);
width: 100%;

animation-duration: 300ms;
animation-fill-mode: forwards;
animation-name: appear;
}

.content {
display: flex;
flex-flow: column;
gap: var(--sp-5);

& a {
color: var(--link-color);
}
}

.visitSite {
color: var(--visit-site-color);
cursor: pointer;
font-size: calc(13 * var(--px-in-rem));
letter-spacing: calc(-0.08 * var(--px-in-rem));
line-height: calc(16 * var(--px-in-rem));
text-decoration: underline;
}

@keyframes appear {
0% {
padding: 0 var(--sp-10);
max-height: 0;
}
100% {
padding: var(--sp-6) var(--sp-10);
max-height: calc(400 * var(--px-in-rem));
}
}

/* Platform-specific styles */

/* macOS */
[data-platform-name="macos"] {
& .container {
background: var(--advanced-info-bg);
box-shadow: inset 0 1px 0 0 var(--border-color);
}

& .visitSite {
align-self: flex-end;
}
}

/* iOS */
[data-platform-name="ios"] {
& .wrapper {
display: flex;
justify-content: center;
border-top: 1px solid var(--color-black-at-9);
width: 100%;

@media (prefers-color-scheme: dark) {
border-top: 1px solid var(--color-white-at-9);
}
}

& .container {
align-items: center;
gap: var(--sp-6);
}

& .heading {
text-align: center;
}

& .content {
text-align: center;
}

& .visitSite {
font-size: calc(16 * var(--px-in-rem));
font-weight: 400;
letter-spacing: calc(-0.31 * var(--px-in-rem));
line-height: calc(21 * var(--px-in-rem));
}
}
Loading
Loading