<commit_before>import React, { createContext, useState, useContext, memo } from 'react';
import classNames from 'classnames';
import { extend } from 'koot';

import db from '@database';
import pref from '@api/preferences';

import htmlHead from '@utils/html-head';
import getTimeJST from '@utils/get-time-jst';
import getLink from '@utils/get-link';
import getShip from '@utils/get-ship';
import getEquipment from '@utils/get-equipment';
import sortShips from '@utils/sort-ships';
// import routerReplace from '@utils/router-replace'

// import {Link, IndexLink} from 'react-router'
import Page from '@ui/containers/page';

import Link from '@ui/components/link';
import LinkEquipment from '@ui/components/link/equipment';
import Title from '@ui/components/title';
import Button from '@ui/components/button';
import MainHeader from '@ui/components/main-header/main-options';
import {
    DayAndShip as ImprovementDayAndShip,
    Resources as ImprovementResources,
} from '@ui/components/improvement';
import ImprovementStar from '@ui/components/improvement/star';
import Icon from '@components/icon';

// ============================================================================

const daysArr = [
    'Sunday',
    'Monday',
    'Tuesday',
    'Wednesday',
    'Thurday',
    'Friday',
    'Saturday',
];

const ArsenalContext = createContext();

// ============================================================================

@extend({
    connect: true,
    pageinfo: (state, renderProps) => {
        const day =
            typeof renderProps.params === 'object'
                ? renderProps.params.day
                : undefined;
        return htmlHead(state, {
            title: [
                __('nav.arsenal'),
                typeof day !== 'undefined'
                    ? __(`day_full`, daysArr[day])
                    : undefined,
            ],
        });
    },
    styles: require('./styles.less'),
})
class PageArsenal extends React.Component {
    state = {
        rendering: true,
        watchList: pref.arsenalWatchList,
        collectionShow: db.equipmentCollections
            .map((c) => c.name)
            .reduce((r, cName) => {
                r[cName] =
                    !Array.isArray(pref.arsenalWatchList) ||
                    !pref.arsenalWatchList.length;
                return r;
            }, {}),
    };

    componentDidMount() {
        // get watchList, update collectionShow
    }

    componentDidUpdate(prevProps, prevState) {
        // const prevParams = prevProps.params || {}
        // const params = this.props.params || {}
        if (prevProps.params.day !== this.props.params.day)
            window.scrollTo(undefined, 0);
        if (prevState.watchList !== this.state.watchList)
            pref.arsenalWatchList = this.state.watchList;
    }

    onRender() {
        // if (!this.state.rendering)
        this.setState({
            rendering: false,
        });
    }
    onRender = this.onRender.bind(this);

    watchAdd(equipmentId, improvementIndex) {
        // console.log('WatchList: add', equipmentId, improvementIndex);
        const value = `${equipmentId}-${improvementIndex}`;
        this.setState((state) => ({
            watchList: Array.isArray(state.watchList)
                ? [...state.watchList, value]
                : [value],
        }));
    }
    watchAdd = this.watchAdd.bind(this);
    watchRemove(equipmentId, improvementIndex) {
        if (!Array.isArray(this.state.watchList)) return;
        const value = `${equipmentId}-${improvementIndex}`;
        this.setState((state) => {
            const index = state.watchList.indexOf(value);
            if (index < 0) return {};
            if (state.watchList.length === 1)
                return {
                    watchList: false,
                };
            return {
                watchList: [...state.watchList.splice(index, 1)],
            };
        });
    }<commit_msg>fix: Arsenal - remove from watch list<commit_after>import React, { createContext, useState, useContext, memo } from 'react';
import classNames from 'classnames';
import { extend } from 'koot';

import db from '@database';
import pref from '@api/preferences';

import htmlHead from '@utils/html-head';
import getTimeJST from '@utils/get-time-jst';
import getLink from '@utils/get-link';
import getShip from '@utils/get-ship';
import getEquipment from '@utils/get-equipment';
import sortShips from '@utils/sort-ships';
// import routerReplace from '@utils/router-replace'

// import {Link, IndexLink} from 'react-router'
import Page from '@ui/containers/page';

import Link from '@ui/components/link';
import LinkEquipment from '@ui/components/link/equipment';
import Title from '@ui/components/title';
import Button from '@ui/components/button';
import MainHeader from '@ui/components/main-header/main-options';
import {
    DayAndShip as ImprovementDayAndShip,
    Resources as ImprovementResources,
} from '@ui/components/improvement';
import ImprovementStar from '@ui/components/improvement/star';
import Icon from '@components/icon';

// ============================================================================

const daysArr = [
    'Sunday',
    'Monday',
    'Tuesday',
    'Wednesday',
    'Thurday',
    'Friday',
    'Saturday',
];

const ArsenalContext = createContext();

// ============================================================================

@extend({
    connect: true,
    pageinfo: (state, renderProps) => {
        const day =
            typeof renderProps.params === 'object'
                ? renderProps.params.day
                : undefined;
        return htmlHead(state, {
            title: [
                __('nav.arsenal'),
                typeof day !== 'undefined'
                    ? __(`day_full`, daysArr[day])
                    : undefined,
            ],
        });
    },
    styles: require('./styles.less'),
})
class PageArsenal extends React.Component {
    state = {
        rendering: true,
        watchList: pref.arsenalWatchList,
        collectionShow: db.equipmentCollections
            .map((c) => c.name)
            .reduce((r, cName) => {
                r[cName] =
                    !Array.isArray(pref.arsenalWatchList) ||
                    !pref.arsenalWatchList.length;
                return r;
            }, {}),
    };

    componentDidMount() {
        // get watchList, update collectionShow
    }

    componentDidUpdate(prevProps, prevState) {
        // const prevParams = prevProps.params || {}
        // const params = this.props.params || {}
        if (prevProps.params.day !== this.props.params.day)
            window.scrollTo(undefined, 0);
        if (prevState.watchList !== this.state.watchList)
            pref.arsenalWatchList = this.state.watchList;
    }

    onRender() {
        // if (!this.state.rendering)
        this.setState({
            rendering: false,
        });
    }
    onRender = this.onRender.bind(this);

    watchAdd(equipmentId, improvementIndex) {
        // console.log('WatchList: add', equipmentId, improvementIndex);
        const value = `${equipmentId}-${improvementIndex}`;
        this.setState((state) => ({
            watchList: Array.isArray(state.watchList)
                ? [...state.watchList, value]
                : [value],
        }));
    }
    watchAdd = this.watchAdd.bind(this);
    watchRemove(equipmentId, improvementIndex) {
        if (!Array.isArray(this.state.watchList)) return;
        const value = `${equipmentId}-${improvementIndex}`;
        this.setState((state) => {
            const index = state.watchList.indexOf(value);
            if (index < 0) return {};
            if (state.watchList.length === 1)
                return {
                    watchList: false,
                };
            state.watchList.splice(index, 1);
            return {
                watchList: [...state.watchList],
            };
        });
    }
{'fraction_non_alphanumeric': 0.1673997737840895, 'fraction_numerical': 0.0010054040467512883, 'mean_word_length': 2.3213689482470783, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '3493256', 'n_tokens_mistral': 2217, 'n_tokens_neox': 2135, 'n_words': 464}