How to use the react-components.useApiWithoutResult function in react-components

To help you get started, we’ve selected a few react-components examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ProtonMail / react-components / containers / labels / modals / Edit.js View on Github external
function EditLabelModal({ label, mode, onEdit, onAdd, ...props }) {
    const { call } = useEventManager();
    const { createNotification } = useNotifications();
    const reqCreate = useApiWithoutResult(createLabel);
    const reqUpdate = useApiWithoutResult(updateLabel);

    const I18N = {
        edition({ Exclusive } = {}) {
            if (Exclusive === LABEL_EXCLUSIVE.LABEL) {
                return c('Label/folder modal').t`Edit label`;
            }
            return c('Label/folder modal').t`Edit folder`;
        },
        create(label, type) {
            if (type === 'label') {
                return c('Label/folder modal').t`Create a new label`;
            }
            return c('Label/folder modal').t`Create a new folder`;
        }
    };
github ProtonMail / react-components / containers / filters / AddFilterModal.js View on Github external
function AddFilterModal({ filter, type, mode = 'create', onEdit = noop, ...props }) {
    const [filterModel] = useState(() => newFilter(filter, type));
    const [errors, setErrors] = useState({});
    const [model, setModel] = useState(filterModel);
    const [isPreview, setPreview] = useState(false);
    const [isInvalid, setValitidy] = useState(false);
    const [sieveCode, setSieveCode] = useState(filterModel.Sieve || '');

    const { call } = useEventManager();
    const { createNotification } = useNotifications();
    const reqCreate = useApiWithoutResult(addTreeFilter);
    const reqUpdate = useApiWithoutResult(updateFilter);

    const create = async (filter) => {
        const { Filter } = await reqCreate.request(filter);
        call();
        createNotification({
            text: c('Notification').t`${Filter.Name} created`
        });
        props.onClose();
    };

    const update = async (filter) => {
        const { Filter } = await reqUpdate.request(filter.ID, filter);
        call();
        createNotification({
            text: c('Filter notification').t`Filter ${Filter.Name} updated`
github ProtonMail / proton-mail-settings / src / app / containers / Filters / useFilters.js View on Github external
const useFilters = () => {
    const { result = {}, loading } = useApiResult(queryFilters, []);
    const requestStatus = useApiWithoutResult(toggleEnable);
    const requestRemove = useApiWithoutResult(deleteFilter);

    const [filerList, setFilters] = useState([]);

    useEffect(() => {
        setFilters(result.Filters || []);
    }, [result.Filters]);

    const toggleStatus = async ({ ID }, enable = true) => {
        await requestStatus.request(ID, enable);
    };

    const removeFilter = ({ ID }) => {
        setFilters(filerList.filter((filter) => filter.ID !== ID));
    };
github ProtonMail / react-components / containers / logs / LogsSection.js View on Github external
const LogsSection = () => {
    const i18n = getEventsI18N();
    const [settings] = useUserSettings();
    const { createModal } = useModals();
    const [logAuth, setLogAuth] = useState(settings.LogAuth);
    const { page, onNext, onPrevious, onSelect } = usePaginationAsync(1);
    const { result = {}, loading, request: requestQueryLogs } = useApiResult(
        () =>
            queryLogs({
                Page: page - 1,
                PageSize: ELEMENTS_PER_PAGE
            }),
        [page]
    );
    const { Logs: logs = [], Total: total = 0 } = result;
    const requestDownload = useApiWithoutResult(queryLogs);
    const { request: requestClearLogs } = useApiWithoutResult(clearLogs);
    const { request: requestUpdateLogAuth } = useApiWithoutResult(updateLogAuth);

    const handleWipe = async () => {
        await requestClearLogs();
        await requestQueryLogs();
    };

    const handleDownload = async () => {
        const { Logs = [] } = await requestDownload.request();
        const data = Logs.reduce(
            (acc, { Event, Time, IP }) => {
                acc.push(`${i18n[Event]},${moment(Time * 1000).toISOString()},${IP}`);
                return acc;
            },
            [['Event', 'Time', 'IP'].join(',')]
github ProtonMail / react-components / containers / filters / SpamFiltersSection.js View on Github external
function SpamFiltersSection() {
    const reqSearch = useApiWithoutResult(getIncomingDefaults);
    const { blackList, whiteList, refreshWhiteList, refreshBlackList, move, remove, search, create } = useSpamList();

    const { result: white = {}, loading: loadingWhite } = useApiResult(getWhiteList, []);
    const { result: black = {}, loading: loadingBlack } = useApiResult(getBlackList, []);

    const [loader, setLoader] = useState({});

    useEffect(() => {
        refreshWhiteList(white.IncomingDefaults || []);
        setLoader({ ...loader, white: loadingWhite });
    }, [white.IncomingDefaults]);

    useEffect(() => {
        refreshBlackList(black.IncomingDefaults || []);
        setLoader({ ...loader, black: loadingBlack });
    }, [black.IncomingDefaults]);

react-components

React components used by Khan Academy

MIT
Latest version published 7 years ago

Package Health Score

48 / 100
Full package analysis