<commit_before>import {useReducer, useEffect, useCallback, useRef, useContext} from 'react';
import {Routes, Route, Navigate, useParams} from 'react-router-dom';
import {useResource, selectAPINull} from '@xorkevin/substation';
import {useAuthCall, useAuthResource} from '@xorkevin/turbine';
import {
  Grid,
  Column,
  ListGroup,
  ListItem,
  useMenu,
  Menu,
  MenuItem,
  Anchor,
  ButtonGroup,
  FaIcon,
  Time,
} from '@xorkevin/nuke';
import ButtonTertiary from '@xorkevin/nuke/src/component/button/tertiary';
import AnchorText from '@xorkevin/nuke/src/component/anchor/text';

import {GovUICtx} from '../../middleware';
import {formatURL} from '../../utility';

const CHATS_LIMIT = 32;
const CHATS_SCROLL_LIMIT = 16;

const selectAPILatestDMs = (api) => api.conduit.dm;
const selectAPIDMs = (api) => api.conduit.dm.ids;
const selectAPIUsers = (api) => api.u.user.ids;

const SelectAChat = () => {
  return <div>Select a chat</div>;
};

const Chat = ({chatsMap, users, invalidateChat}) => {
  const ctx = useContext(GovUICtx);

  const {chatid} = useParams();
  const chat = chatid ? chatsMap.value.get(chatid) : null;
  const user = chat ? users.value.get(chat.userid) : null;

  useEffect(() => {
    if (chatid) {
      invalidateChat(chatid);
    }
  }, [invalidateChat, chatid]);

  if (!chat) {
    return <div>Chat not found</div>;
  }

  return (
    <div>
      <h5>
        {user && (
          <AnchorText
            local
            href={formatURL(ctx.pathUserProfile, user.username)}
          >
            {user.first_name} {user.last_name}
          </AnchorText>
        )}
      </h5><commit_msg>Use dm chat name<commit_after>import {useReducer, useEffect, useCallback, useRef, useContext} from 'react';
import {Routes, Route, Navigate, useParams} from 'react-router-dom';
import {useResource, selectAPINull} from '@xorkevin/substation';
import {useAuthCall, useAuthResource} from '@xorkevin/turbine';
import {
  Grid,
  Column,
  ListGroup,
  ListItem,
  useMenu,
  Menu,
  MenuItem,
  Anchor,
  ButtonGroup,
  FaIcon,
  Time,
} from '@xorkevin/nuke';
import ButtonTertiary from '@xorkevin/nuke/src/component/button/tertiary';
import AnchorText from '@xorkevin/nuke/src/component/anchor/text';

import {GovUICtx} from '../../middleware';
import {formatURL} from '../../utility';

const CHATS_LIMIT = 32;
const CHATS_SCROLL_LIMIT = 16;

const selectAPILatestDMs = (api) => api.conduit.dm;
const selectAPIDMs = (api) => api.conduit.dm.ids;
const selectAPIUsers = (api) => api.u.user.ids;

const SelectAChat = () => {
  return <div>Select a chat</div>;
};

const Chat = ({chatsMap, users, invalidateChat}) => {
  const ctx = useContext(GovUICtx);

  const {chatid} = useParams();
  const chat = chatid ? chatsMap.value.get(chatid) : null;
  const user = chat ? users.value.get(chat.userid) : null;

  useEffect(() => {
    if (chatid) {
      invalidateChat(chatid);
    }
  }, [invalidateChat, chatid]);

  return (
    <div>
      <h5>
        {user ? (
          <AnchorText
            local
            href={formatURL(ctx.pathUserProfile, user.username)}
          >
            {chat.name || `${user.first_name} ${user.last_name}`}
          </AnchorText>
        ) : (
          chat && chat.name
        )}
      </h5>
{'fraction_non_alphanumeric': 0.14909314478942515, 'fraction_numerical': 0.0036889025514909315, 'mean_word_length': 3.248041775456919, 'pattern_counts': {'":': 0, '<': 19, '<?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': '3685353', 'n_tokens_mistral': 1167, 'n_tokens_neox': 1132, 'n_words': 247}