<commit_before>import React, { useState } from 'react';
import { c } from 'ttag';
import { Label, Checkbox, useApiWithoutResult, useUserSettings, useEventManager } from 'react-components';
import { NEWS } from 'proton-shared/lib/constants';
import { updateNews } from 'proton-shared/lib/api/settings';
import { toggleBit, hasBit } from 'proton-shared/lib/helpers/bitset';

const { ANNOUNCEMENTS, FEATURES, NEWSLETTER, BETA } = NEWS;

const NewsCheckboxes = () => {
    const [{ News }] = useUserSettings();
    const { call } = useEventManager();
    const { request, loading } = useApiWithoutResult(updateNews);
    const [news, setNews] = useState(News);

    const handleChange = async (mask) => {
        const newNews = toggleBit(news, mask);

        setNews(newNews);
        await request(newNews);
        await call();
    };

    return (
        <>
            <Label htmlFor="announcements">
                <Checkbox
                    id="announcements"
                    checked={hasBit(news, ANNOUNCEMENTS)}
                    disabled={loading}
                    onChange={handleChange(ANNOUNCEMENTS)}
                />
                {c('Label for news').t`Major announcements (2-3 per year)`}
            </Label>
            <Label htmlFor="features">
                <Checkbox
                    id="features"
                    checked={hasBit(news, FEATURES)}
                    disabled={loading}
                    onChange={handleChange(FEATURES)}
                />
                {c('Label for news').t`Major features (3-4 per year)`}
            </Label>
            <Label htmlFor="newsletter">
                <Checkbox
                    id="newsletter"
                    checked={hasBit(news, NEWSLETTER)}
                    disabled={loading}
                    onChange={handleChange(NEWSLETTER)}
                />
                {c('Label for news').t`Proton newsletter (5-6 per year)`}
            </Label>
            <Label htmlFor="beta">
                <Checkbox id="beta" checked={hasBit(news, BETA)} disabled={loading} onChange={handleChange(BETA)} />
                {c('Label for news').t`Proton Beta (10-12 per year)`}
            </Label>
        </>
    );
};

export default NewsCheckboxes;
<commit_msg>Hotfix - handleChange has first an input: mask and then the event<commit_after>import React, { useState } from 'react';
import { c } from 'ttag';
import { Label, Checkbox, useApiWithoutResult, useUserSettings, useEventManager } from 'react-components';
import { NEWS } from 'proton-shared/lib/constants';
import { updateNews } from 'proton-shared/lib/api/settings';
import { toggleBit, hasBit } from 'proton-shared/lib/helpers/bitset';

const { ANNOUNCEMENTS, FEATURES, NEWSLETTER, BETA } = NEWS;

const NewsCheckboxes = () => {
    const [{ News }] = useUserSettings();
    const { call } = useEventManager();
    const { request, loading } = useApiWithoutResult(updateNews);
    const [news, setNews] = useState(News);

    const handleChange = (mask) => async () => {
        const newNews = toggleBit(news, mask);

        await request(newNews);
        await call();
        setNews(newNews);
    };

    return (
        <>
            <Label htmlFor="announcements">
                <Checkbox
                    id="announcements"
                    checked={hasBit(news, ANNOUNCEMENTS)}
                    disabled={loading}
                    onChange={handleChange(ANNOUNCEMENTS)}
                />
                {c('Label for news').t`Major announcements (2-3 per year)`}
            </Label>
            <Label htmlFor="features">
                <Checkbox
                    id="features"
                    checked={hasBit(news, FEATURES)}
                    disabled={loading}
                    onChange={handleChange(FEATURES)}
                />
                {c('Label for news').t`Major features (3-4 per year)`}
            </Label>
            <Label htmlFor="newsletter">
                <Checkbox
                    id="newsletter"
                    checked={hasBit(news, NEWSLETTER)}
                    disabled={loading}
                    onChange={handleChange(NEWSLETTER)}
                />
                {c('Label for news').t`Proton newsletter (5-6 per year)`}
            </Label>
            <Label htmlFor="beta">
                <Checkbox id="beta" checked={hasBit(news, BETA)} disabled={loading} onChange={handleChange(BETA)} />
                {c('Label for news').t`Proton Beta (10-12 per year)`}
            </Label>
        </>
    );
};

export default NewsCheckboxes;

{'fraction_non_alphanumeric': 0.12505427702996091, 'fraction_numerical': 0.004342162396873643, 'mean_word_length': 1.8420727945712523, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1086443', 'n_tokens_mistral': 1295, 'n_tokens_neox': 1236, 'n_words': 276}