<commit_before>import React from 'react';
import { RootState } from '../store/reducers';
import { connect } from 'react-redux';
import { toggleCollapsedSection } from '../settings/actions';
import { Dispatch } from 'redux';
import { AppIcon, expandIcon, collapseIcon } from '../shell/icons';
import classNames from 'classnames';
import '../dim-ui/CollapsibleTitle.scss';
import './InventoryCollapsibleTitle.scss';
import { DimStore } from './store-types';
import { storeBackgroundColor } from '../shell/filters';
import { t } from 'app/i18next-t';
import { postmasterAlmostFull, postmasterSpaceLeft, POSTMASTER_SIZE } from 'app/loadout/postmaster';

interface ProvidedProps {
  sectionId: string;
  title: React.ReactNode;
  children?: React.ReactNode;
  className?: string;
  stores: DimStore[];
}

interface StoreProps {
  collapsed: boolean;
}

interface DispatchProps {
  toggle(): void;
}

function mapStateToProps(state: RootState, props: ProvidedProps): StoreProps {
  return {
    collapsed: state.settings.collapsedSections[props.sectionId]
  };
}

function mapDispatchToProps(dispatch: Dispatch, ownProps: ProvidedProps): DispatchProps {
  return {
    toggle: () => {
      dispatch(toggleCollapsedSection(ownProps.sectionId));
    }
  };
}

type Props = StoreProps & ProvidedProps & DispatchProps;

function InventoryCollapsibleTitle({
  sectionId,
  title,
  collapsed,
  children,
  toggle,
  className,
  stores
}: Props) {
  const checkPostmaster = sectionId === 'Postmaster';

  return (
    <>
      <div
        className={classNames('store-row', 'inventory-title', {
          collapsed
        })}
      >
        {stores.map((store, index) => (
          <div
            key={store.id}
            className={classNames('title', 'store-cell', className, {
              collapsed,
              vault: store.isVault,
              postmasterFull: checkPostmaster && store.isDestiny2() && postmasterAlmostFull(store)
            })}
            style={storeBackgroundColor(store, index)}
          >
            {index === 0 ? (
              <span className="collapse-handle" onClick={toggle}>
                <AppIcon className="collapse-icon" icon={collapsed ? expandIcon : collapseIcon} />{' '}
                <span>
                  {checkPostmaster && store.isDestiny2() && postmasterAlmostFull(store)
                    ? t('ItemService.PostmasterAlmostFull', {
                        number: postmasterSpaceLeft(store),
                        postmasterSize: POSTMASTER_SIZE
                      })
                    : title}
                </span>
              </span>
            ) : (
              checkPostmaster &&
              store.isDestiny2() &&
              postmasterAlmostFull(store) &&
              t('ItemService.PostmasterAlmostFull', {
                number: postmasterSpaceLeft(store),
                postmasterSize: POSTMASTER_SIZE
              })
            )}
          </div>
        ))}
      </div>
      {!collapsed && children}
    </>
  );
}

export default connect<StoreProps, DispatchProps>(
  mapStateToProps,
  mapDispatchToProps
)(InventoryCollapsibleTitle);<commit_msg>Change postmaster warning to show amount occupied, not left<commit_after>import React from 'react';
import { RootState } from '../store/reducers';
import { connect } from 'react-redux';
import { toggleCollapsedSection } from '../settings/actions';
import { Dispatch } from 'redux';
import { AppIcon, expandIcon, collapseIcon } from '../shell/icons';
import classNames from 'classnames';
import '../dim-ui/CollapsibleTitle.scss';
import './InventoryCollapsibleTitle.scss';
import { DimStore } from './store-types';
import { storeBackgroundColor } from '../shell/filters';
import { t } from 'app/i18next-t';
import { postmasterAlmostFull, POSTMASTER_SIZE, postmasterSpaceUsed } from 'app/loadout/postmaster';

interface ProvidedProps {
  sectionId: string;
  title: React.ReactNode;
  children?: React.ReactNode;
  className?: string;
  stores: DimStore[];
}

interface StoreProps {
  collapsed: boolean;
}

interface DispatchProps {
  toggle(): void;
}

function mapStateToProps(state: RootState, props: ProvidedProps): StoreProps {
  return {
    collapsed: state.settings.collapsedSections[props.sectionId]
  };
}

function mapDispatchToProps(dispatch: Dispatch, ownProps: ProvidedProps): DispatchProps {
  return {
    toggle: () => {
      dispatch(toggleCollapsedSection(ownProps.sectionId));
    }
  };
}

type Props = StoreProps & ProvidedProps & DispatchProps;

function InventoryCollapsibleTitle({
  sectionId,
  title,
  collapsed,
  children,
  toggle,
  className,
  stores
}: Props) {
  const checkPostmaster = sectionId === 'Postmaster';

  return (
    <>
      <div
        className={classNames('store-row', 'inventory-title', {
          collapsed
        })}
      >
        {stores.map((store, index) => (
          <div
            key={store.id}
            className={classNames('title', 'store-cell', className, {
              collapsed,
              vault: store.isVault,
              postmasterFull: checkPostmaster && store.isDestiny2() && postmasterAlmostFull(store)
            })}
            style={storeBackgroundColor(store, index)}
          >
            {index === 0 ? (
              <span className="collapse-handle" onClick={toggle}>
                <AppIcon className="collapse-icon" icon={collapsed ? expandIcon : collapseIcon} />{' '}
                <span>
                  {checkPostmaster && store.isDestiny2() && postmasterAlmostFull(store)
                    ? t('ItemService.PostmasterAlmostFull', {
                        number: postmasterSpaceUsed(store),
                        postmasterSize: POSTMASTER_SIZE
                      })
                    : title}
                </span>
              </span>
            ) : (
              checkPostmaster &&
              store.isDestiny2() &&
              postmasterAlmostFull(store) &&
              t('ItemService.PostmasterAlmostFull', {
                number: postmasterSpaceUsed(store),
                postmasterSize: POSTMASTER_SIZE
              })
            )}
          </div>
        ))}
      </div>
      {!collapsed && children}
    </>
  );
}

export default connect<StoreProps, DispatchProps>(
  mapStateToProps,
  mapDispatchToProps
)(InventoryCollapsibleTitle);
{'fraction_non_alphanumeric': 0.12058638083228247, 'fraction_numerical': 0.0018915510718789407, 'mean_word_length': 2.435300487276665, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 31, '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': '7241731', 'n_tokens_mistral': 1771, 'n_tokens_neox': 1734, 'n_words': 349}