Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
82 changes: 82 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion svelte-chat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@tsconfig/svelte": "^5.0.4",
"svelte": "^4.2.18",
"svelte-check": "^3.8.5",
"talon-auth": "^0.12.0",
"tslib": "^2.6.3",
"typescript": "^5.5.4",
"vite": "^5.3.5",
Expand All @@ -26,4 +27,4 @@
"@feathersjs/errors": "^5.0.29",
"vite-plugin-top-level-await": "^1.4.2"
}
}
}
27 changes: 20 additions & 7 deletions svelte-chat/src/App.svelte
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
<script lang="ts">
import 'talon-auth/login'
import type { TalonLoginComponent } from 'talon-auth'
import { createAutomerge, DocHandle } from '@feathersdev/automerge'
import type { Doc } from '@automerge/automerge-repo';
import type { ChatAppData, CloudAuthUser, Message, User } from './utils.js';
import { formatDate, sha256 } from './utils.js';
import { afterUpdate } from 'svelte';
import { loadAppDocument, type AppDocumentHandle } from './automerge.js';
import { auth } from './auth.js';
import { afterUpdate, onMount } from 'svelte';
import loading from './assets/loading.svg';
const appId = import.meta.env.VITE_CLOUD_APP_ID as string
/**
* The document handle type for the application
*/
type AppDocumentHandle = DocHandle<ChatAppData>
let ready = false;
let cloudAuthUser: CloudAuthUser | null = null;
let user: User | null = null;
Expand All @@ -15,6 +23,8 @@
let text: string = '';
let handle: AppDocumentHandle;
const getAuth = () => document.querySelector('talon-login') as TalonLoginComponent
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The getAuth() function may return null if the <talon-login> element is not yet rendered in the DOM. This can cause runtime errors when calling methods like getUser() or logoutAndForget(). Consider adding null checking or ensuring the component is mounted before accessing it.

Suggested change
const getAuth = () => document.querySelector('talon-login') as TalonLoginComponent
const getAuth = () => {
const el = document.querySelector('talon-login') as TalonLoginComponent | null;
if (!el) {
throw new Error('<talon-login> element not found in the DOM');
}
return el;
}

Copilot uses AI. Check for mistakes.
const getUserById = (id: string) => users.find((user) => user.id === id);
const init = async () => {
Expand All @@ -27,8 +37,10 @@
ready = true;
};
handle = await loadAppDocument();
cloudAuthUser = await auth.getUser();
const automerge = createAutomerge(getAuth())
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The automerge client is created inside the init() function but is not stored in a variable accessible outside this scope. If automerge needs to be referenced elsewhere in the component lifecycle, it should be declared at the component level similar to handle.

Copilot uses AI. Check for mistakes.
handle = await automerge.find<ChatAppData>();
cloudAuthUser = await getAuth().getUser();
// Update application data when document changes
handle.on('change', ({ doc }) => loadDocument(doc));
// Initialise the document if it is already available
Expand Down Expand Up @@ -90,7 +102,7 @@
};
const logout = async () => {
await auth.logoutAndForget();
await getAuth().logoutAndForget();
window.location.reload();
};
Expand All @@ -100,10 +112,11 @@
?.scrollIntoView({ behavior: 'smooth' });
});
init();
onMount(() => init())
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The init() function is async but its Promise is not being handled. Consider either awaiting it or handling potential errors: onMount(() => { init().catch(console.error) })

Suggested change
onMount(() => init())
onMount(() => { init().catch(console.error); })

Copilot uses AI. Check for mistakes.
</script>

<main>
<talon-login app-id="{appId}" />
{#if ready}
{#if user === null}
<div
Expand Down
39 changes: 0 additions & 39 deletions svelte-chat/src/auth.ts

This file was deleted.

21 changes: 0 additions & 21 deletions svelte-chat/src/automerge.ts

This file was deleted.