<commit_before>import { DateTime, Interval } from "luxon";
import PropTypes from "prop-types";
import React from "react";
import styled from "styled-components";

import style from "@agir/front/genericComponents/_variables.scss";

import { Row } from "@agir/donations/donationForm/AllocationsWidget/Styles";
import { Column } from "@agir/front/genericComponents/grid";
import Card from "@agir/front/genericComponents/Card";
import { LayoutTitle } from "@agir/front/dashboardComponents/Layout";
import Button from "@agir/front/genericComponents/Button";
import EventCard from "@agir/front/genericComponents/EventCard";

import { useGlobalContext } from "@agir/front/genericComponents/GlobalContext";
import { dateFromISOString, displayHumanDay } from "@agir/lib/utils/time";
import FilterTabs from "@agir/front/genericComponents/FilterTabs";
import Onboarding from "@agir/front/genericComponents/Onboarding";

const TopBar = styled.div`
  display: flex;
  flex-flow: row wrap;
  justify-content: space-between;
  margin: 0 0 25px;

  @media (max-width: ${style.collapse}px) {
    margin: 0 0 2rem;
  }

  & > ${LayoutTitle} {
    margin: 0;

    @media (max-width: ${style.collapse}px) {
      flex: 0 0 100%;
      margin-bottom: 1rem;
    }
  }

  & > div {
    display: flex;
    flex-direction: row-reverse;
    align-items: center;

    @media only screen and (max-width: ${style.collapse}px) {
      flex-direction: row;
      margin-left: 1.5rem;
      margin-right: 1.5rem;
    }
  }

  & ${Button} + ${Button} {
    @media only screen and (min-width: ${style.collapse}px) {
      margin-right: 0.5rem;
    }
    @media only screen and (max-width: ${style.collapse}px) {
      margin-left: 0.5rem;
    }
  }
`;

const Day = styled.h3`
  color: ${style.black500};
  text-transform: uppercase;
  font-size: 14px;
  margin-top: 24px;
`;

const EmptyAgenda = styled.div`
  & p {
    strong {
      color: ${style.black1000};
    }
    a {
      font-weight: bold;
      cursor: pointer;
    }
  }
`;

const StyledAgenda = styled.div`
  & header {
    margin-bottom: 0;
  }

  & h2 {
    font-size: 18px;
    font-weight: 500;
  }

  & h2,
  & ${Day}, & ${EmptyAgenda} {
    margin: 2rem 0 1rem;

    @media (max-width: ${style.collapse}px) {
      margin: 2rem 25px 1rem;
    }
  }

  & ${Card} {
    padding-left: 1.5rem;
    padding-right: 1.5rem;
  }

  & ${Card} + ${Card} {
    margin-top: 1rem;
  }
`;

const otherEventConfig = {
  NEAR_TYPE: {
    label: "À proximité",
    allowEmpty: true,
    filter: (events) =>
      events.filter(
        (event) =>
          event.distance &&
          event.distance < 100 * 1000 &&
          !event.rsvp &&
          dateFromISOString(event.endTime) > DateTime.local()
      ),
  },
  GROUPS_TYPE: {
    label: "Dans mes groupes",
    allowEmpty: (user) => Array.isArray(user.groups) && user.groups.length > 0,
    filter: (events, groups) =>
      events.filter(
        (event) =>
          Array.isArray(event.groups) &&
          Array.isArray(groups) &&
          dateFromISOString(event.endTime) > DateTime.local() &&
          event.groups.some((group) => groups.includes(group.id).length > 0)
      ),
  },
  PAST_TYPE: {
    label: "Passés",
    allowEmpty: false,
    filter: (events) =>
      events
        .filter((event) => dateFromISOString(event.endTime) < DateTime.local())
        .reverse(),
  },
  ORGANIZED_TYPE: {
    label: "Organisés",
    allowEmpty: false,
    filter: (events) => events.filter((event) => event.isOrganizer).reverse(),
  },
};

