diff --git a/inertia/components/dashboard/dashboard_header.tsx b/inertia/components/dashboard/dashboard_header.tsx index 70d9971..7a63a31 100644 --- a/inertia/components/dashboard/dashboard_header.tsx +++ b/inertia/components/dashboard/dashboard_header.tsx @@ -16,6 +16,7 @@ import { BsThreeDotsVertical } from 'react-icons/bs'; import { GoPencil } from 'react-icons/go'; import { IoIosAddCircleOutline } from 'react-icons/io'; import { IoTrashOutline } from 'react-icons/io5'; +import { ShareCollection } from '~/components/share/share_collection'; import { appendCollectionId } from '~/lib/navigation'; import { useActiveCollection } from '~/stores/collection_store'; @@ -57,6 +58,8 @@ export function DashboardHeader({ navbar, aside }: DashboardHeaderProps) { + + @@ -99,6 +102,7 @@ export function DashboardHeader({ navbar, aside }: DashboardHeaderProps) { + ; + + const sharedUrl = generateShareUrl(activeCollection); + return ( + + + + + + + + {t('click-to-copy')} + + {({ copied, copy }) => + !copied ? ( + {sharedUrl} + ) : ( + {t('success-copy')} + ) + } + + + + ); +} diff --git a/inertia/i18n/locales/en/common.json b/inertia/i18n/locales/en/common.json index fa4fe6c..a60840d 100644 --- a/inertia/i18n/locales/en/common.json +++ b/inertia/i18n/locales/en/common.json @@ -80,5 +80,7 @@ "made_by": "Made with ❤\uFE0F by" }, "loading": "Loading...", - "no-results": "No results found" + "no-results": "No results found", + "click-to-copy": "Click on the following link to copy the shareable url", + "success-copy": "Link copied to clipboard" } \ No newline at end of file diff --git a/inertia/i18n/locales/fr/common.json b/inertia/i18n/locales/fr/common.json index c676f8e..afdd88b 100644 --- a/inertia/i18n/locales/fr/common.json +++ b/inertia/i18n/locales/fr/common.json @@ -80,5 +80,7 @@ "made_by": "Fait avec ❤\uFE0F par" }, "loading": "Chargement...", - "no-results": "Aucun résultat trouvé" + "no-results": "Aucun résultat trouvé", + "click-to-copy": "Cliquez sur le lien suivant pour copier l'URL partageable", + "success-copy": "Link copié dans le presse-papiers" } \ No newline at end of file diff --git a/inertia/lib/navigation.ts b/inertia/lib/navigation.ts index 05ffdd3..e8d881e 100644 --- a/inertia/lib/navigation.ts +++ b/inertia/lib/navigation.ts @@ -1,4 +1,4 @@ -import { Collection, Link } from '~/types/app'; +import { Collection, CollectionWithLinks, Link } from '~/types/app'; export const appendCollectionId = ( url: string, @@ -26,3 +26,11 @@ export function isValidHttpUrl(urlParam: string) { return url.protocol === 'http:' || url.protocol === 'https:'; } + +export const generateShareUrl = ( + collection: Collection | CollectionWithLinks +) => { + const pathname = `/shared/${collection.id}`; + if (typeof window === 'undefined') return pathname; + return `${window.location.origin}${pathname}`; +};