Skip to content

Commit

Permalink
Merge pull request #1187 from Chia-Network/refactor/glossary-page
Browse files Browse the repository at this point in the history
feat: add sync remaining to indicator
  • Loading branch information
MichaelTaylor3D authored Apr 2, 2024
2 parents aa28008 + 37437bb commit dcf880a
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/renderer/components/blocks/widgets/SyncIndicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,48 @@ interface SyncIndicatorProps {
orgUid?: string;
}

/**
* Component to display sync status indicator.
* It shows a green circle if the organization is synced, and a pulsing yellow circle if syncing.
* When 'detailed' is true, it also shows a label next to the indicator.
* The sync status is determined based on 'orgUid' from the organizations data.
*/
const SyncIndicator: React.FC<SyncIndicatorProps> = ({ detailed, orgUid }) => {
const { data: organizationsMap } = useGetOrganizationsMapQuery(null, {
skip: !orgUid,
pollingInterval: 10000,
});

const { data: organizationList } = useGetOrganizationsListQuery(null, {
skip: Boolean(orgUid),
pollingInterval: 10000,
});

let isSynced = false;
let syncRemaining = 0;

if (!orgUid) {
isSynced = !organizationList?.some((org) => !org.synced);
if (!isSynced) {
syncRemaining = organizationList?.reduce((acc, org) => acc + org.sync_remaining, 0) ?? 0;
}
} else {
isSynced = organizationsMap?.[orgUid]?.synced;
const orgData = organizationsMap?.[orgUid];
isSynced = orgData?.synced;
if (!isSynced) {
syncRemaining = orgData?.sync_remaining ?? 0;
}
}

return (
<div className={`flex items-center space-x-2 ${detailed ? 'p-2 rounded-lg shadow bg-white dark:bg-gray-800' : ''}`}>
<div className={`${isSynced ? 'bg-green-500' : 'animate-pulse bg-yellow-500'} h-4 w-4 rounded-full`}></div>
{detailed && (
<span className={`text-sm ${isSynced ? 'text-green-700' : 'text-yellow-600'}`}>
{isSynced ? 'Synced' : 'Syncing...'}
</span>
<>
<span className={`text-sm ${isSynced ? 'text-green-700' : 'text-yellow-600'}`}>
{isSynced ? 'Synced' : 'Syncing...'}
</span>
{!isSynced && (
// Made "sync remaining" more subtle with lighter color and smaller font
<span className="text-xs text-yellow-400">
({syncRemaining} remaining)
</span>
)}
</>
)}
</div>
);
Expand Down

0 comments on commit dcf880a

Please sign in to comment.