react-icons/io#IoMdRefresh TypeScript Examples
The following examples show how to use
react-icons/io#IoMdRefresh.
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.tsx From hub with Apache License 2.0 | 4 votes |
RepositoriesSection = (props: Props) => {
const history = useHistory();
const { ctx, dispatch } = useContext(AppCtx);
const [isLoading, setIsLoading] = useState(false);
const [modalStatus, setModalStatus] = useState<ModalStatus>({
open: false,
});
const [openClaimRepo, setOpenClaimRepo] = useState<boolean>(false);
const [repositories, setRepositories] = useState<Repo[] | undefined>(undefined);
const [activeOrg, setActiveOrg] = useState<undefined | string>(ctx.prefs.controlPanel.selectedOrg);
const [apiError, setApiError] = useState<null | string>(null);
const [activePage, setActivePage] = useState<number>(props.activePage ? parseInt(props.activePage) : 1);
const calculateOffset = (pageNumber?: number): number => {
return DEFAULT_LIMIT * ((pageNumber || activePage) - 1);
};
const [offset, setOffset] = useState<number>(calculateOffset());
const [total, setTotal] = useState<number | undefined>(undefined);
const onPageNumberChange = (pageNumber: number): void => {
setOffset(calculateOffset(pageNumber));
setActivePage(pageNumber);
};
const updatePageNumber = () => {
history.replace({
search: `?page=${activePage}${props.repoName ? `&repo-name=${props.repoName}` : ''}${
props.visibleModal ? `&modal=${props.visibleModal}` : ''
}`,
});
};
async function fetchRepositories() {
try {
setIsLoading(true);
let filters: { [key: string]: string[] } = {};
if (activeOrg) {
filters.org = [activeOrg];
} else {
filters.user = [ctx.user!.alias];
}
let query: SearchQuery = {
offset: offset,
limit: DEFAULT_LIMIT,
filters: filters,
};
const data = await API.searchRepositories(query);
const total = parseInt(data.paginationTotalCount);
if (total > 0 && data.items.length === 0) {
onPageNumberChange(1);
} else {
const repos = data.items;
setRepositories(repos);
setTotal(total);
// Check if active repo logs modal is in the available repos
if (!isUndefined(props.repoName)) {
const activeRepo = repos.find((repo: Repo) => repo.name === props.repoName);
// Clean query string if repo is not available
if (isUndefined(activeRepo)) {
dispatch(unselectOrg());
history.replace({
search: `?page=${activePage}`,
});
}
} else {
updatePageNumber();
}
}
setApiError(null);
setIsLoading(false);
} catch (err: any) {
setIsLoading(false);
if (err.kind !== ErrorKind.Unauthorized) {
setApiError('An error occurred getting the repositories, please try again later.');
setRepositories([]);
} else {
props.onAuthError();
}
}
}
useEffect(() => {
if (isUndefined(props.activePage)) {
updatePageNumber();
}
}, []); /* eslint-disable-line react-hooks/exhaustive-deps */
useEffect(() => {
if (props.activePage && activePage !== parseInt(props.activePage)) {
fetchRepositories();
}
}, [activePage]); /* eslint-disable-line react-hooks/exhaustive-deps */
useEffect(() => {
if (!isUndefined(repositories)) {
if (activePage === 1) {
// fetchRepositories is forced when context changes
fetchRepositories();
} else {
// when current page is different to 1, to update page number fetchRepositories is called
onPageNumberChange(1);
}
}
}, [activeOrg]); /* eslint-disable-line react-hooks/exhaustive-deps */
useEffect(() => {
if (activeOrg !== ctx.prefs.controlPanel.selectedOrg) {
setActiveOrg(ctx.prefs.controlPanel.selectedOrg);
}
}, [ctx.prefs.controlPanel.selectedOrg]); /* eslint-disable-line react-hooks/exhaustive-deps */
useEffect(() => {
fetchRepositories();
}, []); /* eslint-disable-line react-hooks/exhaustive-deps */
return (
<main
role="main"
className="pe-xs-0 pe-sm-3 pe-md-0 d-flex flex-column flex-md-row justify-content-between my-md-4"
>
<div className="flex-grow-1 w-100">
<div>
<div className="d-flex flex-row align-items-center justify-content-between pb-2 border-bottom">
<div className={`h3 pb-0 ${styles.title}`}>Repositories</div>
<div>
<button
className={`btn btn-outline-secondary btn-sm text-uppercase me-0 me-md-2 ${styles.btnAction}`}
onClick={fetchRepositories}
aria-label="Refresh repositories list"
>
<div className="d-flex flex-row align-items-center justify-content-center">
<IoMdRefresh className="d-inline d-md-none" />
<IoMdRefreshCircle className="d-none d-md-inline me-2" />
<span className="d-none d-md-inline">Refresh</span>
</div>
</button>
<button
className={`btn btn-outline-secondary btn-sm text-uppercase me-0 me-md-2 ${styles.btnAction}`}
onClick={() => setOpenClaimRepo(true)}
aria-label="Open claim repository modal"
>
<div className="d-flex flex-row align-items-center justify-content-center">
<RiArrowLeftRightLine className="me-md-2" />
<span className="d-none d-md-inline">Claim ownership</span>
</div>
</button>
<ActionBtn
className={`btn btn-outline-secondary btn-sm text-uppercase ${styles.btnAction}`}
contentClassName="justify-content-center"
onClick={(e: ReactMouseEvent<HTMLButtonElement>) => {
e.preventDefault();
setModalStatus({ open: true });
}}
action={AuthorizerAction.AddOrganizationRepository}
label="Open add repository modal"
>
<>
<MdAdd className="d-inline d-md-none" />
<MdAddCircle className="d-none d-md-inline me-2" />
<span className="d-none d-md-inline">Add</span>
</>
</ActionBtn>
</div>
</div>
</div>
{modalStatus.open && (
<RepositoryModal
open={modalStatus.open}
repository={modalStatus.repository}
onSuccess={fetchRepositories}
onAuthError={props.onAuthError}
onClose={() => setModalStatus({ open: false })}
/>
)}
{openClaimRepo && (
<ClaimOwnershipRepositoryModal
open={openClaimRepo}
onAuthError={props.onAuthError}
onClose={() => setOpenClaimRepo(false)}
onSuccess={fetchRepositories}
/>
)}
{(isLoading || isUndefined(repositories)) && <Loading />}
<p className="mt-5">
If you want your repositories to be labeled as <span className="fw-bold">Verified Publisher</span>, you can
add a{' '}
<ExternalLink
href="https://github.com/artifacthub/hub/blob/master/docs/metadata/artifacthub-repo.yml"
className="text-reset"
label="Open documentation"
>
<u>metadata file</u>
</ExternalLink>{' '}
to each of them including the repository ID provided below. This label will let users know that you own or
have control over the repository. The repository metadata file must be located at the path used in the
repository URL.
</p>
{!isUndefined(repositories) && (
<>
{repositories.length === 0 ? (
<NoData issuesLinkVisible={!isNull(apiError)}>
{isNull(apiError) ? (
<>
<p className="h6 my-4">Add your first repository!</p>
<ActionBtn
className="btn btn-sm btn-outline-secondary"
onClick={(e: ReactMouseEvent<HTMLButtonElement>) => {
e.preventDefault();
setModalStatus({ open: true });
}}
action={AuthorizerAction.AddOrganizationRepository}
label="Open add first repository modal"
>
<div className="d-flex flex-row align-items-center text-uppercase">
<MdAddCircle className="me-2" />
<span>Add repository</span>
</div>
</ActionBtn>
</>
) : (
<>{apiError}</>
)}
</NoData>
) : (
<>
<div className="row mt-3 mt-md-4 gx-0 gx-xxl-4" data-testid="repoList">
{repositories.map((repo: Repo) => (
<RepositoryCard
key={`repo_${repo.name}`}
repository={repo}
visibleModal={
// Legacy - old tracking errors email were not passing modal param
!isUndefined(props.repoName) && repo.name === props.repoName
? props.visibleModal || 'tracking'
: undefined
}
setModalStatus={setModalStatus}
onSuccess={fetchRepositories}
onAuthError={props.onAuthError}
/>
))}
</div>
{!isUndefined(total) && (
<Pagination
limit={DEFAULT_LIMIT}
offset={offset}
total={total}
active={activePage}
className="my-5"
onChange={onPageNumberChange}
/>
)}
</>
)}
</>
)}
</div>
</main>
);
}
Example #2
Source File: Inspector.tsx From openchakra with MIT License | 4 votes |
Inspector = () => {
const dispatch = useDispatch()
const component = useSelector(getSelectedComponent)
const { isOpen, onOpen, onClose } = useDisclosure()
const [componentName, onChangeComponentName] = useState('')
const componentsNames = useSelector(getComponentNames)
const { clearActiveProps } = useInspectorUpdate()
const saveComponent = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault()
dispatch.components.setComponentName({
componentId: component.id,
name: componentName,
})
onClose()
onChangeComponentName('')
}
const isValidComponentName = useMemo(() => {
return (
!!componentName.match(/^[A-Z]\w*$/g) &&
!componentsNames.includes(componentName) &&
// @ts-ignore
!componentsList.includes(componentName)
)
}, [componentName, componentsNames])
const { type, rootParentType, id, children } = component
const isRoot = id === 'root'
const parentIsRoot = component.parent === 'root'
const docType = rootParentType || type
const componentHasChildren = children.length > 0
useEffect(() => {
clearActiveProps()
}, [clearActiveProps])
return (
<>
<Box bg="white">
<Box
fontWeight="semibold"
fontSize="md"
color="yellow.900"
py={2}
px={2}
boxShadow="sm"
bg="yellow.100"
display="flex"
justifyContent="space-between"
flexDir="column"
>
{isRoot ? 'Document' : type}
{!!component.componentName && (
<Text fontSize="xs" fontWeight="light">
{component.componentName}
</Text>
)}
</Box>
{!isRoot && (
<Stack
direction="row"
py={2}
spacing={2}
align="center"
zIndex={99}
px={2}
flexWrap="wrap"
justify="flex-end"
>
<CodeActionButton />
{!component.componentName && (
<ActionButton
label="Name component"
icon={<EditIcon path="" />}
onClick={onOpen}
/>
)}
<ActionButton
label="Duplicate"
onClick={() => dispatch.components.duplicate()}
icon={<CopyIcon path="" />}
/>
<ActionButton
label="Reset props"
icon={<IoMdRefresh />}
onClick={() => dispatch.components.resetProps(component.id)}
/>
<ActionButton
label="Chakra UI Doc"
as={Link}
onClick={() => {
window.open(
`https://chakra-ui.com/${docType.toLowerCase()}`,
'_blank',
)
}}
icon={<GoRepo />}
/>
<ActionButton
bg="red.500"
label="Remove"
onClick={() => dispatch.components.deleteComponent(component.id)}
icon={<FiTrash2 />}
/>
</Stack>
)}
</Box>
<Box pb={1} bg="white" px={3}>
<Panels component={component} isRoot={isRoot} />
</Box>
<StylesPanel
isRoot={isRoot}
showChildren={componentHasChildren}
parentIsRoot={parentIsRoot}
/>
<Modal onClose={onClose} isOpen={isOpen} isCentered>
<ModalOverlay>
<ModalContent>
<form onSubmit={saveComponent}>
<ModalHeader>Save this component</ModalHeader>
<ModalCloseButton />
<ModalBody>
<FormControl isInvalid={!isValidComponentName}>
<FormLabel>Component name</FormLabel>
<Input
size="md"
autoFocus
variant="outline"
isFullWidth
focusBorderColor="blue.500"
errorBorderColor="red.500"
value={componentName}
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
onChangeComponentName(e.target.value)
}
/>
{!isValidComponentName && (
<FormErrorMessage>
Component name must start with a capital character and
must not contain space or special character, and name
should not be already taken (including existing chakra-ui
components).
</FormErrorMessage>
)}
<FormHelperText>
This will name your component that you will see in the code
panel as a separated component.
</FormHelperText>
</FormControl>
</ModalBody>
<ModalFooter>
<Button
colorScheme="blue"
mr={3}
type="submit"
isDisabled={!isValidComponentName}
>
Save
</Button>
<Button onClick={onClose}>Cancel</Button>
</ModalFooter>
</form>
</ModalContent>
</ModalOverlay>
</Modal>
</>
)
}