Skip to content

Commit

Permalink
refactor: move useStateStore to src/store/hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinCupela committed Sep 11, 2024
1 parent 45c5eb7 commit 401af81
Show file tree
Hide file tree
Showing 15 changed files with 26 additions and 20 deletions.
3 changes: 2 additions & 1 deletion src/components/ChatView/ChatView.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React, { createContext, useContext, useEffect, useMemo, useState } from 'react';

import { ThreadProvider, useStateStore } from '../Threads';
import { ThreadProvider } from '../Threads';
import { Icon } from '../Threads/icons';
import { UnreadCountBadge } from '../Threads/UnreadCountBadge';
import { useChatContext } from '../../context';
import { useStateStore } from '../../store';

import type { PropsWithChildren } from 'react';
import type { Thread, ThreadManagerState } from 'stream-chat';
Expand Down
10 changes: 5 additions & 5 deletions src/components/Message/MessageOptions.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import clsx from 'clsx';
import React from 'react';

import {
Expand All @@ -7,14 +8,13 @@ import {
} from './icons';
import { MESSAGE_ACTIONS } from './utils';
import { MessageActions } from '../MessageActions';
import { useDialogIsOpen } from '../Dialog';
import { ReactionSelectorWithButton } from '../Reactions/ReactionSelectorWithButton';

import { useTranslationContext } from '../../context';
import { MessageContextValue, useMessageContext } from '../../context/MessageContext';
import { useMessageContext, useTranslationContext } from '../../context';

import type { DefaultStreamChatGenerics, IconProps } from '../../types/types';
import { ReactionSelectorWithButton } from '../Reactions/ReactionSelectorWithButton';
import { useDialogIsOpen } from '../Dialog';
import clsx from 'clsx';
import type { MessageContextValue } from '../../context/MessageContext';

export type MessageOptionsProps<
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
Expand Down
14 changes: 8 additions & 6 deletions src/components/Message/__tests__/MessageOptions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@ import { MessageSimple } from '../MessageSimple';
import { ACTIONS_NOT_WORKING_IN_THREAD, MESSAGE_ACTIONS } from '../utils';

import { Attachment } from '../../Attachment';
import { defaultReactionOptions } from '../../Reactions';

import { ChannelActionProvider } from '../../../context/ChannelActionContext';
import { ChannelStateProvider } from '../../../context/ChannelStateContext';
import { ChatProvider } from '../../../context/ChatContext';
import { ComponentProvider } from '../../../context/ComponentContext';
import {
ChannelActionProvider,
ChannelStateProvider,
ChatProvider,
ComponentProvider,
DialogManagerProvider,
} from '../../../context';

import {
generateChannel,
generateMessage,
generateUser,
getTestClientWithUser,
} from '../../../mock-builders';
import { DialogManagerProvider } from '../../../context';
import { defaultReactionOptions } from '../../Reactions';

const MESSAGE_ACTIONS_TEST_ID = 'message-actions';

Expand Down
3 changes: 2 additions & 1 deletion src/components/Thread/Thread.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import {
useChatContext,
useComponentContext,
} from '../../context';
import { useStateStore, useThreadContext } from '../../components/Threads';
import { useThreadContext } from '../Threads';
import { useStateStore } from '../../store';

import type { MessageProps, MessageUIComponentProps } from '../Message/types';
import type { MessageActionsArray } from '../Message/utils';
Expand Down
2 changes: 1 addition & 1 deletion src/components/Threads/ThreadList/ThreadList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ThreadListEmptyPlaceholder as DefaultThreadListEmptyPlaceholder } from
import { ThreadListUnseenThreadsBanner as DefaultThreadListUnseenThreadsBanner } from './ThreadListUnseenThreadsBanner';
import { ThreadListLoadingIndicator as DefaultThreadListLoadingIndicator } from './ThreadListLoadingIndicator';
import { useChatContext, useComponentContext } from '../../../context';
import { useStateStore } from '../hooks/useStateStore';
import { useStateStore } from '../../../store';

const selector = (nextValue: ThreadManagerState) => [nextValue.threads] as const;

Expand Down
2 changes: 1 addition & 1 deletion src/components/Threads/ThreadList/ThreadListItemUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { UnreadCountBadge } from '../UnreadCountBadge';
import { useChatContext } from '../../../context';
import { useThreadsViewContext } from '../../ChatView';
import { useThreadListItemContext } from './ThreadListItem';
import { useStateStore } from '../hooks/useStateStore';
import { useStateStore } from '../../../store';

export type ThreadListItemUIProps = ComponentPropsWithoutRef<'button'>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { ThreadManagerState } from 'stream-chat';

import { LoadingIndicator as DefaultLoadingIndicator } from '../../Loading';
import { useChatContext, useComponentContext } from '../../../context';
import { useStateStore } from '../hooks/useStateStore';
import { useStateStore } from '../../../store';

const selector = (nextValue: ThreadManagerState) => [nextValue.pagination.isLoadingNext];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { ThreadManagerState } from 'stream-chat';

import { Icon } from '../icons';
import { useChatContext } from '../../../context';
import { useStateStore } from '../hooks/useStateStore';
import { useStateStore } from '../../../store';

const selector = (nextValue: ThreadManagerState) => [nextValue.unseenThreadIds] as const;

Expand Down
2 changes: 1 addition & 1 deletion src/components/Threads/hooks/useThreadManagerState.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useChatContext } from 'context';
import { useStateStore } from './useStateStore';
import { ThreadManagerState } from 'stream-chat';
import { useStateStore } from '../../../store';

export const useThreadManagerState = <T extends readonly unknown[]>(
selector: (nextValue: ThreadManagerState) => T,
Expand Down
2 changes: 1 addition & 1 deletion src/components/Threads/hooks/useThreadState.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ThreadState } from 'stream-chat';
import { useStateStore } from './useStateStore';
import { useThreadListItemContext } from '../ThreadList';
import { useThreadContext } from '../ThreadContext';
import { useStateStore } from '../../../store/';

/**
* @description returns thread state, prioritizes `ThreadListItemContext` falls back to `ThreadContext` if not former is not present
Expand Down
1 change: 0 additions & 1 deletion src/components/Threads/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './ThreadContext';
export * from './ThreadList';
export * from './hooks/useStateStore';
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './components';
export * from './context';
export * from './i18n';
export * from './store';
export * from './types';
export * from './utils';
1 change: 1 addition & 0 deletions src/store/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './useStateStore';
File renamed without changes.
1 change: 1 addition & 0 deletions src/store/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './hooks';

0 comments on commit 401af81

Please sign in to comment.