summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2024-10-17 02:19:23 -0400
committerOwen Jacobson <owen@grimoire.ca>2024-10-17 02:19:23 -0400
commitbde5aea211e9838b4511a2b57c6a256fe89b66ab (patch)
tree729caf0811cea28d639c893034586e79dfc71392
parentea74daca4809e4008dd8d01039db9fff3be659d9 (diff)
Get loaded data using `export let data`, instead of fishing around in $page.
This is mostly a how-to-Svelte thing. I've also made the API responses for invites a bit more caller-friendly by flattening them and adding the ID field into them. The ID is redundant (the client knows it because the client has the invitation URL), but it makes presenting invitations and actioning them a bit easier.
-rw-r--r--.sqlx/query-d9c772a28d1b5b2ca3b0a2c19a4eed48252247f15a046098d63359c6d9047c9a.json38
-rw-r--r--.sqlx/query-df22d29fc47244ee696b3eaab9d1be6f740ec4a7fc713056befc4ac700259951.json32
-rw-r--r--docs/api/invitations.md12
-rw-r--r--src/invite/mod.rs8
-rw-r--r--src/invite/repo.rs7
-rw-r--r--ui/routes/(login)/invite/[invite]/+page.js3
-rw-r--r--ui/routes/(login)/invite/[invite]/+page.svelte14
7 files changed, 57 insertions, 57 deletions
diff --git a/.sqlx/query-d9c772a28d1b5b2ca3b0a2c19a4eed48252247f15a046098d63359c6d9047c9a.json b/.sqlx/query-d9c772a28d1b5b2ca3b0a2c19a4eed48252247f15a046098d63359c6d9047c9a.json
new file mode 100644
index 0000000..39e9231
--- /dev/null
+++ b/.sqlx/query-d9c772a28d1b5b2ca3b0a2c19a4eed48252247f15a046098d63359c6d9047c9a.json
@@ -0,0 +1,38 @@
+{
+ "db_name": "SQLite",
+ "query": "\n\t\t\t\tselect\n invite.id as \"invite_id: Id\",\n\t\t\t\t\tissuer.id as \"issuer_id: login::Id\",\n\t\t\t\t\tissuer.name as \"issuer_name\",\n\t\t\t\t\tinvite.issued_at as \"invite_issued_at: DateTime\"\n\t\t\t\tfrom invite\n\t\t\t\tjoin login as issuer on (invite.issuer = issuer.id)\n\t\t\t\twhere invite.id = $1\n\t\t\t",
+ "describe": {
+ "columns": [
+ {
+ "name": "invite_id: Id",
+ "ordinal": 0,
+ "type_info": "Text"
+ },
+ {
+ "name": "issuer_id: login::Id",
+ "ordinal": 1,
+ "type_info": "Text"
+ },
+ {
+ "name": "issuer_name",
+ "ordinal": 2,
+ "type_info": "Text"
+ },
+ {
+ "name": "invite_issued_at: DateTime",
+ "ordinal": 3,
+ "type_info": "Text"
+ }
+ ],
+ "parameters": {
+ "Right": 1
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false
+ ]
+ },
+ "hash": "d9c772a28d1b5b2ca3b0a2c19a4eed48252247f15a046098d63359c6d9047c9a"
+}
diff --git a/.sqlx/query-df22d29fc47244ee696b3eaab9d1be6f740ec4a7fc713056befc4ac700259951.json b/.sqlx/query-df22d29fc47244ee696b3eaab9d1be6f740ec4a7fc713056befc4ac700259951.json
deleted file mode 100644
index 5a34da8..0000000
--- a/.sqlx/query-df22d29fc47244ee696b3eaab9d1be6f740ec4a7fc713056befc4ac700259951.json
+++ /dev/null
@@ -1,32 +0,0 @@
-{
- "db_name": "SQLite",
- "query": "\n\t\t\t\tselect\n\t\t\t\t\tissuer.id as \"issuer_id: login::Id\",\n\t\t\t\t\tissuer.name as \"issuer_name\",\n\t\t\t\t\tinvite.issued_at as \"invite_issued_at: DateTime\"\n\t\t\t\tfrom invite\n\t\t\t\tjoin login as issuer on (invite.issuer = issuer.id)\n\t\t\t\twhere invite.id = $1\n\t\t\t",
- "describe": {
- "columns": [
- {
- "name": "issuer_id: login::Id",
- "ordinal": 0,
- "type_info": "Text"
- },
- {
- "name": "issuer_name",
- "ordinal": 1,
- "type_info": "Text"
- },
- {
- "name": "invite_issued_at: DateTime",
- "ordinal": 2,
- "type_info": "Text"
- }
- ],
- "parameters": {
- "Right": 1
- },
- "nullable": [
- false,
- false,
- false
- ]
- },
- "hash": "df22d29fc47244ee696b3eaab9d1be6f740ec4a7fc713056befc4ac700259951"
-}
diff --git a/docs/api/invitations.md b/docs/api/invitations.md
index 0f21a0e..f75e30b 100644
--- a/docs/api/invitations.md
+++ b/docs/api/invitations.md
@@ -91,17 +91,11 @@ The response will include the following fields:
| Field | Type | Description |
|:------------|:-------|:--|
-| `issuer` | object | The details of the login that issued the invitation. |
+| `id` | string | The ID of the invitation. |
+| `issuer` | string | The login name of the invitation's issuer. |
| `issued_at` | string | The timestamp from which the invitation will expire. |
-The `issuer` object will include the following fields:
-
-| Field | Type | Description |
-|:-------|:-------|:--|
-| `id` | string | The login ID of the invitation's issuer. |
-| `name` | string | The login name of the invitation's issuer. |
-
-Clients should present the issuer's name to the user when presenting an invitation, so as to personalize the invitation and help them understand their connection with the service.
+Clients should present the `issuer` to the user when presenting an invitation, so as to personalize the invitation and help them understand their connection with the service.
### Invitation not found
diff --git a/src/invite/mod.rs b/src/invite/mod.rs
index 5f9d490..abf1c3a 100644
--- a/src/invite/mod.rs
+++ b/src/invite/mod.rs
@@ -3,10 +3,7 @@ mod id;
mod repo;
mod routes;
-use crate::{
- clock::DateTime,
- login::{self, Login},
-};
+use crate::{clock::DateTime, login};
pub use self::{id::Id, routes::router};
@@ -19,6 +16,7 @@ pub struct Invite {
#[derive(serde::Serialize)]
pub struct Summary {
- pub issuer: Login,
+ pub id: Id,
+ pub issuer: String,
pub issued_at: DateTime,
}
diff --git a/src/invite/repo.rs b/src/invite/repo.rs
index 2ab993f..643f5b7 100644
--- a/src/invite/repo.rs
+++ b/src/invite/repo.rs
@@ -68,6 +68,7 @@ impl<'c> Invites<'c> {
let invite = sqlx::query!(
r#"
select
+ invite.id as "invite_id: Id",
issuer.id as "issuer_id: login::Id",
issuer.name as "issuer_name",
invite.issued_at as "invite_issued_at: DateTime"
@@ -78,10 +79,8 @@ impl<'c> Invites<'c> {
invite,
)
.map(|row| Summary {
- issuer: Login {
- id: row.issuer_id,
- name: row.issuer_name,
- },
+ id: row.invite_id,
+ issuer: row.issuer_name,
issued_at: row.invite_issued_at,
})
.fetch_one(&mut *self.0)
diff --git a/ui/routes/(login)/invite/[invite]/+page.js b/ui/routes/(login)/invite/[invite]/+page.js
index d90f542..e6664d2 100644
--- a/ui/routes/(login)/invite/[invite]/+page.js
+++ b/ui/routes/(login)/invite/[invite]/+page.js
@@ -5,7 +5,8 @@ export async function load({ params }) {
let response = await getInvite(invite);
switch (response.status) {
case 200:
- return response.data;
+ let invite = response.data
+ return { invite };
break;
case 404:
return null;
diff --git a/ui/routes/(login)/invite/[invite]/+page.svelte b/ui/routes/(login)/invite/[invite]/+page.svelte
index eea05fc..b9a4a97 100644
--- a/ui/routes/(login)/invite/[invite]/+page.svelte
+++ b/ui/routes/(login)/invite/[invite]/+page.svelte
@@ -1,20 +1,18 @@
<script>
import { goto } from '$app/navigation';
- import { page } from '$app/stores';
import { acceptInvite } from '$lib/apiServer';
- $: inviteId = $page?.params?.invite;
- $: invite = $page.data;
-
import LogIn from '$lib/components/LogIn.svelte';
+ export let data;
+
let disabled;
let username;
let password;
async function onSubmit() {
disabled = true;
- const response = await acceptInvite(inviteId, username, password);
+ const response = await acceptInvite(data.invite.id, username, password);
if (200 <= response.status && response.status < 300) {
username = '';
password = '';
@@ -24,5 +22,9 @@
}
</script>
-<p>Hi there! {invite.issuer.name} invites you to the conversation.</p>
+{#await data}
+<p>Loading invitation…</p>
+{:then { invite }}
+<p>Hi there! {invite.issuer} invites you to the conversation.</p>
<LogIn bind:disabled bind:username bind:password on:submit={onSubmit} />
+{/await}