Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions frontend/src/components/NGLinks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import NGLinkDialog from '@/components/ui/Dialogs/NGLinkDialog';
import FgDialog from '@/components/ui/Dialogs/FgDialog';
import DeleteBtn from '@/components/ui/buttons/DeleteBtn';
import { useNGLinkContext } from '@/contexts/NGLinkContext';
import type { NGLink } from '@/queries/ngLinkQueries';
import type { CreateNGLinkPayload, NGLink } from '@/queries/ngLinkQueries';
import { copyToClipboard } from '@/utils/copyText';

export default function NGLinks() {
const {
Expand Down Expand Up @@ -37,14 +38,15 @@ export default function NGLinks() {
setEditItem(undefined);
};

const handleCreate = async (payload: {
url: string;
short_name?: string;
title?: string;
}) => {
const handleCreate = async (payload: CreateNGLinkPayload) => {
try {
await createNGLinkMutation.mutateAsync(payload);
toast.success('Link created');
const ngLink = await createNGLinkMutation.mutateAsync(payload);
const result = await copyToClipboard(ngLink.neuroglancer_url);
if (result.success) {
toast.success('Link created and copied to clipboard');
} else {
toast.error(`Failed to copy link: ${result.error}`);
}
handleClose();
} catch (error) {
const message =
Expand All @@ -59,8 +61,13 @@ export default function NGLinks() {
title?: string;
}) => {
try {
await updateNGLinkMutation.mutateAsync(payload);
toast.success('Link updated');
const ngLink = await updateNGLinkMutation.mutateAsync(payload);
const result = await copyToClipboard(ngLink.neuroglancer_url);
if (result.success) {
toast.success('Link updated and copied to clipboard');
} else {
toast.error(`Failed to copy link: ${result.error}`);
}
handleClose();
} catch (error) {
const message =
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/ui/Dialogs/NGLinkDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,8 @@ export default function NGLinkDialog({
? 'Saving...'
: 'Creating...'
: isEditMode
? 'Save'
: 'Create'}
? 'Save and copy link'
: 'Create and copy link'}
</Button>
<Button
className="!rounded-md"
Expand Down
24 changes: 17 additions & 7 deletions frontend/src/queries/ngLinkQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,26 @@ type NGLinkResponse = {
};

/**
* Payload for creating a Neuroglancer link
* Payload for creating a Neuroglancer link from a full URL
*/
export type CreateNGLinkPayload = {
url?: string;
state?: Record<string, unknown>;
url_base?: string;
short_name?: string;
title?: string;
type CreateNGLinkFromUrl = {
url: string;
short_name: string | undefined;
title: string | undefined;
};

/**
* Payload for creating a Neuroglancer link from state and base URL
*/
type CreateNGLinkFromState = {
state: Record<string, unknown>;
url_base: string;
short_name: string | undefined;
title: string | undefined;
};

export type CreateNGLinkPayload = CreateNGLinkFromUrl | CreateNGLinkFromState;

/**
* Payload for updating a Neuroglancer link
*/
Expand Down