- Share on the Outline page opens a sheet: create / copy / turn off a read-only link, share the link with the system share sheet, or send the outline as text - The link has its own token (separate from the whole-study share link) and the public endpoint returns only the outlines, rebuilt field by field: no observations, interpretations, applications, scripts or word notes - Opening the link shows the outline(s) with no sign-in, a switcher between the whole-study and per-chunk outlines, and Print / PDF - New outline_share_token column (added automatically on start) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
45 lines
1.8 KiB
JavaScript
45 lines
1.8 KiB
JavaScript
// The read-only link to a study's outlines: status, create, turn off, copy. A separate link from the
|
||
// whole-study share link, and it only ever shows outlines.
|
||
import { useEffect, useState } from 'react';
|
||
import { disableOutlineSharing, enableOutlineSharing, getOutlineShareStatus } from '../syncService.js';
|
||
|
||
export function useOutlineShareLink(projectId, enabled = true) {
|
||
const [token, setToken] = useState(null);
|
||
const [state, setState] = useState('loading'); // 'loading' | 'ready' | 'unavailable' (no account / server)
|
||
const [busy, setBusy] = useState(false);
|
||
const [error, setError] = useState('');
|
||
|
||
useEffect(() => {
|
||
setToken(null);
|
||
setError('');
|
||
if (!projectId || !enabled) return undefined;
|
||
let active = true;
|
||
setState('loading');
|
||
getOutlineShareStatus(projectId).then((result) => {
|
||
if (!active) return;
|
||
if (result.ok) { setToken(result.data.shareToken); setState('ready'); } else setState('unavailable');
|
||
});
|
||
return () => { active = false; };
|
||
}, [projectId, enabled]);
|
||
|
||
const url = token ? `${window.location.origin}${window.location.pathname}?outline=${token}` : '';
|
||
|
||
const create = async () => {
|
||
setBusy(true);
|
||
setError('');
|
||
const result = await enableOutlineSharing(projectId);
|
||
setBusy(false);
|
||
if (result.ok) setToken(result.data.shareToken);
|
||
else setError(result.status === 404 ? 'Your study hasn’t synced to your account yet. Wait a moment and try again.' : 'Couldn’t create the link. Check your connection and try again.');
|
||
};
|
||
|
||
const turnOff = async () => {
|
||
setBusy(true);
|
||
const result = await disableOutlineSharing(projectId);
|
||
setBusy(false);
|
||
if (result.ok) setToken(null); else setError('Couldn’t turn the link off. Try again.');
|
||
};
|
||
|
||
return { token, url, state, busy, error, create, turnOff };
|
||
}
|