more wiring up of messages
This commit is contained in:
		@@ -1,5 +1,6 @@
 | 
				
			|||||||
<script lang="ts">
 | 
					<script lang="ts">
 | 
				
			||||||
	import { onMount, tick } from 'svelte';
 | 
						import { onMount, tick } from 'svelte';
 | 
				
			||||||
 | 
						import { createMessage } from '$lib/services/messages';
 | 
				
			||||||
	import {
 | 
						import {
 | 
				
			||||||
		LitAuthClient,
 | 
							LitAuthClient,
 | 
				
			||||||
		BaseProvider,
 | 
							BaseProvider,
 | 
				
			||||||
@@ -12,7 +13,7 @@
 | 
				
			|||||||
	import { ProviderType } from '@lit-protocol/constants';
 | 
						import { ProviderType } from '@lit-protocol/constants';
 | 
				
			||||||
	import { LitAccessControlConditionResource, LitAbility } from '@lit-protocol/auth-helpers';
 | 
						import { LitAccessControlConditionResource, LitAbility } from '@lit-protocol/auth-helpers';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const redirectUri = 'http://localhost:5173/';
 | 
						const redirectUri = 'http://localhost:5173/log';
 | 
				
			||||||
	let view = 'sign_in';
 | 
						let view = 'sign_in';
 | 
				
			||||||
	let error;
 | 
						let error;
 | 
				
			||||||
	let litAuthClient;
 | 
						let litAuthClient;
 | 
				
			||||||
@@ -34,15 +35,14 @@
 | 
				
			|||||||
	async function authWithGoogle() {
 | 
						async function authWithGoogle() {
 | 
				
			||||||
		isLoading = true;
 | 
							isLoading = true;
 | 
				
			||||||
		error = null;
 | 
							error = null;
 | 
				
			||||||
		// Add chat message updates
 | 
							addMessage('Starting authentication with Google...'); // Replace console.log
 | 
				
			||||||
		addMessage('Starting authentication with Google...');
 | 
					 | 
				
			||||||
		try {
 | 
							try {
 | 
				
			||||||
			const provider = litAuthClient.initProvider<GoogleProvider>(ProviderType.Google);
 | 
								const provider = litAuthClient.initProvider<GoogleProvider>(ProviderType.Google);
 | 
				
			||||||
			await provider.signIn();
 | 
								await provider.signIn();
 | 
				
			||||||
			addMessage('Handling Google authentication...');
 | 
								addMessage('Handling Google authentication...'); // Replace console.log
 | 
				
			||||||
			await handleRedirect(ProviderType.Google);
 | 
								await handleRedirect(ProviderType.Google);
 | 
				
			||||||
		} catch (err) {
 | 
							} catch (err) {
 | 
				
			||||||
			console.error(err);
 | 
								createMessage('Error: ' + err.message); // Use createMessage
 | 
				
			||||||
			error = err;
 | 
								error = err;
 | 
				
			||||||
			view = 'ERROR';
 | 
								view = 'ERROR';
 | 
				
			||||||
		} finally {
 | 
							} finally {
 | 
				
			||||||
@@ -166,6 +166,7 @@
 | 
				
			|||||||
	onMount(async () => {
 | 
						onMount(async () => {
 | 
				
			||||||
		isLoading = true;
 | 
							isLoading = true;
 | 
				
			||||||
		console.log('Component mounted.');
 | 
							console.log('Component mounted.');
 | 
				
			||||||
 | 
							addMessage('MOUNTED.');
 | 
				
			||||||
		try {
 | 
							try {
 | 
				
			||||||
			litNodeClient = new LitNodeClient({
 | 
								litNodeClient = new LitNodeClient({
 | 
				
			||||||
				litNetwork: 'serrano',
 | 
									litNetwork: 'serrano',
 | 
				
			||||||
@@ -248,9 +249,3 @@
 | 
				
			|||||||
		</div>
 | 
							</div>
 | 
				
			||||||
	{/if}
 | 
						{/if}
 | 
				
			||||||
</main>
 | 
					</main>
 | 
				
			||||||
 | 
					 | 
				
			||||||
{#each messages as message, index}
 | 
					 | 
				
			||||||
	<div class="chat-message">
 | 
					 | 
				
			||||||
		<p>{message}</p>
 | 
					 | 
				
			||||||
	</div>
 | 
					 | 
				
			||||||
{/each}
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										34
									
								
								src/lib/components/MessageInput.svelte
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								src/lib/components/MessageInput.svelte
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,34 @@
 | 
				
			|||||||
 | 
					<script>
 | 
				
			||||||
 | 
						import { createMessage, clearMessages } from '$lib/services/messages';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						let newMessageText = '';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						function handleSend() {
 | 
				
			||||||
 | 
							if (newMessageText.trim() !== '') {
 | 
				
			||||||
 | 
								createMessage(newMessageText);
 | 
				
			||||||
 | 
								newMessageText = '';
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						function handleClear() {
 | 
				
			||||||
 | 
							clearMessages(); // Call the clearMessages function to clear all messages.
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<footer class="fixed bottom-0 left-0 right-0 bg-white p-4 flex justify-end">
 | 
				
			||||||
 | 
						<input
 | 
				
			||||||
 | 
							type="text"
 | 
				
			||||||
 | 
							class="flex-grow border rounded px-3 py-2 mr-2"
 | 
				
			||||||
 | 
							placeholder="Type your message..."
 | 
				
			||||||
 | 
							bind:value={newMessageText}
 | 
				
			||||||
 | 
						/>
 | 
				
			||||||
 | 
						<button class="bg-blue-500 hover:bg-blue-600 text-white py-2 px-4 rounded" on:click={handleSend}>
 | 
				
			||||||
 | 
							Send Message
 | 
				
			||||||
 | 
						</button>
 | 
				
			||||||
 | 
						<button
 | 
				
			||||||
 | 
							class="bg-red-500 hover:bg-red-600 text-white py-2 px-4 rounded ml-2"
 | 
				
			||||||
 | 
							on:click={handleClear}
 | 
				
			||||||
 | 
						>
 | 
				
			||||||
 | 
							Clear
 | 
				
			||||||
 | 
						</button>
 | 
				
			||||||
 | 
					</footer>
 | 
				
			||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
<script>
 | 
					<script>
 | 
				
			||||||
	import { messages, clearMessages, addRandomMessage } from '$lib/services/messages';
 | 
						import { messages } from '$lib/services/messages';
 | 
				
			||||||
</script>
 | 
					</script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<main class="p-4 flex flex-col-reverse overflow-y-auto h-[calc(100vh-70px)]">
 | 
					<main class="p-4 flex flex-col-reverse overflow-y-auto h-[calc(100vh-70px)]">
 | 
				
			||||||
@@ -13,18 +13,3 @@
 | 
				
			|||||||
		{/each}
 | 
							{/each}
 | 
				
			||||||
	</div>
 | 
						</div>
 | 
				
			||||||
</main>
 | 
					</main>
 | 
				
			||||||
 | 
					 | 
				
			||||||
<footer class="fixed bottom-0 left-0 right-0 bg-white p-4 flex justify-end">
 | 
					 | 
				
			||||||
	<button
 | 
					 | 
				
			||||||
		class="bg-red-500 hover:bg-red-600 text-white py-2 px-4 rounded mr-2"
 | 
					 | 
				
			||||||
		on:click={clearMessages}
 | 
					 | 
				
			||||||
	>
 | 
					 | 
				
			||||||
		Clear
 | 
					 | 
				
			||||||
	</button>
 | 
					 | 
				
			||||||
	<button
 | 
					 | 
				
			||||||
		class="bg-blue-500 hover:bg-blue-600 text-white py-2 px-4 rounded"
 | 
					 | 
				
			||||||
		on:click={addRandomMessage}
 | 
					 | 
				
			||||||
	>
 | 
					 | 
				
			||||||
		Send Random Message
 | 
					 | 
				
			||||||
	</button>
 | 
					 | 
				
			||||||
</footer>
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										8
									
								
								src/lib/components/interfaces/Message.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								src/lib/components/interfaces/Message.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
				
			|||||||
 | 
					interface Message {
 | 
				
			||||||
 | 
					    message: string;
 | 
				
			||||||
 | 
					    date: Date;
 | 
				
			||||||
 | 
					    sender: string;
 | 
				
			||||||
 | 
					    type: string;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default Message;
 | 
				
			||||||
@@ -55,6 +55,14 @@ export function addRandomMessage() {
 | 
				
			|||||||
    ]);
 | 
					    ]);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function createMessage(text) {
 | 
				
			||||||
 | 
					    const currentDate = new Date().toLocaleString();
 | 
				
			||||||
 | 
					    messages.update(oldMessages => [
 | 
				
			||||||
 | 
					        ...oldMessages,
 | 
				
			||||||
 | 
					        { text: text, timestamp: currentDate }
 | 
				
			||||||
 | 
					    ]);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function clearMessages() {
 | 
					export function clearMessages() {
 | 
				
			||||||
    messages.set([]);
 | 
					    messages.set([]);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,14 +6,16 @@
 | 
				
			|||||||
	import Balance from '$lib/Balance.svelte';
 | 
						import Balance from '$lib/Balance.svelte';
 | 
				
			||||||
	import WalletConnect from '$lib/WalletConnect.svelte';
 | 
						import WalletConnect from '$lib/WalletConnect.svelte';
 | 
				
			||||||
	import GoogleAuth from '$lib/GoogleAuth.svelte';
 | 
						import GoogleAuth from '$lib/GoogleAuth.svelte';
 | 
				
			||||||
 | 
						import Messages from '$lib/components/Messages.svelte';
 | 
				
			||||||
 | 
						import MessageInput from '$lib/components/MessageInput.svelte';
 | 
				
			||||||
	let pkpWallet;
 | 
						let pkpWallet;
 | 
				
			||||||
	let authSig;
 | 
						let authSig;
 | 
				
			||||||
	let pkpPubKey =
 | 
						let pkpPubKey =
 | 
				
			||||||
		'046da3ba67065fd1e2726242ca01cd4601524893f4aa4b0042578fa6cbec28fa8c9a28eb9f7893932fc09717edc9e1db57e157a21eed346247c1db5a722a01f571';
 | 
							'046da3ba67065fd1e2726242ca01cd4601524893f4aa4b0042578fa6cbec28fa8c9a28eb9f7893932fc09717edc9e1db57e157a21eed346247c1db5a722a01f571';
 | 
				
			||||||
</script>
 | 
					</script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<LitStatus />
 | 
					<!-- <LitStatus />
 | 
				
			||||||
<AuthSign />
 | 
					<AuthSign /> -->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<!-- <div class="p-4 bg-gray-200 flex justify-center items-center flex-col">
 | 
					<!-- <div class="p-4 bg-gray-200 flex justify-center items-center flex-col">
 | 
				
			||||||
	<Wallet bind:pkpWallet bind:authSig />
 | 
						<Wallet bind:pkpWallet bind:authSig />
 | 
				
			||||||
@@ -23,3 +25,5 @@
 | 
				
			|||||||
	<WalletConnect bind:pkpWallet bind:authSig bind:pkpPubKey />
 | 
						<WalletConnect bind:pkpWallet bind:authSig bind:pkpPubKey />
 | 
				
			||||||
</div> -->
 | 
					</div> -->
 | 
				
			||||||
<GoogleAuth />
 | 
					<GoogleAuth />
 | 
				
			||||||
 | 
					<Messages />
 | 
				
			||||||
 | 
					<MessageInput />
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +0,0 @@
 | 
				
			|||||||
<script>
 | 
					 | 
				
			||||||
	import Messages from '$lib/components/Messages.svelte';
 | 
					 | 
				
			||||||
</script>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
<Messages />
 | 
					 | 
				
			||||||
		Reference in New Issue
	
	Block a user