<commit_before>import { observable } from 'mobx';

import { HistoryItem, HistorySection, Dictionary } from '~/interfaces';
import { formatDate } from '~/utils/time';

export class Store {
  @observable
  public loading = true;

  @observable
  public dictionary: Dictionary;

  @observable
  public historyItems: HistoryItem[] = [];

  @observable
  public historySections: HistorySection[] = [
    {
      date: new Date().toString(),
      id: '0wrwa',
      items: [],
    },
  ];

  public loadedCount = 0;

  public filterItems(filter = '') {
    this.historyItems = this.historyItems
      .filter(
        item =>
          item.title.toLowerCase().indexOf(filter.toLowerCase()) !== -1 ||
          item.url.toLowerCase().indexOf(filter.toLowerCase()) !== -1,
      )
      .reverse();
  }

  public loadSections(count: number) {
    const section = this.historySections[0];

    for (let i = this.loadedCount; i < count + this.loadedCount; i++) {
      if (i < this.historyItems.length) {
        section.items.push(this.historyItems[i]);
      }
    }

    this.loadedCount += count;
  }
}<commit_msg>Improve history<commit_after>import { observable } from 'mobx';

import { HistoryItem, HistorySection, Dictionary } from '~/interfaces';
import { formatDate } from '~/utils/time';

export class Store {
  @observable
  public loading = true;

  @observable
  public dictionary: Dictionary;

  @observable
  public historyItems: HistoryItem[] = [];

  @observable
  public historySections: HistorySection[] = [];

  public loadedCount = 0;

  public filterItems(filter = '') {
    this.historyItems = this.historyItems
      .filter(
        item =>
          item.title.toLowerCase().indexOf(filter.toLowerCase()) !== -1 ||
          item.url.toLowerCase().indexOf(filter.toLowerCase()) !== -1,
      )
      .reverse();
  }

  public loadSections(count: number) {
    for (let i = this.loadedCount; i < count + this.loadedCount; i++) {
      if (i < this.historyItems.length) {
        const item = this.historyItems[i];
        const date = new Date(item.date);

        const dateStr = formatDate(this.dictionary, date);

        const foundSection = this.historySections.find(x => x.date === dateStr);

        const newItem = {
          ...item,
          favicon: '', // store.faviconsStore.favicons[item.favicon]
          selected: false,
        };

        if (foundSection == null) {
          const section: HistorySection = {
            items: [newItem],
            date: dateStr,
            id: item._id,
          };

          this.historySections.push(section);
        } else {
          foundSection.items.push(newItem);
        }
      }
    }

    this.loadedCount += count;
  }
}
{'fraction_non_alphanumeric': 0.13706705969049374, 'fraction_numerical': 0.0029476787030213707, 'mean_word_length': 2.4897172236503855, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 6, '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': '4536257', 'n_tokens_mistral': 809, 'n_tokens_neox': 790, 'n_words': 175}