Skip to content

Commit 8804210

Browse files
committed
✨ feat: add test button
1 parent 8253273 commit 8804210

File tree

7 files changed

+73
-12
lines changed

7 files changed

+73
-12
lines changed

dev.docker-compose.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ services:
5757
volumes:
5858
- ./mock-oidc-landingpage.html:/static/mock-oidc-landingpage.html
5959

60-
ntfy:
61-
image: binwiederhier/ntfy
62-
command:
63-
- serve
64-
volumes:
65-
- ./ntfy:/etc/ntfy
66-
ports:
67-
- 80:80
68-
restart: unless-stopped
60+
# ntfy:
61+
# image: binwiederhier/ntfy
62+
# command:
63+
# - serve
64+
# volumes:
65+
# - ./ntfy:/etc/ntfy
66+
# ports:
67+
# - 80:80
68+
# restart: unless-stopped
6969

7070
volumes:
7171
project-dev:

messages/de.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,9 @@
2121
"subscribeToTheTopic": "3. Subscribe to the topic",
2222
"subscribeToTheTopicExplaination": "Finally, you have to subcribe to the topic. You can do this on all devices you want to receive notifications on. For instructions on how to do that, see the link below.",
2323
"instructions": "Instructions",
24-
"differentServerExplaination": "When asked if you would like to configure a different server, do that and fill the below value."
24+
"differentServerExplaination": "When asked if you would like to configure a different server, do that and fill the below value.",
25+
"sendTest": "4. Send a test notification (optional)",
26+
"sendTestExplaination": "Send a test notification to all your devices to make sure everything is working as expected.",
27+
"send": "Send",
28+
"sent": "Sent!"
2529
}

messages/en.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,9 @@
2121
"subscribeToTheTopic": "3. Subscribe to the topic",
2222
"subscribeToTheTopicExplaination": "Finally, you have to subcribe to the topic. You can do this on all devices you want to receive notifications on. For instructions on how to do that, see the link below.",
2323
"instructions": "Instructions",
24-
"differentServerExplaination": "When asked if you would like to configure a different server, do that and fill the below value"
24+
"differentServerExplaination": "When asked if you would like to configure a different server, do that and fill the below value",
25+
"sendTest": "4. Send a test notification (optional)",
26+
"sendTestExplaination": "Send a test notification to all your devices to make sure everything is working as expected.",
27+
"send": "Send",
28+
"sent": "Sent!"
2529
}

schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ scalar JSON
9090
type Mutation {
9191
removeTopic: User
9292
resetTopic: User
93+
sendTest: String
9394
}
9495

9596
type Query {

src/api/handlers/user.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import { abilityBuilder, schemaBuilder } from '$api/rumble';
33
import { configPrivate } from '$config/private';
44
import { configPublic } from '$config/public';
55
import { nanoid } from '$lib/helpers/nanoid';
6+
import { assertFindFirstExists } from '@m1212e/rumble';
67
import { basics } from './basics';
8+
import { GraphQLError } from 'graphql';
9+
import { sendMessage } from '$api/services/sendMessage';
710

811
const { arg, ref, pubsub, table } = basics('user');
912

@@ -88,6 +91,32 @@ schemaBuilder.mutationFields((t) => {
8891
)
8992
);
9093
}
94+
}),
95+
sendTest: t.field({
96+
type: 'String',
97+
resolve: async (root, args, ctx, info) => {
98+
const user = ctx.mustBeLoggedIn();
99+
100+
const dbUser = await db.query.user
101+
.findFirst({
102+
where: {
103+
id: user.sub
104+
}
105+
})
106+
.then(assertFindFirstExists);
107+
108+
if (!dbUser.ntfyTopic) {
109+
throw new GraphQLError('You need to set a topic first!');
110+
}
111+
112+
await sendMessage({
113+
body: 'Test',
114+
title: 'Test',
115+
targetEmail: dbUser!.email
116+
});
117+
118+
return 'OK';
119+
}
91120
})
92121
};
93122
});

src/api/services/sendMessage.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,6 @@ export async function sendMessage({
4040
topic: foundUser.ntfyTopic,
4141
title
4242
});
43+
44+
console.info('Sent notification to', foundUser.email, foundUser.ntfyTopic.slice(0, 5) + '...');
4345
}

src/routes/app/+page.svelte

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { m } from '$lib/paraglide/messages';
44
import toast from 'svelte-french-toast';
55
import type { PageData } from './$houdini';
6-
import { LogOut, Plus, Copy, Undo2, Trash2, SquareArrowOutUpRight } from 'lucide-svelte';
6+
import { LogOut, Plus, Copy, Undo2, Trash2, SquareArrowOutUpRight, Send } from 'lucide-svelte';
77
import { Modal } from '@skeletonlabs/skeleton-svelte';
88
import { configPublic } from '$config/public';
99
@@ -30,6 +30,12 @@
3030
}
3131
}
3232
`);
33+
34+
const SendTestMutation = graphql(`
35+
mutation SendTestMutation {
36+
sendTest
37+
}
38+
`);
3339
</script>
3440

3541
<main class="flex max-w-4xl flex-col justify-between p-2">
@@ -114,6 +120,21 @@
114120
>
115121
</div>
116122
{/if}
123+
{#if topic}
124+
<h1 class="mt-8 text-3xl font-bold">{m.sendTest()}</h1>
125+
<p>{m.sendTestExplaination()}</p>
126+
<button
127+
type="button"
128+
class="btn preset-filled-primary-500 mt-4"
129+
onclick={async () => {
130+
await SendTestMutation.mutate(null);
131+
toast.success(m.sent());
132+
}}
133+
>
134+
<Send />
135+
{m.send()}</button
136+
>
137+
{/if}
117138
</div>
118139

119140
<div>

0 commit comments

Comments
 (0)