Skip to content

Commit

Permalink
add a debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
koddsson committed Nov 9, 2023
1 parent 8cda9f5 commit bbd3859
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
<link rel="manifest" href="/public/manifest.webmanifest">

<meta name="viewport" content="width=device-width, initial-scale=1" />

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@shoelace-style/[email protected]/cdn/themes/light.css" />
<script type="module" src="https://cdn.jsdelivr.net/npm/@shoelace-style/[email protected]/cdn/components/alert/alert.js"></script>

<script async type="module" src="./src/js/index.ts"></script>
<script defer type="module" src="./src/js/index.ts"></script>
<link rel="stylesheet" href="./dist/index.css" />
</head>
<body>
Expand Down
30 changes: 30 additions & 0 deletions src/js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,35 @@ async function ready(): Promise<void> {
})
}

// Custom function to emit toast notifications
//
// API Documentation: https://shoelace.style/components/alert/
function notify(message: string, {variant = 'warning', icon = 'exclamation-triangle', duration = 3000} = {}) {
const alert = Object.assign(document.createElement('sl-alert'), {
variant,
closable: true,
duration,
innerHTML: `
<sl-icon name="${icon}" slot="icon"></sl-icon>
${message}
`,
})

document.body.append(alert)
// @ts-ignore
return alert.toast()
}

if (new URL(window.location.toString(), window.location.origin).searchParams.get('debug') === 'true') {
window.addEventListener('unhandledrejection', event => {
notify(`[unhandledrejection]: ${event.reason}`)
})
window.addEventListener('error', event => {
notify(`[error]: ${event.type}: ${event.message}\n`, {duration: Infinity})
})
}

await ready()
fetchSubscriptions()

throw new Error('foobar')

0 comments on commit bbd3859

Please sign in to comment.