-
Notifications
You must be signed in to change notification settings - Fork 0
[Feature] sse 연결 시점을 앱 시작 시점으로 변경 및 react-native-svg 라이브러리 업그레이드
#90
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
35ad8f7
refactor: SSE 연결 시점을 "앱 시작"으로 변경
dioo1461 4f9e24b
fix: 그룹 생성 시, 공개 여부가 실제와 반대로 적용되고 있던 문제 수정
dioo1461 baf1e3a
refactor: SSEProvider에서 chatCount를 관리하도록 구조 변경
dioo1461 a2d293a
fix(Windows): react-native-svg 라이브러리를 업그레이드하여 Windows에서의 버벅임 문제 개선
dioo1461 1631f09
refactor: 코드 리뷰 반영
dioo1461 2dd8ab5
chore: tsc incremental 옵션 적용
dioo1461 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import type { PropsWithChildren } from 'react'; | ||
| import { createContext, useCallback, useEffect, useMemo, useRef } from 'react'; | ||
|
|
||
| import { useChatRoomListSse, useSafeContext } from './hooks'; | ||
|
|
||
| type SseStore = { | ||
| getCount: (roomId: string) => number; | ||
| setCount: (roomId: string, count: number) => void; | ||
| inc: (roomId: string) => void; | ||
| subscribe: (listener: () => void) => () => void; | ||
| }; | ||
|
|
||
| const SseContext = createContext<SseStore | null>(null); | ||
|
|
||
| const SSEProvider = ({ children }: PropsWithChildren) => { | ||
| const mapRef = useRef(new Map<string, number>()); | ||
| const listenersRef = useRef(new Set<() => void>()); | ||
|
|
||
| const emit = useCallback(() => { | ||
| listenersRef.current.forEach(cb => { | ||
| cb(); | ||
| }); | ||
| }, []); | ||
|
|
||
| const store = useMemo<SseStore>(() => ({ | ||
| getCount: (roomId) => mapRef.current.get(roomId) ?? 0, | ||
| setCount: (roomId, count) => { | ||
| mapRef.current.set(roomId, count); | ||
| emit(); | ||
| }, | ||
| inc: (roomId) => { | ||
| mapRef.current.set(roomId, (mapRef.current.get(roomId) ?? 0) + 1); | ||
| emit(); | ||
| }, | ||
| subscribe: (listener) => { | ||
| listenersRef.current.add(listener); | ||
| return () => listenersRef.current.delete(listener); | ||
| }, | ||
| }), [emit]); | ||
|
|
||
| useChatRoomListSse({ | ||
| onInitMessage: (payload) => { | ||
| payload.rooms?.forEach(r => { | ||
| const count = Math.max(0, r.unread ?? 0); | ||
| store.setCount(r.roomId, count); | ||
| }); | ||
| }, | ||
| onNewMessage: (payload) => { | ||
| store.inc(payload.roomId); | ||
| }, | ||
| }); | ||
|
|
||
| return <SseContext.Provider value={store}>{children}</SseContext.Provider>; | ||
| }; | ||
|
|
||
| export const useSSEContext = () => useSafeContext(SseContext); | ||
|
|
||
| export default SSEProvider; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { useSyncExternalStore } from 'react'; | ||
|
|
||
| import { useSSEContext } from '@/SSEProvider'; | ||
|
|
||
| export const useChatCount = (roomId: string) => { | ||
| const store = useSSEContext(); | ||
|
|
||
| return useSyncExternalStore( | ||
| store.subscribe, | ||
| () => store.getCount(roomId), | ||
| () => store.getCount(roomId), | ||
| ); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetGroupsResponseexposes bothisOpenandisApprovalRequiredas independent fields (seesrc/features/groups/model/groups.ts), so treatingisPublicas!isApprovalRequiredcan be wrong when a group is publicly searchable but still requires approval. This also makes the list view disagree with the detail view, which still usesparams.isOpen. In those cases, groups will be labeled private in the list even though they are open. Prefer usinggroup.isOpen(or whatever the API contract defines) for public/private status.Useful? React with 👍 / 👎.