-
Notifications
You must be signed in to change notification settings - Fork 1
Feature: 메모 선택 #113
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
Feature: 메모 선택 #113
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
e465ff1
feat: 메모 선택 구현
guesung 5f245b4
feat: exc 누를 시 선택 모드 종료
guesung ca5f850
feat: 선택 시 상단에 옵션이 뜨기
guesung eaf1abd
feat: 여러 개의 데이터를 한 번에 수정
guesung c358660
feat: 여러 개의 값을 수정할 수 있는 `useMemosUpsertMutation` 훅 구현
guesung f133e6d
feat: 선택한 요소에 대해 일괄 수정
guesung 4e99534
feat: 카테고리 업데이트의 낙관적 업데이트
guesung a258d94
chore: supabaseClient를 인자로 전달
guesung 73074e3
fix: 메모 제거 후 낙관적 업데이트 수행
guesung 29367ef
feat: 키보드 단축키 추가
guesung 0353937
refactor: 변수화 및 최적화
guesung 6fcc79c
fix: 타입 이슈 해결
guesung 94e10ec
feat: 아이템 카테고리 변경 시 옵션 모드 종료
guesung 63504c5
design: 다크 모드 지원
guesung ebac4ea
feat: 애니메이션
guesung 4f182ff
chore: 필요한 경우가 아니라면 push로 이동
guesung c552d6e
feat: transition 모듈화
guesung 113861b
fix: 빌드 이슈 해결
guesung 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
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,8 @@ | ||
export const MOTION_VARIANTS = { | ||
fadeInAndOut: { | ||
initial: { opacity: 0, y: 10 }, | ||
animate: { opacity: 1, y: 0 }, | ||
transition: { duration: 0.3 }, | ||
exit: { opacity: 0, y: 10 }, | ||
}, | ||
}; |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
export * from './supabase'; | ||
export { default as useCloseOnEscape } from './useCloseOnEscape'; | ||
export { default as useDidMount } from './useDidMount'; | ||
export { default as useError } from './useError'; | ||
export { default as useFetch } from './useFetch'; | ||
export { default as useKeyboardBind } from './useKeyboardBind'; | ||
export { default as useThrottle } from './useThrottle'; | ||
export { default as useUserPreferDarkMode } from './useUserPreferDarkMode'; |
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
44 changes: 44 additions & 0 deletions
44
packages/shared/src/hooks/supabase/useMemosUpsertMutation.ts
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,44 @@ | ||
import { NoMemosError, QUERY_KEY } from '@src/constants'; | ||
import { MemoRow, MemoSupabaseClient, MemoSupabaseResponse, MemoTable } from '@src/types'; | ||
import { upsertMemos } from '@src/utils'; | ||
import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'; | ||
|
||
type MutationVariables = MemoTable['Insert'][]; | ||
type MutationData = Awaited<ReturnType<typeof upsertMemos>>; | ||
type MutationError = Error; | ||
|
||
interface UseMemosUpsertMutationProps extends UseMutationOptions<MutationData, MutationError, MutationVariables> { | ||
supabaseClient: MemoSupabaseClient; | ||
} | ||
|
||
export default function useMemosUpsertMutation({ supabaseClient, ...useMutationProps }: UseMemosUpsertMutationProps) { | ||
const queryClient = useQueryClient(); | ||
return useMutation<MutationData, MutationError, MutationVariables>({ | ||
...useMutationProps, | ||
mutationFn: async memoRequest => await upsertMemos(supabaseClient, memoRequest), | ||
onMutate: async memoRequest => { | ||
await queryClient.cancelQueries({ queryKey: QUERY_KEY.memos() }); | ||
const previousMemos = queryClient.getQueryData<MemoSupabaseResponse>(QUERY_KEY.memos()); | ||
|
||
if (!previousMemos) throw new NoMemosError(); | ||
|
||
const { data: previousMemosData } = previousMemos; | ||
|
||
if (!previousMemosData) throw new NoMemosError(); | ||
|
||
const updatedMemosData = [...previousMemosData]; | ||
|
||
memoRequest.forEach(memo => { | ||
const currentMemoIndex = updatedMemosData.findIndex(previousMemo => previousMemo.id === memo.id); | ||
const currentMemoBase = updatedMemosData.find(previousMemo => previousMemo.id === memo.id); | ||
|
||
if (currentMemoIndex === -1 || !currentMemoBase) updatedMemosData.unshift(memo as MemoRow); | ||
else updatedMemosData.splice(currentMemoIndex, 1, { ...currentMemoBase, ...memo }); | ||
}); | ||
|
||
await queryClient.setQueryData(QUERY_KEY.memos(), { ...previousMemos, data: updatedMemosData }); | ||
|
||
return { previousMemos }; | ||
}, | ||
}); | ||
} |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { useEffect } from 'react'; | ||
|
||
type KeyboardEventKey = 'Backspace' | 'Escape'; | ||
|
||
interface UseKeyboardBindProps { | ||
key: KeyboardEventKey; | ||
callback: () => void; | ||
} | ||
|
||
export default function useKeyboardBind({ key, callback }: UseKeyboardBindProps) { | ||
useEffect(() => { | ||
const handleKeyDown = (event: KeyboardEvent) => { | ||
if (event.key === key) callback(); | ||
}; | ||
|
||
window.addEventListener('keydown', handleKeyDown); | ||
return () => window.removeEventListener('keydown', handleKeyDown); | ||
}, [key, callback]); | ||
} |
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 @@ | ||
export const isAllSame = (array: unknown[]) => new Set(array).size === 1; |
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
23 changes: 20 additions & 3 deletions
23
packages/web/src/app/[lng]/memos/components/MemoCardHeader/index.tsx
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.