Skip to content

Commit 417fb11

Browse files
committed
Merge new user settings screen and old web push settings screen
1 parent 0408fee commit 417fb11

File tree

9 files changed

+46
-30
lines changed

9 files changed

+46
-30
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Now try logging in - click the "login with your GitHub user" link. You'll go thr
6262
6363
## Using Push Notifications
6464

65-
On each Cicada screen you'll see a "Manage Web Push Notifications" link - choosing this will allow you to subscribe for notifications.
65+
On each Cicada screen you'll see a "User Settings" link - choosing this will allow you to subscribe for notifications.
6666

6767
**IMPORTANT FOR IPHONE USERS** :
6868
On an iPhone you need to "install" Cicada as a Progressive Web App (PWA) first - you do this by adding it to your home screen via the "share" button in Safari.

src/app/web/viewResultWrappers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function pageViewResultWithoutHtmx(bodyContents: HiccoughContent[], logge
2222
element('hr'),
2323
...(loggedIn
2424
? [
25-
p(a('web-push.html', 'Manage Web Push Notifications')),
25+
p(a('/userSettings', 'User Settings')),
2626
p(a('/', 'Back to home')),
2727
p(a('/github/auth/logout', 'Logout'))
2828
]

src/web/app/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ <h3 class="mt-4">Recent Branch Activity</h3>
2525
hx-swap='outerHTML'>Loading Recent Activity...
2626
</div>
2727
<hr />
28-
<p><a href='../web-push.html'>Manage Web Push Notifications</a></p>
28+
<p><a href="/userSettings">User Settings</a></p>
2929
<p><a href='/github/auth/logout'>Logout</a></p>
3030
</div>
3131
</body>

src/web/js/web-push.js

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ async function subscribeToPush() {
1313
return
1414
}
1515

16+
updateStatus('Attempting to subscribe for notifications')
1617
const registration = await navigator.serviceWorker.getRegistration(serviceWorkerScript)
1718
const subscription = await registration.pushManager.subscribe({
1819
userVisibleOnly: true,
@@ -21,15 +22,18 @@ async function subscribeToPush() {
2122
console.log(JSON.stringify(subscription))
2223
await postToServer('webPushSubscribe', subscription)
2324
await updateUI()
25+
updateStatus('Subscribed for push notifications ✅')
2426
}
2527

2628
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2729
async function unsubscribeFromPush() {
30+
updateStatus('Attempting to unsubscribe from push notifications')
2831
const registration = await navigator.serviceWorker.getRegistration(serviceWorkerScript)
2932
const subscription = await registration.pushManager.getSubscription()
3033
await postToServer('webPushUnsubscribe', { endpoint: subscription.endpoint })
3134
await subscription.unsubscribe()
3235
await updateUI()
36+
updateStatus('Unsubscribed from push notifications')
3337
}
3438

3539
async function testPing() {
@@ -38,15 +42,13 @@ async function testPing() {
3842
}
3943

4044
async function updateUI() {
41-
updateFurtherStatus('')
4245
if (!('serviceWorker' in navigator)) {
4346
updateStatus('Web Push not supported by this browser - no service worker')
4447
return
4548
}
4649
if (!('PushManager' in window)) {
47-
updateStatus('Web Push not supported by this browser')
48-
updateFurtherStatus(
49-
'If using an iOS device then use Cicada as a PWA by adding a shortcut to your home screen, and open from there.'
50+
updateStatus(
51+
'Web Push not supported by this browser. If using an iOS device then use Cicada as a PWA by adding a shortcut to your home screen, and open from there.'
5052
)
5153
return
5254
}
@@ -66,33 +68,30 @@ async function updateUI() {
6668
const pushSubscription = await serviceWorkerRegistration.pushManager.getSubscription()
6769
if (pushSubscription) {
6870
console.log(`Push Subscription Endpoint = ${pushSubscription.endpoint}`)
69-
updateStatus('Subscribed for push notifications ✅')
70-
updateSubscriptionButton('Unsubscribe', unsubscribeFromPush)
71+
updateSubscribeToggle(true, unsubscribeFromPush)
7172
} else {
72-
updateStatus('You need to subscribe for push notifications')
73-
updateSubscriptionButton('Subscribe', subscribeToPush)
73+
updateSubscribeToggle(false, subscribeToPush)
7474
}
7575

7676
document.getElementById('pingButton').onclick = testPing
77+
updateStatus('')
7778
}
7879

7980
function updateStatus(s) {
8081
const status = document.getElementById('status')
8182
status.textContent = s
8283
}
8384

84-
function updateFurtherStatus(s) {
85-
const status = document.getElementById('furtherStatus')
86-
status.textContent = s
87-
}
88-
89-
function updateSubscriptionButton(s, onclick) {
90-
const button = document.getElementById('updateSubscription')
91-
const enabled = s && s.length > 0
92-
button.disabled = !enabled
93-
button.setAttribute('class', enabled ? 'btn btn-primary btn-lg' : 'invisible')
94-
button.textContent = s
95-
button.onclick = onclick
85+
function updateSubscribeToggle(checked, onclick) {
86+
const toggle = document.getElementById('subscribeToggle')
87+
toggle.removeAttribute('disabled')
88+
toggle.disabled = false
89+
toggle.onclick = onclick
90+
if (checked) {
91+
toggle.setAttribute('checked', checked)
92+
} else {
93+
toggle.removeAttribute('checked')
94+
}
9695
}
9796

9897
async function getOrRegisterServiceWorker() {

src/web/repo/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ <h4 class="mt-4">Recent Activity</h4>
3939
</div>
4040
<hr />
4141
<p>
42-
<a href="/web-push.html">Manage Web Push Notifications</a>
42+
<a href="/userSettings">User Settings</a>
4343
</p>
4444
<p>
4545
<a href="/">Back to home</a>

src/web/userSettings/index.html

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,34 @@
55
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
66
<meta name='viewport' content='width=device-width, initial-scale=1'>
77
<title>Cicada User Settings</title>
8+
<script src='/js/web-push.js' type="module"></script>
89
<script src='/js/htmx.min.js' crossorigin='anonymous'></script>
9-
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
10+
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
11+
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
1012
<link rel='stylesheet' href='https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.min.css'>
1113
</head>
1214

1315
<body>
1416
<script src="/js/checkLoggedIn.js"></script>
1517
<div class='container' id='toplevel'>
1618
<h1 class="display-3 mt-4">User Settings</h1>
19+
<h2>Web Push Settings</h2>
20+
<div class="form-check form-switch">
21+
<input id="subscribeToggle" class="form-check-input" type="checkbox" role="switch" disabled>
22+
<label class="form-check-label" for="subscribeToggle">Subscribe for web push notifications on this
23+
device</label>
24+
</div>
25+
<p id='status' class='lead'>Finding Web Push Status...</p>
26+
<hr />
27+
<h2>Visibility and Notifications</h2>
1728
<script src="/js/checkForHtmxUnauthorizedResponse.js"></script>
1829
<div id="topUserSettings"
1930
hx-get='/app/fragment/userSettings'
2031
hx-trigger='load'
2132
hx-swap='innerHTML'>Finding user settings...
2233
</div>
23-
<div>
34+
<hr/>
35+
<h2>Advanced</h2>
2436
<button type="button"
2537
class="btn btn-danger"
2638
hx-post="/app/fragment/resetUserSettings"
@@ -30,7 +42,12 @@ <h1 class="display-3 mt-4">User Settings</h1>
3042
>
3143
Reset User Settings
3244
</button>
33-
</div>
45+
<button type="button"
46+
id="pingButton"
47+
class="btn btn-primary"
48+
>
49+
Test push notifications</button>
50+
<button type="button" class="btn btn-secondary" id='updateServiceWorker' disabled>Update Service Worker</button>
3451
<hr />
3552
<p>
3653
<a href="/">Back to home</a>

src/web/workflow/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ <h1 class="display-3 mt-4">Cicada</h1>
3636
</div>
3737
<hr />
3838
<p>
39-
<a href="/web-push.html">Manage Web Push Notifications</a>
39+
<a href="/userSettings">User Settings</a>
4040
</p>
4141
<p>
4242
<a href="/">Back to home</a>

test/local/functional/domain/github/githubUserAuth/githubWebAuthHandler.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ test('failedOauthCallback', async () => {
114114
<p>Unable to login because there was no code on request</p>
115115
<hr></hr>
116116
<p>
117-
<a href="web-push.html">Manage Web Push Notifications</a>
117+
<a href="/userSettings">User Settings</a>
118118
</p>
119119
<p>
120120
<a href="/">Back to home</a>

test/remote/authorizedContent.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ testuser
5353
</p>
5454
<hr></hr>
5555
<p>
56-
<a href="web-push.html">Manage Web Push Notifications</a>
56+
<a href="/userSettings">User Settings</a>
5757
</p>
5858
<p>
5959
<a href="/">Back to home</a>

0 commit comments

Comments
 (0)