From 16f689a598e61071d863ef4e9436c3abf71d54e8 Mon Sep 17 00:00:00 2001
From: "Thomas G. Lopes" <26071571+TGlide@users.noreply.github.com>
Date: Thu, 19 Jun 2025 01:07:27 +0100
Subject: [PATCH] better share modal
---
src/lib/backend/convex/conversations.ts | 15 ++
src/lib/backend/convex/messages.ts | 22 +++
src/lib/components/ui/share-button/index.ts | 1 +
.../ui/share-button/share-button.svelte | 145 ++++++++++++++++++
src/lib/components/ui/switch/switch.svelte | 2 +-
src/routes/account/models/+page.svelte | 28 +++-
src/routes/chat/+layout.svelte | 81 +---------
src/routes/share/[id]/+page.server.ts | 32 ++++
src/routes/share/[id]/+page.svelte | 118 ++++++++++++++
9 files changed, 360 insertions(+), 84 deletions(-)
create mode 100644 src/lib/components/ui/share-button/index.ts
create mode 100644 src/lib/components/ui/share-button/share-button.svelte
create mode 100644 src/routes/share/[id]/+page.server.ts
create mode 100644 src/routes/share/[id]/+page.svelte
diff --git a/src/lib/backend/convex/conversations.ts b/src/lib/backend/convex/conversations.ts
index 946760b..243e7a2 100644
--- a/src/lib/backend/convex/conversations.ts
+++ b/src/lib/backend/convex/conversations.ts
@@ -304,6 +304,21 @@ export const remove = mutation({
},
});
+export const getPublicById = query({
+ args: {
+ conversation_id: v.id('conversations'),
+ },
+ handler: async (ctx, args) => {
+ const conversation = await ctx.db.get(args.conversation_id);
+
+ if (!conversation || !conversation.public) {
+ return null;
+ }
+
+ return conversation;
+ },
+});
+
export const search = query({
args: {
session_token: v.string(),
diff --git a/src/lib/backend/convex/messages.ts b/src/lib/backend/convex/messages.ts
index fc3a0b8..edb01f5 100644
--- a/src/lib/backend/convex/messages.ts
+++ b/src/lib/backend/convex/messages.ts
@@ -169,6 +169,28 @@ export const updateMessage = mutation({
},
});
+export const getByConversationPublic = query({
+ args: {
+ conversation_id: v.id('conversations'),
+ },
+ handler: async (ctx, args) => {
+ // First check if the conversation is public
+ const conversation = await ctx.db.get(args.conversation_id);
+
+ if (!conversation || !conversation.public) {
+ return null;
+ }
+
+ const messages = await ctx.db
+ .query('messages')
+ .withIndex('by_conversation', (q) => q.eq('conversation_id', args.conversation_id))
+ .order('asc')
+ .collect();
+
+ return messages;
+ },
+});
+
export const updateError = mutation({
args: {
session_token: v.string(),
diff --git a/src/lib/components/ui/share-button/index.ts b/src/lib/components/ui/share-button/index.ts
new file mode 100644
index 0000000..ee003e6
--- /dev/null
+++ b/src/lib/components/ui/share-button/index.ts
@@ -0,0 +1 @@
+export { default as ShareButton } from './share-button.svelte';
\ No newline at end of file
diff --git a/src/lib/components/ui/share-button/share-button.svelte b/src/lib/components/ui/share-button/share-button.svelte
new file mode 100644
index 0000000..aae5ced
--- /dev/null
+++ b/src/lib/components/ui/share-button/share-button.svelte
@@ -0,0 +1,145 @@
+
+
+
Public sharing
+Anyone with the link can view this conversation
++ Enable public sharing to generate a shareable link +
+ {/if} +