@airtable/blocks/ui#Loader JavaScript Examples
The following examples show how to use
@airtable/blocks/ui#Loader.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.js From apps-wikipedia-enrichment with MIT License | 5 votes |
function WikipediaEnrichmentApp() {
const base = useBase();
const table = base.getTableByName(TABLE_NAME);
const titleField = table.getFieldByName(TITLE_FIELD_NAME);
// load the records ready to be updated
// we only need to load the word field - the others don't get read, only written to.
const records = useRecords(table, {fields: [titleField]});
// keep track of whether we have up update currently in progress - if there is, we want to hide
// the update button so you can't have two updates running at once.
const [isUpdateInProgress, setIsUpdateInProgress] = useState(false);
// check whether we have permission to update our records or not. Any time we do a permissions
// check like this, we can pass in undefined for values we don't yet know. Here, as we want to
// make sure we can update the summary and image fields, we make sure to include them even
// though we don't know the values we want to use for them yet.
const permissionCheck = table.checkPermissionsForUpdateRecord(undefined, {
[EXTRACT_FIELD_NAME]: undefined,
[IMAGE_FIELD_NAME]: undefined,
});
async function onButtonClick() {
setIsUpdateInProgress(true);
const recordUpdates = await getExtractAndImageUpdatesAsync(table, titleField, records);
await updateRecordsInBatchesAsync(table, recordUpdates);
setIsUpdateInProgress(false);
}
return (
<Box
// center the button/loading spinner horizontally and vertically.
position="absolute"
top="0"
bottom="0"
left="0"
right="0"
display="flex"
flexDirection="column"
justifyContent="center"
alignItems="center"
>
{isUpdateInProgress ? (
<Loader />
) : (
<Fragment>
<Button
variant="primary"
onClick={onButtonClick}
disabled={!permissionCheck.hasPermission}
marginBottom={3}
>
Update summaries and images
</Button>
{!permissionCheck.hasPermission &&
// when we don't have permission to perform the update, we want to tell the
// user why. `reasonDisplayString` is a human-readable string that will
// explain why the button is disabled.
permissionCheck.reasonDisplayString}
</Fragment>
)}
</Box>
);
}
Example #2
Source File: sync-data.js From neighbor-express with MIT License | 5 votes |
export function SyncData() {
const messagesTable = useBase().getTable(DESTINATION_TABLE);
const records = useRecords(messagesTable);
const [completed, setCompleted] = useState(false);
const [syncing, setSyncing] = useState(false);
const [succesfulCount, setSuccesfulCount] = useState(0);
const [syncError, setSyncError] = useState(null);
async function syncData() {
setCompleted(false);
setSyncing(true);
const { total, err } = await SyncVolunteerData(messagesTable, records);
setSuccesfulCount(total);
setSyncError(err);
setSyncing(false);
setCompleted(true);
}
return (
<Box>
<h2> Sync Galaxy Digital Data </h2>
{syncing && !completed && <Loader />}
{!syncing && (
<>
{completed && !syncError && (
<p>Successfully updated all volunteer data</p>
)}
{completed && syncError && (
<p>
`Sync completed for ${succesfulCount} with error ${syncError}`
</p>
)}
<Box
margin={2}
display="flex"
flexDirection="row"
justifyContent="flex-start"
alignItems="center"
>
<Button
marginX={2}
variant="primary"
onClick={syncData}
disabled={syncing}
>
Sync
</Button>
</Box>
</>
)}
</Box>
);
}