Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Adrien Denat
commited on
Fix share not working on iOS (#150)
Browse files- src/lib/shareConversation.ts +2 -9
- src/lib/utils/share.ts +7 -0
- src/routes/r/[id]/+page.svelte +2 -9
src/lib/shareConversation.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import { base } from "$app/paths";
|
| 2 |
import { ERROR_MESSAGES, error } from "$lib/stores/errors";
|
|
|
|
| 3 |
|
| 4 |
export async function shareConversation(id: string, title: string) {
|
| 5 |
try {
|
|
@@ -18,15 +19,7 @@ export async function shareConversation(id: string, title: string) {
|
|
| 18 |
|
| 19 |
const { url } = await res.json();
|
| 20 |
|
| 21 |
-
|
| 22 |
-
navigator.share({
|
| 23 |
-
title,
|
| 24 |
-
text: "Share this chat with others",
|
| 25 |
-
url,
|
| 26 |
-
});
|
| 27 |
-
} else {
|
| 28 |
-
prompt("Copy this public url to share:", url);
|
| 29 |
-
}
|
| 30 |
} catch (err) {
|
| 31 |
error.set(ERROR_MESSAGES.default);
|
| 32 |
console.error(err);
|
|
|
|
| 1 |
import { base } from "$app/paths";
|
| 2 |
import { ERROR_MESSAGES, error } from "$lib/stores/errors";
|
| 3 |
+
import { share } from "./utils/share";
|
| 4 |
|
| 5 |
export async function shareConversation(id: string, title: string) {
|
| 6 |
try {
|
|
|
|
| 19 |
|
| 20 |
const { url } = await res.json();
|
| 21 |
|
| 22 |
+
share(url, title);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
} catch (err) {
|
| 24 |
error.set(ERROR_MESSAGES.default);
|
| 25 |
console.error(err);
|
src/lib/utils/share.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export function share(url: string, title: string) {
|
| 2 |
+
if (navigator.share) {
|
| 3 |
+
navigator.share({ url, title });
|
| 4 |
+
} else {
|
| 5 |
+
prompt("Copy this public url to share:", url);
|
| 6 |
+
}
|
| 7 |
+
}
|
src/routes/r/[id]/+page.svelte
CHANGED
|
@@ -6,6 +6,7 @@
|
|
| 6 |
import { ERROR_MESSAGES, error } from "$lib/stores/errors";
|
| 7 |
import { pendingMessage } from "$lib/stores/pendingMessage";
|
| 8 |
import { pendingMessageIdToRetry } from "$lib/stores/pendingMessageIdToRetry";
|
|
|
|
| 9 |
import type { PageData } from "./$types";
|
| 10 |
|
| 11 |
export let data: PageData;
|
|
@@ -44,15 +45,7 @@
|
|
| 44 |
async function shareConversation() {
|
| 45 |
const url = `${window.location.origin}${window.location.pathname}`;
|
| 46 |
|
| 47 |
-
|
| 48 |
-
navigator.share({
|
| 49 |
-
title: data.title,
|
| 50 |
-
text: "Share this chat with others",
|
| 51 |
-
url,
|
| 52 |
-
});
|
| 53 |
-
} else {
|
| 54 |
-
prompt("Share this link with your friends:", url);
|
| 55 |
-
}
|
| 56 |
}
|
| 57 |
</script>
|
| 58 |
|
|
|
|
| 6 |
import { ERROR_MESSAGES, error } from "$lib/stores/errors";
|
| 7 |
import { pendingMessage } from "$lib/stores/pendingMessage";
|
| 8 |
import { pendingMessageIdToRetry } from "$lib/stores/pendingMessageIdToRetry";
|
| 9 |
+
import { share } from "$lib/utils/share";
|
| 10 |
import type { PageData } from "./$types";
|
| 11 |
|
| 12 |
export let data: PageData;
|
|
|
|
| 45 |
async function shareConversation() {
|
| 46 |
const url = `${window.location.origin}${window.location.pathname}`;
|
| 47 |
|
| 48 |
+
share(url, data.title);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
}
|
| 50 |
</script>
|
| 51 |
|