const OtherEvents = ({ others }) => {
  const { routes, user } = useGlobalContext();
  const events = React.useMemo(
    () =>
      others.map((event) => ({
        ...event,
        schedule: Interval.fromDateTimes(
          dateFromISOString(event.startTime),
          dateFromISOString(event.endTime)
        ),
      })),
    [others]
  );
  const byType = React.useMemo(
    () =>
      Object.entries(otherEventConfig).reduce(
        (result, [typeKey, typeConfig]) => ({
          ...result,
          [typeKey]: typeConfig.filter(events, user.groups),
        }),
        {}
      ),
    [events, user.groups]
  );
  const types = React.useMemo(
    () =>
      Object.keys(byType).filter((type) => {
        if (byType[type].length > 0) {
          return true;
        }
        if (typeof otherEventConfig[type].allowEmpty === "function") {
          return otherEventConfig[type].allowEmpty(user);
        }
        return otherEventConfig[type].allowEmpty;
      }),<commit_msg>fix: missing events in person group tab<commit_after>import { DateTime, Interval } from "luxon";
import PropTypes from "prop-types";
import React from "react";
import styled from "styled-components";

import style from "@agir/front/genericComponents/_variables.scss";

import { Row } from "@agir/donations/donationForm/AllocationsWidget/Styles";
import { Column } from "@agir/front/genericComponents/grid";
import Card from "@agir/front/genericComponents/Card";
import { LayoutTitle } from "@agir/front/dashboardComponents/Layout";
import Button from "@agir/front/genericComponents/Button";
import EventCard from "@agir/front/genericComponents/EventCard";

import { useGlobalContext } from "@agir/front/genericComponents/GlobalContext";
import { dateFromISOString, displayHumanDay } from "@agir/lib/utils/time";
import FilterTabs from "@agir/front/genericComponents/FilterTabs";
import Onboarding from "@agir/front/genericComponents/Onboarding";

const TopBar = styled.div`
  display: flex;
  flex-flow: row wrap;
  justify-content: space-between;
  margin: 0 0 25px;

  @media (max-width: ${style.collapse}px) {
    margin: 0 0 2rem;
  }

  & > ${LayoutTitle} {
    margin: 0;

    @media (max-width: ${style.collapse}px) {
      flex: 0 0 100%;
      margin-bottom: 1rem;
    }
  }

  & > div {
    display: flex;
    flex-direction: row-reverse;
    align-items: center;

    @media only screen and (max-width: ${style.collapse}px) {
      flex-direction: row;
      margin-left: 1.5rem;
      margin-right: 1.5rem;
    }
  }

  & ${Button} + ${Button} {
    @media only screen and (min-width: ${style.collapse}px) {
      margin-right: 0.5rem;
    }
    @media only screen and (max-width: ${style.collapse}px) {
      margin-left: 0.5rem;
    }
  }
`;

const Day = styled.h3`
  color: ${style.black500};
  text-transform: uppercase;
  font-size: 14px;
  margin-top: 24px;
`;

const EmptyAgenda = styled.div`
  & p {
    strong {
      color: ${style.black1000};
    }
    a {
      font-weight: bold;
      cursor: pointer;
    }
  }
`;

const StyledAgenda = styled.div`
  & header {
    margin-bottom: 0;
  }

  & h2 {
    font-size: 18px;
    font-weight: 500;
  }

  & h2,
  & ${Day}, & ${EmptyAgenda} {
    margin: 2rem 0 1rem;

    @media (max-width: ${style.collapse}px) {
      margin: 2rem 25px 1rem;
    }
  }

  & ${Card} {
    padding-left: 1.5rem;
    padding-right: 1.5rem;
  }

  & ${Card} + ${Card} {
    margin-top: 1rem;
  }
`;

const otherEventConfig = {
  NEAR_TYPE: {
    label: "À proximité",
    allowEmpty: true,
    filter: (events) =>
      events.filter(
        (event) =>
          event.distance &&
          event.distance < 100 * 1000 &&
          !event.rsvp &&
          dateFromISOString(event.endTime) > DateTime.local()
      ),
  },
  GROUPS_TYPE: {
    label: "Dans mes groupes",
    allowEmpty: (user) => Array.isArray(user.groups) && user.groups.length > 0,
    filter: (events) =>
      events.filter(
        (event) =>
          Array.isArray(event.groups) &&
          dateFromISOString(event.endTime) > DateTime.local() &&
          event.groups.some((group) => !!group.isMember)
      ),
  },
  PAST_TYPE: {
    label: "Passés",
    allowEmpty: false,
    filter: (events) =>
      events
        .filter((event) => dateFromISOString(event.endTime) < DateTime.local())
        .reverse(),
  },
  ORGANIZED_TYPE: {
    label: "Organisés",
    allowEmpty: false,
    filter: (events) => events.filter((event) => event.isOrganizer).reverse(),
  },
};

const OtherEvents = ({ others }) => {
  const { routes, user } = useGlobalContext();
  const events = React.useMemo(
    () =>
      others.map((event) => ({
        ...event,
        schedule: Interval.fromDateTimes(
          dateFromISOString(event.startTime),
          dateFromISOString(event.endTime)
        ),
      })),
    [others]
  );
  const byType = React.useMemo(
    () =>
      Object.entries(otherEventConfig).reduce(
        (result, [typeKey, typeConfig]) => ({
          ...result,
          [typeKey]: typeConfig.filter(events),
        }),
        {}
      ),
    [events]
  );
  const types = React.useMemo(
    () =>
      Object.keys(byType).filter((type) => {
        if (byType[type].length > 0) {
          return true;
        }
        if (typeof otherEventConfig[type].allowEmpty === "function") {
          return otherEventConfig[type].allowEmpty(user);
        }
        return otherEventConfig[type].allowEmpty;
      }),
{'fraction_non_alphanumeric': 0.15197771587743733, 'fraction_numerical': 0.01415041782729805, 'mean_word_length': 2.6266666666666665, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 50, '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': '1777837', 'n_tokens_mistral': 3084, 'n_tokens_neox': 2955, 'n_words': 597}