<commit_before>import * as React from 'react';
import { connect } from 'react-redux';

import Album from '../../models/Album';
import TileItem from '../../models/TileItem';
import { State } from '../../modules';
import AppBar from '../AppBar';

import preloadMedia from '../../helpers/preloadMedia';
import AlbumGrid from './AlbumGrid';
import './index.css';
import TextContent from './TextContent';
import Subalbum from '../../models/Subalbum';
import { NamespacesConsumer } from 'react-i18next';


interface AlbumViewProps {
  album: Album;
}


interface Year {
  year: string | null;
  subalbums: Subalbum[];
}

function groupAlbumsByYear(subalbums: Subalbum[]): Year[] {
  let currentYear: Year | null = null;
  const years: Year[] = [];

  subalbums.forEach((subalbum) => {
    const year = subalbum.date ? subalbum.date.split('-')[0] : null;

    if (!currentYear || currentYear.year !== year) {
      currentYear = { year, subalbums: [] };
      years.push(currentYear);
    }

    currentYear.subalbums.push(subalbum);
  });

  return years;
}


class AlbumView extends React.PureComponent<AlbumViewProps, {}> {
  render() {
    const { album } = this.props;

    return (
      <NamespacesConsumer ns={['AlbumView']}>
        {(t) => (
          <div>
            <AppBar />

            {album.body ? <TextContent content={album.body} /> : null}

            {/* Subalbums */}
            { album.layout == 'yearly' ? (
              <div className='YearlyView'>
                {groupAlbumsByYear(album.subalbums).map(({ year, subalbums }) => {
                  return (
                    <div>
                      <h2>{year ? year : t('unknownYear')}</h2>
                      <AlbumGrid tiles={subalbums} getTitle={(tile: TileItem) => tile.title} />
                    </div>
                  );
                })}
              </div>
            ) : (
              <AlbumGrid tiles={album.subalbums} getTitle={(tile: TileItem) => tile.title} />
            )}

            {/* Pictures */}
            <AlbumGrid tiles={album.pictures} getTitle={(tile: TileItem) => ""} /><commit_msg>frontend/AlbumView: fix missing key on years<commit_after>import * as React from 'react';
import { connect } from 'react-redux';

import Album from '../../models/Album';
import TileItem from '../../models/TileItem';
import { State } from '../../modules';
import AppBar from '../AppBar';

import preloadMedia from '../../helpers/preloadMedia';
import AlbumGrid from './AlbumGrid';
import './index.css';
import TextContent from './TextContent';
import Subalbum from '../../models/Subalbum';
import { NamespacesConsumer } from 'react-i18next';


interface AlbumViewProps {
  album: Album;
}


interface Year {
  year: string | null;
  subalbums: Subalbum[];
}

function groupAlbumsByYear(subalbums: Subalbum[]): Year[] {
  let currentYear: Year | null = null;
  const years: Year[] = [];

  subalbums.forEach((subalbum) => {
    const year = subalbum.date ? subalbum.date.split('-')[0] : null;

    if (!currentYear || currentYear.year !== year) {
      currentYear = { year, subalbums: [] };
      years.push(currentYear);
    }

    currentYear.subalbums.push(subalbum);
  });

  return years;
}


class AlbumView extends React.PureComponent<AlbumViewProps, {}> {
  render() {
    const { album } = this.props;

    return (
      <NamespacesConsumer ns={['AlbumView']}>
        {(t) => (
          <div>
            <AppBar />

            {album.body ? <TextContent content={album.body} /> : null}

            {/* Subalbums */}
            { album.layout == 'yearly' ? (
              <div className='YearlyView'>
                {groupAlbumsByYear(album.subalbums).map(({ year, subalbums }) => {
                  return (
                    <div key={year ? year : 'unknownYear'}>
                      <h2>{year ? year : t('unknownYear')}</h2>
                      <AlbumGrid tiles={subalbums} getTitle={(tile: TileItem) => tile.title} />
                    </div>
                  );
                })}
              </div>
            ) : (
              <AlbumGrid tiles={album.subalbums} getTitle={(tile: TileItem) => tile.title} />
            )}

            {/* Pictures */}
            <AlbumGrid tiles={album.pictures} getTitle={(tile: TileItem) => ""} />
{'fraction_non_alphanumeric': 0.16367032453887462, 'fraction_numerical': 0.0023348120476301658, 'mean_word_length': 2.1733333333333333, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 43, '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': '2639704', 'n_tokens_mistral': 1298, 'n_tokens_neox': 1245, 'n_words': 278}