Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLNP-5046] Migrate ThreadProvider to the new state management pattern #1250

Open
wants to merge 3 commits into
base: feat/state-mgmt-migration-1
Choose a base branch
from

Conversation

git-babel
Copy link
Contributor

@git-babel git-babel commented Nov 12, 2024

Overview

This PR migrate ThreadProvider and related files to the new state management pattern.

Changelog

  • ThreadProvider is migrated, and useThread() hook is introduced.
  • Removed ThreadDispatcher usages in ThreadProvider; it is replaced with the new state-action pattern of useThread().
  • PubSub of config still remains. It is out of scope of this PR.

Remaining tasks

  • Add unit tests and integration tests.

FurtherConcern

  • Handling hook
    • The previous ThreadProvider contained several custom hooks. Those hooks retrieved state and actions through useThreadContext()
    • Due to that, replacing useThreadContext() to new useThread() faced a problem. Those hooks �conatin useThread(), useThread() contains the hooks. So it makes cycle.
    • For now, I moved all functionality of the hooks to the useThread(), but it looks wrong. Any good way to handle this?

Copy link

netlify bot commented Nov 12, 2024

Deploy Preview for sendbird-uikit-react ready!

Name Link
🔨 Latest commit b11d66c
🔍 Latest deploy log https://app.netlify.com/sites/sendbird-uikit-react/deploys/6732e2b5d0f902000835a547
😎 Deploy Preview https://deploy-preview-1250--sendbird-uikit-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

} = threadContext;
const messageInputRef = useRef();

const isMentionEnabled = groupChannel.enableMention;
const isVoiceMessageEnabled = groupChannel.enableVoiceMessage;
const isMultipleFilesMessageEnabled = threadContext.isMultipleFilesMessageEnabled ?? config.isMultipleFilesMessageEnabled;
const isMultipleFilesMessageEnabled = threadContext.state.isMultipleFilesMessageEnabled ?? config.isMultipleFilesMessageEnabled;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요거도 위에 threadContext breakdown 할때 빼서 넣으면 더 좋지 않을까 생각해봤습니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

대단한 이유는 아닌데, isMultipleFilesMessageEnabled의 네이밍이 겹쳐서 이렇게 하긴 했습니다.

type: ThreadContextActionTypes.GET_CHANNEL_FAILURE,
payload: error,
});
getChannelFailure();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기 실패한 에러를 같이 주는건 어떤가요?

type: ThreadContextActionTypes.GET_PARENT_MESSAGE_FAILURE,
payload: error,
});
getParentMessageFailure();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기도 에러 같이주면 좋을것 같습니다.

type: ThreadContextActionTypes.GET_CHANNEL_FAILURE,
payload: error,
});
getChannelFailure();
});
}
}, [message, sdkInit]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기 message가 아니라 channelUrl을 주는게 더 나을것같은데 어떻게 생각하시나요?

url: URL.createObjectURL(file),
// pending thumbnail message seems to be failed
// @ts-ignore
requestState: 'pending',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

제 기억으로는 requestState는 deprecated 되었고 sendingStatus가 대체한것같아서 확인 후 맞는걸 사용하도록 바꾸는게 좋지 않을까 생각해봤습니다.

url: URL.createObjectURL(file),
// pending thumbnail message seems to be failed
// @ts-ignore
requestState: 'pending',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기두요!


const toggleReaction = useToggleReactionCallback({ currentChannel }, { logger });

const sendMessage = useCallback((props: SendMessageParams) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기서 useSendMessageCallback 류의 hook들을 사용하지 않은 이유도 궁금합니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 관해서 저희가 내부적으로도 이야기를 한 적이 있습니다. 처음에는 가능한 기존에 사용하던 use~~ �훅을 여기서도 사용하려고 했는데 문제가 조금 있습니다.
일단 579 line의 useMemo()를 기준으로 useMemo() 위에서 �을 사용할 경우 use~~ 훅에서 useThread()를 사용하기 때문에 cycle이 생겨서 훅을 사용할 수 없습니다.
반대로 useMemo() 안에서 훅을 사용할 경우 useMemo 안에서 또다시 훅을 사용하는 케이스가 되므로 리액트 에러가 발생합니다.
이러한 문제들 때문에 기존의 use~~ 훅들의 content를 useThread() 내에 풀어서 옮겨놓았습니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants