mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-04-20 22:50:11 -04:00
* Hide notice on overview and - Removed prettier/recommended from eslint - Optimized imports * move overview check to parent * don't show recents if there is none * use useMatch
57 lines
1.3 KiB
TypeScript
57 lines
1.3 KiB
TypeScript
import { CRDTOperation, useLibraryQuery, useLibrarySubscription } from '@sd/client';
|
|
import { tw } from '@sd/ui';
|
|
|
|
const Label = tw.span`text-gray-300`;
|
|
const Pill = tw.span`rounded-full bg-gray-500 px-2 py-1`;
|
|
const Row = tw.p`overflow-hidden text-ellipsis space-x-1`;
|
|
|
|
const OperationItem = ({ op }: { op: CRDTOperation }) => {
|
|
let contents = null;
|
|
|
|
if ('record_id' in op.typ) {
|
|
let subContents = null;
|
|
|
|
if (op.typ.data === null) {
|
|
subContents = 'Delete';
|
|
} else if (op.typ.data === 'a' || 'u' in op.typ.data) {
|
|
subContents = 'Create';
|
|
} else {
|
|
subContents = `Update - ${op.typ.data.field}`;
|
|
}
|
|
|
|
contents = (
|
|
<>
|
|
<div className="space-x-2">
|
|
<Pill>{subContents}</Pill>
|
|
</div>
|
|
<Row>
|
|
<Label>Model</Label>
|
|
<span>{op.typ.model}</span>
|
|
</Row>
|
|
<Row>
|
|
<Label>Time</Label>
|
|
<span>{op.timestamp}</span>
|
|
</Row>
|
|
</>
|
|
);
|
|
}
|
|
|
|
return <li className="space-y-1 rounded-md bg-gray-700 p-2 text-sm">{contents}</li>;
|
|
};
|
|
|
|
export const Component = () => {
|
|
const messages = useLibraryQuery(['sync.messages']);
|
|
|
|
useLibrarySubscription(['sync.newMessage'], {
|
|
onData: () => messages.refetch()
|
|
});
|
|
|
|
return (
|
|
<ul className="space-y-2">
|
|
{messages.data?.map((op) => (
|
|
<OperationItem key={op.id} op={op} />
|
|
))}
|
|
</ul>
|
|
);
|
|
};
|