()
| 448 | } |
| 449 | |
| 450 | function HostedOptions() { |
| 451 | const id = useDocDetails("id"); |
| 452 | if (typeof id !== "number") throw new Error("id is not a number"); |
| 453 | |
| 454 | const isPublic = useDocDetails("isPublic"); |
| 455 | const publicId = useDocDetails("publicId"); |
| 456 | |
| 457 | const makePublic = useMutation( |
| 458 | "makeChartPublic", |
| 459 | async (isPublic: boolean) => makeChartPublic(id, isPublic), |
| 460 | { |
| 461 | onSuccess: (result) => { |
| 462 | if (!result) return; |
| 463 | useDoc.setState( |
| 464 | (state) => { |
| 465 | return produce(state, (draft) => { |
| 466 | draft.details.isPublic = result.isPublic; |
| 467 | if (result.publicId) draft.details.publicId = result.publicId; |
| 468 | }); |
| 469 | }, |
| 470 | false, |
| 471 | "HostedOptions/makePublic" |
| 472 | ); |
| 473 | }, |
| 474 | } |
| 475 | ); |
| 476 | return ( |
| 477 | <Column> |
| 478 | <Title> |
| 479 | <Trans>Public</Trans> |
| 480 | </Title> |
| 481 | <Box flow="column" content="normal start" items="center stretch" gap={2}> |
| 482 | <label htmlFor="isPublic" className="text-sm"> |
| 483 | <Trans>Make publicly accessible</Trans> |
| 484 | </label> |
| 485 | <input |
| 486 | type="checkbox" |
| 487 | name="isPublic" |
| 488 | id="isPublic" |
| 489 | defaultChecked={isPublic} |
| 490 | data-session-activity="Toggle Make Public" |
| 491 | onChange={(e) => { |
| 492 | makePublic.mutate(e.target.checked); |
| 493 | }} |
| 494 | /> |
| 495 | {makePublic.isLoading && ( |
| 496 | <Spinner r={6} s={2} c="var(--color-highlightColor)" /> |
| 497 | )} |
| 498 | </Box> |
| 499 | {isPublic && ( |
| 500 | <Box> |
| 501 | <LinkCopy |
| 502 | value={`${window.location.origin}/p/${publicId}`} |
| 503 | title={t`Public`} |
| 504 | rawTitle="Public" |
| 505 | ariaLabel="Copy Public Link" |
| 506 | /> |
| 507 | </Box> |
nothing calls this directly
no test coverage detected