<commit_before>// @flow
import * as ICONS from 'constants/icons';
import React from 'react';
import Page from 'component/page';
import Card from 'component/common/card';
import Spinner from 'component/spinner';
import Notification from 'component/notification';
import Button from 'component/button';
import Yrbl from 'component/yrbl';
import usePrevious from 'effects/use-previous';

type Props = {
  notifications: Array<Notification>,
  fetching: boolean,
  unreadCount: number,
  unseenCount: number,
  doSeeAllNotifications: () => void,
  doReadNotifications: () => void,
};

export default function NotificationsPage(props: Props) {
  const { notifications, fetching, unreadCount, unseenCount, doSeeAllNotifications, doReadNotifications } = props;
  const [hasFetched, setHasFetched] = React.useState(false);
  const previousFetching = usePrevious(fetching);
  const hasNotifications = notifications.length > 0;

  React.useEffect(() => {
    if (unreadCount > 0) {
      doReadNotifications();
    }
  }, [unreadCount, doReadNotifications]);

  React.useEffect(() => {
    if ((fetching === false && previousFetching === true) || hasNotifications) {
      setHasFetched(true);
    }
  }, [fetching, previousFetching, setHasFetched, hasNotifications]);

  return (
    <Page>
      {fetching && !hasNotifications && (
        <div className="main--empty">
          <Spinner delayed />
        </div>
      )}
      {hasFetched && (
        <>
          {notifications && notifications.length > 0 ? (
            <Card
              isBodyList
              title={
                <span>
                  {__('Notifications')}
                  {fetching && <Spinner type="small" />}
                </span>
              }
              titleActions={
                unseenCount > 0 && (
                  <Button
                    icon={ICONS.EYE}
                    onClick={doSeeAllNotifications}
                    button="secondary"
                    label={__('Mark all as read')}<commit_msg>make sure notifications aren't hidden<commit_after>// @flow
import * as ICONS from 'constants/icons';
import React from 'react';
import Page from 'component/page';
import Card from 'component/common/card';
import Spinner from 'component/spinner';
import Notification from 'component/notification';
import Button from 'component/button';
import Yrbl from 'component/yrbl';

type Props = {
  notifications: Array<Notification>,
  fetching: boolean,
  unreadCount: number,
  unseenCount: number,
  doSeeAllNotifications: () => void,
  doReadNotifications: () => void,
};

export default function NotificationsPage(props: Props) {
  const { notifications, fetching, unreadCount, unseenCount, doSeeAllNotifications, doReadNotifications } = props;
  const hasNotifications = notifications.length > 0;

  React.useEffect(() => {
    if (unreadCount > 0) {
      doReadNotifications();
    }
  }, [unreadCount, doReadNotifications]);

  return (
    <Page>
      {fetching && !hasNotifications && (
        <div className="main--empty">
          <Spinner delayed />
        </div>
      )}
      {!fetching && (
        <>
          {notifications && notifications.length > 0 ? (
            <Card
              isBodyList
              title={
                <span>
                  {__('Notifications')}
                  {fetching && <Spinner type="small" />}
                </span>
              }
              titleActions={
                unseenCount > 0 && (
                  <Button
                    icon={ICONS.EYE}
                    onClick={doSeeAllNotifications}
                    button="secondary"
                    label={__('Mark all as read')}
{'fraction_non_alphanumeric': 0.11841390548614883, 'fraction_numerical': 0.0021727322107550242, 'mean_word_length': 2.3300180831826403, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 36, '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': '5425646', 'n_tokens_mistral': 1037, 'n_tokens_neox': 994, 'n_words': 238}