-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
106 changed files
with
1,677 additions
and
2,080 deletions.
There are no files selected for viewing
This file contains 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 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,10 @@ | ||
self.addEventListener('push', (event) => { | ||
const data = event.data | ||
? event.data.json() | ||
: { title: '알림', body: '내용 없음' }; | ||
|
||
self.registration.showNotification(data.title, { | ||
body: data.body, | ||
// icon: 'icon.png', | ||
}); | ||
}); |
This file contains 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 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 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,5 @@ | ||
export * from './schema'; | ||
export * from './useGetAlarm'; | ||
export * from './useGetStockAlarm'; | ||
export * from './usePostCreateAlarm'; | ||
export * from './usePostInitAlarm'; |
This file contains 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,47 @@ | ||
import { z } from 'zod'; | ||
|
||
const KeysSchema = z.object({ | ||
p256dh: z.string(), | ||
auth: z.string(), | ||
}); | ||
|
||
export const PostInitAlarmRequestSchema = z.object({ | ||
endpoint: z.string(), | ||
keys: KeysSchema, | ||
}); | ||
|
||
export type PostInitAlarmRequest = z.infer<typeof PostInitAlarmRequestSchema>; | ||
|
||
export const PostInitAlarmResponseSchema = z.object({ | ||
message: z.string(), | ||
}); | ||
|
||
export type PostInitAlarmResponse = z.infer<typeof PostInitAlarmResponseSchema>; | ||
|
||
export const PostCreateAlarmRequestSchema = z.object({ | ||
stockId: z.string(), | ||
targetPrice: z.number().optional(), | ||
targetVolume: z.number().optional(), | ||
alarmExpiredDate: z.string().datetime().nullish(), | ||
}); | ||
|
||
export type PostCreateAlarmRequest = z.infer< | ||
typeof PostCreateAlarmRequestSchema | ||
>; | ||
|
||
export const AlarmInfoSchema = z.object({ | ||
alarmId: z.number(), | ||
stockId: z.string(), | ||
targetPrice: z.number().nullable(), | ||
targetVolume: z.number().nullable(), | ||
alarmExpiredDate: z.string().datetime().nullable(), | ||
}); | ||
|
||
export const AlarmResponseSchema = z.array(AlarmInfoSchema); | ||
export type AlarmResponse = z.infer<typeof AlarmResponseSchema>; | ||
|
||
export const StockAlarmRequestSchema = z.object({ | ||
stockId: z.string(), | ||
}); | ||
|
||
export type StockAlarmRequest = z.infer<typeof StockAlarmRequestSchema>; |
This file contains 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,18 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { type AlarmResponse, AlarmResponseSchema } from './schema'; | ||
import { get } from '@/apis/utils/get'; | ||
|
||
const getAlarm = () => | ||
get<AlarmResponse>({ | ||
schema: AlarmResponseSchema, | ||
url: '/api/alarm/user', | ||
}); | ||
|
||
export const useGetAlarm = ({ isLoggedIn }: { isLoggedIn: boolean }) => { | ||
return useQuery({ | ||
queryKey: ['getAlarm'], | ||
queryFn: getAlarm, | ||
enabled: isLoggedIn, | ||
staleTime: 1000 * 60 * 5, | ||
}); | ||
}; |
26 changes: 26 additions & 0 deletions
26
packages/frontend/src/apis/queries/alarm/useGetStockAlarm.ts
This file contains 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,26 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { | ||
type AlarmResponse, | ||
StockAlarmRequest, | ||
AlarmResponseSchema, | ||
} from './schema'; | ||
import { get } from '@/apis/utils/get'; | ||
|
||
const getStockAlarm = ({ stockId }: StockAlarmRequest) => | ||
get<AlarmResponse>({ | ||
schema: AlarmResponseSchema, | ||
url: `/api/alarm/stock/${stockId}`, | ||
}); | ||
|
||
export const useGetStockAlarm = ({ | ||
stockId, | ||
isLoggedIn, | ||
}: StockAlarmRequest & { isLoggedIn: boolean }) => { | ||
return useQuery({ | ||
queryKey: ['getStockAlarm', stockId], | ||
queryFn: () => getStockAlarm({ stockId }), | ||
enabled: isLoggedIn, | ||
staleTime: 1000 * 60 * 5, | ||
select: (data) => data.reverse(), | ||
}); | ||
}; |
37 changes: 37 additions & 0 deletions
37
packages/frontend/src/apis/queries/alarm/usePostCreateAlarm.ts
This file contains 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,37 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
import { | ||
type PostCreateAlarmRequest, | ||
type AlarmResponse, | ||
AlarmInfoSchema, | ||
} from './schema'; | ||
import { post } from '@/apis/utils/post'; | ||
|
||
const postCreateAlarm = ({ | ||
stockId, | ||
targetPrice, | ||
targetVolume, | ||
alarmExpiredDate, | ||
}: PostCreateAlarmRequest) => | ||
post<AlarmResponse>({ | ||
params: { stockId, targetPrice, targetVolume, alarmExpiredDate }, | ||
schema: AlarmInfoSchema, | ||
url: '/api/alarm', | ||
}); | ||
|
||
export const usePostCreateAlarm = () => { | ||
const queryClient = useQueryClient(); | ||
return useMutation({ | ||
mutationKey: ['createAlarm'], | ||
mutationFn: ({ | ||
stockId, | ||
targetPrice, | ||
targetVolume, | ||
alarmExpiredDate, | ||
}: PostCreateAlarmRequest) => | ||
postCreateAlarm({ stockId, targetPrice, targetVolume, alarmExpiredDate }), | ||
onSuccess: () => | ||
queryClient.invalidateQueries({ | ||
queryKey: ['getStockAlarm', 'getAlarm'], | ||
}), | ||
}); | ||
}; |
20 changes: 20 additions & 0 deletions
20
packages/frontend/src/apis/queries/alarm/usePostInitAlarm.ts
This file contains 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,20 @@ | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { | ||
type PostInitAlarmResponse, | ||
PostInitAlarmResponseSchema, | ||
} from './schema'; | ||
import { post } from '@/apis/utils/post'; | ||
|
||
const postInitAlarm = (subscription: PushSubscription) => | ||
post<PostInitAlarmResponse>({ | ||
params: subscription, | ||
schema: PostInitAlarmResponseSchema, | ||
url: '/api/push/subscribe', | ||
}); | ||
|
||
export const usePostInitAlarm = () => { | ||
return useMutation({ | ||
mutationKey: ['initAlarm'], | ||
mutationFn: (subscription: PushSubscription) => postInitAlarm(subscription), | ||
}); | ||
}; |
This file contains 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 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 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 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './schema'; | ||
export * from './usePostChatLike'; | ||
export * from './useGetChatList'; |
This file contains 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 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,51 @@ | ||
import { useSuspenseInfiniteQuery } from '@tanstack/react-query'; | ||
import { GetChatListRequest } from './schema'; | ||
import { get } from '@/apis/utils/get'; | ||
import { ChatDataResponse, ChatDataResponseSchema } from '@/sockets/schema'; | ||
|
||
const getChatList = ({ | ||
stockId, | ||
latestChatId, | ||
pageSize, | ||
order, | ||
}: GetChatListRequest) => | ||
get<ChatDataResponse>({ | ||
schema: ChatDataResponseSchema, | ||
url: '/api/chat', | ||
params: { | ||
stockId, | ||
latestChatId, | ||
pageSize, | ||
order, | ||
}, | ||
}); | ||
|
||
export const useGetChatList = ({ | ||
stockId, | ||
latestChatId, | ||
pageSize, | ||
order, | ||
}: GetChatListRequest) => { | ||
return useSuspenseInfiniteQuery({ | ||
queryKey: ['chatList', stockId, order], | ||
queryFn: ({ pageParam }) => | ||
getChatList({ | ||
stockId, | ||
latestChatId: pageParam?.latestChatId, | ||
pageSize, | ||
order, | ||
}), | ||
getNextPageParam: (lastPage) => | ||
lastPage.hasMore | ||
? { | ||
latestChatId: lastPage.chats[lastPage.chats.length - 1].id, | ||
} | ||
: undefined, | ||
initialPageParam: { latestChatId }, | ||
select: (data) => ({ | ||
pages: [...data.pages].flatMap((page) => page.chats), | ||
pageParams: [...data.pageParams], | ||
}), | ||
staleTime: 1000 * 60 * 3, | ||
}); | ||
}; |
Oops, something went wrong.