-
Notifications
You must be signed in to change notification settings - Fork 7
feat: Move Svelte chat to Talon Auth web component #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| 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; | ||||||
|
|
@@ -15,6 +23,8 @@ | |||||
| let text: string = ''; | ||||||
| let handle: AppDocumentHandle; | ||||||
| const getAuth = () => document.querySelector('talon-login') as TalonLoginComponent | ||||||
| const getUserById = (id: string) => users.find((user) => user.id === id); | ||||||
| const init = async () => { | ||||||
|
|
@@ -27,8 +37,10 @@ | |||||
| ready = true; | ||||||
| }; | ||||||
| handle = await loadAppDocument(); | ||||||
| cloudAuthUser = await auth.getUser(); | ||||||
| const automerge = createAutomerge(getAuth()) | ||||||
|
||||||
| 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 | ||||||
|
|
@@ -90,7 +102,7 @@ | |||||
| }; | ||||||
| const logout = async () => { | ||||||
| await auth.logoutAndForget(); | ||||||
| await getAuth().logoutAndForget(); | ||||||
| window.location.reload(); | ||||||
| }; | ||||||
|
|
@@ -100,10 +112,11 @@ | |||||
| ?.scrollIntoView({ behavior: 'smooth' }); | ||||||
| }); | ||||||
| init(); | ||||||
| onMount(() => init()) | ||||||
|
||||||
| onMount(() => init()) | |
| onMount(() => { init().catch(console.error); }) |
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
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 likegetUser()orlogoutAndForget(). Consider adding null checking or ensuring the component is mounted before accessing it.