feat: add managed database capture and operator restore
PostgreSQL and MySQL backups run through paired outposts, with operator sign-in, off-site copies, and legacy import. Retention stays on each orbit, so the unused retention console is removed. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,25 +1,40 @@
|
||||
import { useLayoutEffect } from "react";
|
||||
import { useLayoutEffect, useRef } from "react";
|
||||
|
||||
export function useGalaxyMotion(draw: (elapsed: number) => boolean) {
|
||||
const latest = useRef(draw);
|
||||
const wake = useRef<() => void>(undefined);
|
||||
|
||||
export function useGalaxyMotion(active: boolean, draw: (elapsed: number) => boolean) {
|
||||
useLayoutEffect(() => {
|
||||
let frame = 0;
|
||||
let previous: number | undefined;
|
||||
|
||||
const tick = (now: number) => {
|
||||
const keepDrawing = draw(previous === undefined ? 0 : (now - previous) / 1000);
|
||||
previous = now;
|
||||
if (keepDrawing) frame = requestAnimationFrame(tick);
|
||||
frame = 0;
|
||||
const keepDrawing = latest.current(previous === undefined ? 0 : (now - previous) / 1000);
|
||||
previous = keepDrawing ? now : undefined;
|
||||
if (keepDrawing) schedule();
|
||||
};
|
||||
const sync = () => {
|
||||
const schedule = () => {
|
||||
if (!frame && !document.hidden) frame = requestAnimationFrame(tick);
|
||||
};
|
||||
const visibilityChanged = () => {
|
||||
cancelAnimationFrame(frame);
|
||||
frame = 0;
|
||||
previous = undefined;
|
||||
if (!document.hidden && active) frame = requestAnimationFrame(tick);
|
||||
if (!document.hidden && latest.current(0)) schedule();
|
||||
};
|
||||
draw(0);
|
||||
sync();
|
||||
document.addEventListener("visibilitychange", sync);
|
||||
|
||||
wake.current = schedule;
|
||||
document.addEventListener("visibilitychange", visibilityChanged);
|
||||
return () => {
|
||||
cancelAnimationFrame(frame);
|
||||
document.removeEventListener("visibilitychange", sync);
|
||||
wake.current = undefined;
|
||||
document.removeEventListener("visibilitychange", visibilityChanged);
|
||||
};
|
||||
}, [active, draw]);
|
||||
}, []);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
latest.current = draw;
|
||||
if (draw(0)) wake.current?.();
|
||||
});
|
||||
}
|
||||
|
||||
97
web/src/hooks/useScreenTransition.ts
Normal file
97
web/src/hooks/useScreenTransition.ts
Normal file
@@ -0,0 +1,97 @@
|
||||
import { animate, useMotionValue } from "motion/react";
|
||||
import { useLayoutEffect, useRef, type RefObject } from "react";
|
||||
import { gentleSpring } from "../lib/motion";
|
||||
|
||||
export function useScreenTransition(
|
||||
ref: RefObject<HTMLElement | null>,
|
||||
bigScreen: boolean,
|
||||
reducedMotion: boolean,
|
||||
onSettled?: (width: number) => void,
|
||||
fade = false,
|
||||
) {
|
||||
const centerX = useMotionValue(0);
|
||||
const centerY = useMotionValue(0);
|
||||
const width = useMotionValue(0);
|
||||
const height = useMotionValue(0);
|
||||
const target = useRef<DOMRect>(undefined);
|
||||
const lastMode = useRef(bigScreen);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
if (!ref.current) return;
|
||||
const element = ref.current;
|
||||
const values = [centerX, centerY, width, height];
|
||||
const changedMode = lastMode.current !== bigScreen;
|
||||
lastMode.current = bigScreen;
|
||||
let revision = 0;
|
||||
|
||||
function paint() {
|
||||
const rect = target.current;
|
||||
if (!rect?.width || !rect.height) return;
|
||||
const x = centerX.get() - rect.left - rect.width / 2;
|
||||
const y = centerY.get() - rect.top - rect.height / 2;
|
||||
const sx = width.get() / rect.width;
|
||||
const sy = height.get() / rect.height;
|
||||
element.style.transform = `translate(${x}px, ${y}px) scale(${sx}, ${sy})`;
|
||||
if (fade) element.style.opacity = String(1 - Math.min(0.35, Math.hypot(x, y) / 300));
|
||||
}
|
||||
|
||||
function measure(transition = false) {
|
||||
const previous = target.current;
|
||||
element.style.transform = "";
|
||||
const next = element.getBoundingClientRect();
|
||||
target.current = next;
|
||||
const destination = [next.left + next.width / 2, next.top + next.height / 2, next.width, next.height];
|
||||
const animating = values.some(value => value.isAnimating());
|
||||
if (previous && next.x === previous.x && next.y === previous.y &&
|
||||
next.width === previous.width && next.height === previous.height && !reducedMotion && !transition) {
|
||||
if (animating) paint();
|
||||
return;
|
||||
}
|
||||
|
||||
const version = ++revision;
|
||||
const finish = () => {
|
||||
element.style.transform = "";
|
||||
if (fade) element.style.opacity = "";
|
||||
onSettled?.(element.clientWidth);
|
||||
};
|
||||
if (reducedMotion || !previous?.width || !previous.height || (!transition && !animating)) {
|
||||
values.forEach((value, index) => value.jump(destination[index]));
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
let remaining = values.length;
|
||||
paint();
|
||||
values.forEach((value, index) => animate(value, destination[index], {
|
||||
...gentleSpring,
|
||||
restDelta: 0.25,
|
||||
restSpeed: 2,
|
||||
onComplete: () => {
|
||||
if (version === revision && --remaining === 0) finish();
|
||||
},
|
||||
}));
|
||||
}
|
||||
|
||||
const unsubscribes = values.map(value => value.on("change", paint));
|
||||
const resize = () => measure();
|
||||
const observer = new ResizeObserver(resize);
|
||||
observer.observe(element);
|
||||
window.addEventListener("resize", resize);
|
||||
window.addEventListener("scroll", resize, { passive: true });
|
||||
measure(changedMode);
|
||||
return () => {
|
||||
revision++;
|
||||
unsubscribes.forEach(unsubscribe => unsubscribe());
|
||||
observer.disconnect();
|
||||
window.removeEventListener("resize", resize);
|
||||
window.removeEventListener("scroll", resize);
|
||||
};
|
||||
}, [ref, bigScreen, reducedMotion, onSettled, fade, centerX, centerY, width, height]);
|
||||
|
||||
useLayoutEffect(() => () => {
|
||||
centerX.stop();
|
||||
centerY.stop();
|
||||
width.stop();
|
||||
height.stop();
|
||||
}, [centerX, centerY, width, height]);
|
||||
}
|
||||
Reference in New Issue
Block a user