<commit_before>import React, { ChangeEvent } from 'react';
import { c } from 'ttag';
import { SETTINGS_WEEK_START } from 'proton-shared/lib/interfaces';
import { updateWeekStart } from 'proton-shared/lib/api/settings';
import { loadDateLocale } from 'proton-shared/lib/i18n/loadLocale';
import { dateLocaleCode } from 'proton-shared/lib/i18n';
import { getDefaultWeekStartsOn } from 'proton-shared/lib/settings/helper';
import { getBrowserLocale } from 'proton-shared/lib/i18n/helper';

import { Row, Label, Field, Select } from '../../components';
import { useApi, useEventManager, useNotifications, useLoading, useUserSettings } from '../../hooks';

const WeekStartSection = () => {
    const api = useApi();
    const [userSettings] = useUserSettings();
    const { call } = useEventManager();
    const { createNotification } = useNotifications();
    const [loading, withLoading] = useLoading();

    const handleWeekStart = async (value: SETTINGS_WEEK_START) => {
        await loadDateLocale(dateLocaleCode, getBrowserLocale(), { ...userSettings, WeekStart: value });
        await api(updateWeekStart(value));
        await call();
        createNotification({ text: c('Success').t`Preference saved` });
    };

    const days = [
        { text: c('Day').t`Sunday`, value: SETTINGS_WEEK_START.SUNDAY },
        { text: c('Day').t`Monday`, value: SETTINGS_WEEK_START.MONDAY },
        { text: c('Day').t`Tuesday`, value: SETTINGS_WEEK_START.TUESDAY },
        { text: c('Day').t`Wednesday`, value: SETTINGS_WEEK_START.WEDNESDAY },
        { text: c('Day').t`Thursday`, value: SETTINGS_WEEK_START.THURSDAY },
        { text: c('Day').t`Friday`, value: SETTINGS_WEEK_START.FRIDAY },
        { text: c('Day').t`Saturday`, value: SETTINGS_WEEK_START.SATURDAY },
    ];

    const defaultDay = days[getDefaultWeekStartsOn()].text;

    return (
        <Row>
            <Label htmlFor="week-start-select">{c('Label').t`Week start`}</Label>
            <Field>
                <Select
                    id="week-start-select"
                    loading={loading}
                    onChange={({ target }: ChangeEvent<HTMLSelectElement>) =>
                        withLoading(handleWeekStart(+target.value))
                    }
                    value={userSettings.WeekStart}
                    options={[
                        {
                            text: c('Option').t`Use system settings (${defaultDay})`,
                            value: SETTINGS_WEEK_START.LOCALE_DEFAULT,
                        },
                        ...days,
                    ]}
                />
            </Field><commit_msg>Only show Sunday, Monday, and Saturday in the week start picker<commit_after>import React, { ChangeEvent } from 'react';
import { c } from 'ttag';
import { SETTINGS_WEEK_START } from 'proton-shared/lib/interfaces';
import { updateWeekStart } from 'proton-shared/lib/api/settings';
import { loadDateLocale } from 'proton-shared/lib/i18n/loadLocale';
import { dateLocaleCode } from 'proton-shared/lib/i18n';
import { getDefaultWeekStartsOn } from 'proton-shared/lib/settings/helper';
import { getBrowserLocale } from 'proton-shared/lib/i18n/helper';

import { Row, Label, Field, Select } from '../../components';
import { useApi, useEventManager, useNotifications, useLoading, useUserSettings } from '../../hooks';

const WeekStartSection = () => {
    const api = useApi();
    const [userSettings] = useUserSettings();
    const { call } = useEventManager();
    const { createNotification } = useNotifications();
    const [loading, withLoading] = useLoading();

    const handleWeekStart = async (value: SETTINGS_WEEK_START) => {
        await loadDateLocale(dateLocaleCode, getBrowserLocale(), { ...userSettings, WeekStart: value });
        await api(updateWeekStart(value));
        await call();
        createNotification({ text: c('Success').t`Preference saved` });
    };

    const days = [
        { text: c('Day').t`Sunday`, value: SETTINGS_WEEK_START.SUNDAY },
        { text: c('Day').t`Monday`, value: SETTINGS_WEEK_START.MONDAY },
        { text: c('Day').t`Tuesday`, value: SETTINGS_WEEK_START.TUESDAY },
        { text: c('Day').t`Wednesday`, value: SETTINGS_WEEK_START.WEDNESDAY },
        { text: c('Day').t`Thursday`, value: SETTINGS_WEEK_START.THURSDAY },
        { text: c('Day').t`Friday`, value: SETTINGS_WEEK_START.FRIDAY },
        { text: c('Day').t`Saturday`, value: SETTINGS_WEEK_START.SATURDAY },
    ];

    const defaultDay = days[getDefaultWeekStartsOn()].text;

    return (
        <Row>
            <Label htmlFor="week-start-select">{c('Label').t`Week start`}</Label>
            <Field>
                <Select
                    id="week-start-select"
                    loading={loading}
                    onChange={({ target }: ChangeEvent<HTMLSelectElement>) =>
                        withLoading(handleWeekStart(+target.value))
                    }
                    value={userSettings.WeekStart}
                    options={[
                        {
                            text: c('Option').t`Use system settings (${defaultDay})`,
                            value: SETTINGS_WEEK_START.LOCALE_DEFAULT,
                        },
                        days[0],
                        days[1],
                        days[6],
                    ]}
                />
            </Field>
{'fraction_non_alphanumeric': 0.13938381588715665, 'fraction_numerical': 0.0027839643652561247, 'mean_word_length': 2.3265432098765433, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 23, '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': '6645171', 'n_tokens_mistral': 1602, 'n_tokens_neox': 1531, 'n_words': 295}