Skip to content

Commit

Permalink
fix: api 변경 + usePreviousPath hook 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
rabyeoljji committed Dec 11, 2024
1 parent b1c21d9 commit 6f99eb6
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 22 deletions.
12 changes: 12 additions & 0 deletions src/features/document/components/document-type-icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ const DocumentTypeIcon = ({ type, containerClassName, iconClassName }: Props) =>
</div>
)
}

// default
return (
<div
className={cn(
'flex-center size-[36px] shrink-0 rounded-full bg-fill-secondary-orange text-text-primary-inverse',
containerClassName
)}
>
<Icon name="document" className={cn('size-[16px]', iconClassName)} />
</div>
)
}

export default DocumentTypeIcon
2 changes: 0 additions & 2 deletions src/features/search/components/recent-searches.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ const RecentSearches = ({ containerRef, onUpdateKeyword }: Props) => {

useEffect(() => {
const storageSearches = getLocalStorage<string[]>(RECENT_SEARCHES) ?? []
// eslint-disable-next-line no-console
console.log(storageSearches)
setRecentSearches(storageSearches)
}, [])

Expand Down
8 changes: 6 additions & 2 deletions src/features/search/components/search-item/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import Tag from '@/shared/components/ui/tag'
import Text from '@/shared/components/ui/text'
import { cn } from '@/shared/lib/utils'
import DocumentTypeIcon from '@/features/document/components/document-type-icon'
import Link from 'next/link'

interface Props {
documentId: number | undefined // api 수정되면 undefined 제거
createType: Document.ItemInList['documentType']
documentTitle: React.ReactNode
matchingSentence: React.ReactNode
Expand All @@ -14,6 +16,7 @@ interface Props {
}

const SearchItem = ({
documentId,
createType,
documentTitle,
matchingSentence,
Expand All @@ -22,7 +25,8 @@ const SearchItem = ({
lastItem,
}: Props) => {
return (
<div
<Link
href={documentId ? '/document/' + documentId : '#'}
className={cn(
'border-b border-border-divider py-[24px] flex flex-col',
lastItem && 'border-none'
Expand All @@ -49,7 +53,7 @@ const SearchItem = ({
<Text>{relativeDirectory}</Text>
</div>
</div>
</div>
</Link>
)
}

Expand Down
2 changes: 1 addition & 1 deletion src/features/search/components/search-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { PropsWithChildren } from 'react'

const SearchList = ({ length, children }: PropsWithChildren & { length: number }) => {
return (
<div className="h-[calc(100dvh-88px-56px)] overflow-y-auto p-[16px] text-text1-medium">
<div className="h-[calc(100dvh-56px)] overflow-y-auto p-[16px] text-text1-medium">
<Text>
퀴즈 노트 <span className="text-text-accent">{length}</span>
</Text>
Expand Down
12 changes: 8 additions & 4 deletions src/features/search/screen/search-in-document.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'

import { useEffect, useRef, useState } from 'react'
import { ChangeEvent, useEffect, useRef, useState } from 'react'
import SearchList from '../components/search-list'
import SearchItem from '../components/search-item'
import RecentSearches from '../components/recent-searches'
Expand All @@ -13,9 +13,12 @@ import { queries } from '@/shared/lib/tanstack-query/query-keys'
import Loading from '@/shared/components/custom/loading'
import { RECENT_SEARCHES } from '../config'
import { getLocalStorage, setLocalStorage } from '@/shared/utils/storage'
import usePreviousPath from '@/shared/hooks/use-previous-path'

// 퀴즈노트 탭 내 검색창 화면
const SearchInDocument = () => {
usePreviousPath()

const router = useRouter()
const searchParams = useSearchParams()
const initialKeyword = searchParams.get('keyword') || ''
Expand Down Expand Up @@ -89,7 +92,7 @@ const SearchInDocument = () => {
<div>
<HeaderInDocument
inputValue={keyword}
onChangeInputValue={(e) => setKeyword(e.target.value)}
onChangeInputValue={(e: ChangeEvent<HTMLInputElement>) => setKeyword(e.target.value)}
onDeleteKeyword={handleDeleteKeyword}
onSubmit={handleSubmit}
searchInputRef={searchInputRef}
Expand All @@ -108,7 +111,7 @@ const SearchInDocument = () => {
{!isSearchFocused &&
// 검색 결과 X
(!data || searchResults.length === 0 ? (
<div className="flex-center h-[calc(100dvh-88px-56px)] flex-col">
<div className="flex-center h-[calc(100dvh-56px)] flex-col">
<Text typography="subtitle1-bold">검색결과가 없습니다</Text>
<Text typography="text1-medium" className="text-text-sub">
다른 키워드를 입력해보세요
Expand All @@ -122,7 +125,8 @@ const SearchInDocument = () => {
{searchResults.map((searchItem, idx) => (
<SearchItem
key={idx}
createType={idx % 2 === 0 ? 'FILE' : 'TEXT'} // type 들어가야함
documentId={searchItem.documentId}
createType={searchItem.documentType as Document.Type}
documentTitle={highlightAndTrimText(
searchItem.documentName ?? '',
initialKeyword ?? ''
Expand Down
10 changes: 7 additions & 3 deletions src/shared/hooks/use-previous-path.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useCallback } from 'react'
import { usePathname } from 'next/navigation'
import { usePathname, useSearchParams } from 'next/navigation'

const PREVIOUS_PATH_KEY = 'previousPath'

Expand All @@ -10,6 +10,7 @@ interface UsePreviousPath {

const usePreviousPath = ({ getCustomPath } = { getCustomPath: false }): UsePreviousPath => {
const pathname = usePathname()
const searchParams = useSearchParams()

// 이전 경로 가져오기
const getPreviousPath = useCallback((): string | null => {
Expand All @@ -25,12 +26,15 @@ const usePreviousPath = ({ getCustomPath } = { getCustomPath: false }): UsePrevi
useEffect(() => {
const setPreviousPath = () => {
if (pathname && !getCustomPath) {
sessionStorage.setItem(PREVIOUS_PATH_KEY, pathname)
const fullPath = searchParams?.toString()
? `${pathname}?${searchParams.toString()}`
: pathname
sessionStorage.setItem(PREVIOUS_PATH_KEY, fullPath)
}
}

return () => setPreviousPath()
}, [pathname, getCustomPath])
}, [pathname, getCustomPath, searchParams])

return { getPreviousPath, setPreviousPath }
}
Expand Down
5 changes: 4 additions & 1 deletion src/types/document.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ declare global {
type Sort = 'CREATED_AT' | 'UPDATED_AT'

type Status = DeepRequired<components['schemas']['GetAllDocumentsDocumentDto']['status']>
type Type = DeepRequired<components['schemas']['GetAllDocumentsDocumentDto']['documentType']>
type Type = Exclude<
DeepRequired<components['schemas']['GetAllDocumentsDocumentDto']['documentType']>,
undefined
>

type SearchedDocument = DeepRequired<components['schemas']['IntegratedSearchDocumentDto']>

Expand Down
101 changes: 92 additions & 9 deletions src/types/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,23 @@ export interface paths {
patch?: never;
trace?: never;
};
"/api/v2/documents/{document_id}/add-quizzes": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
get?: never;
put?: never;
/** 문서에서 추가 퀴즈 생성 */
post: operations["createQuizzes"];
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/api/v2/documents/search": {
parameters: {
query?: never;
Expand Down Expand Up @@ -716,7 +733,7 @@ export interface paths {
cookie?: never;
};
/** quiz_set_id와 quiz-set-type으로 퀴즈 가져오기 */
get: operations["getQuizSetByCollection"];
get: operations["getQuizSet"];
put?: never;
post?: never;
delete?: never;
Expand Down Expand Up @@ -876,6 +893,23 @@ export interface paths {
patch?: never;
trace?: never;
};
"/api/v2/members/reward": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
/** 초대 링크 보상 확인? */
get: operations["getInviteLinkMember"];
put?: never;
post?: never;
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/api/v2/members/info": {
parameters: {
query?: never;
Expand Down Expand Up @@ -1334,8 +1368,7 @@ export interface components {
createdAt?: string;
};
CreateQuizzesByDocumentRequest: {
/** @enum {string} */
quizType?: "MIX_UP" | "MULTIPLE_CHOICE";
quizType?: string;
/** Format: int32 */
quizCount?: number;
};
Expand Down Expand Up @@ -1398,6 +1431,8 @@ export interface components {
documentId?: number;
documentName?: string;
content?: string;
/** @enum {string} */
documentType?: "FILE" | "TEXT" | "NOTION";
directory?: components["schemas"]["IntegratedSearchDirectoryDto"];
};
IntegratedSearchQuizDto: {
Expand Down Expand Up @@ -1436,6 +1471,12 @@ export interface components {
/** Format: int64 */
id?: number;
};
CreateQuizzesRequest: {
/** Format: int32 */
star?: number;
/** @enum {string} */
quizType?: "MIX_UP" | "MULTIPLE_CHOICE";
};
SearchDocumentDirectoryDto: {
/** Format: int64 */
id?: number;
Expand All @@ -1446,6 +1487,8 @@ export interface components {
documentId?: number;
documentName?: string;
content?: string;
/** @enum {string} */
documentType?: "FILE" | "TEXT" | "NOTION";
directory?: components["schemas"]["SearchDocumentDirectoryDto"];
};
SearchDocumentQuizDto: {
Expand Down Expand Up @@ -1653,7 +1696,6 @@ export interface components {
};
GetQuizSetResponse: {
quizzes?: components["schemas"]["GetQuizSetQuizDto"][];
collectionName?: string;
};
GetQuizSetTodayResponse: {
quizSetId?: string;
Expand Down Expand Up @@ -1681,10 +1723,10 @@ export interface components {
parent?: components["schemas"]["ApplicationContext"];
id?: string;
displayName?: string;
autowireCapableBeanFactory?: components["schemas"]["AutowireCapableBeanFactory"];
applicationName?: string;
/** Format: int64 */
startupDate?: number;
autowireCapableBeanFactory?: components["schemas"]["AutowireCapableBeanFactory"];
environment?: components["schemas"]["Environment"];
/** Format: int32 */
beanDefinitionCount?: number;
Expand Down Expand Up @@ -1850,13 +1892,13 @@ export interface components {
hosts?: string[];
redirectView?: boolean;
propagateQueryProperties?: boolean;
attributesCSV?: string;
attributesMap?: {
[key: string]: Record<string, never>;
};
attributes?: {
[key: string]: string;
};
attributesCSV?: string;
};
ServletContext: {
sessionCookieConfig?: components["schemas"]["SessionCookieConfig"];
Expand Down Expand Up @@ -1891,7 +1933,6 @@ export interface components {
servletRegistrations?: {
[key: string]: components["schemas"]["ServletRegistration"];
};
defaultSessionTrackingModes?: ("COOKIE" | "URL" | "SSL")[];
/** Format: int32 */
effectiveMajorVersion?: number;
/** Format: int32 */
Expand All @@ -1901,6 +1942,7 @@ export interface components {
filterRegistrations?: {
[key: string]: components["schemas"]["FilterRegistration"];
};
defaultSessionTrackingModes?: ("COOKIE" | "URL" | "SSL")[];
effectiveSessionTrackingModes?: ("COOKIE" | "URL" | "SSL")[];
jspConfigDescriptor?: components["schemas"]["JspConfigDescriptor"];
requestCharacterEncoding?: string;
Expand Down Expand Up @@ -2603,6 +2645,30 @@ export interface operations {
};
};
};
createQuizzes: {
parameters: {
query?: never;
header?: never;
path: {
document_id: number;
};
cookie?: never;
};
requestBody: {
content: {
"application/json;charset=UTF-8": components["schemas"]["CreateQuizzesRequest"];
};
};
responses: {
/** @description Created */
201: {
headers: {
[name: string]: unknown;
};
content?: never;
};
};
};
searchDocumentByKeyword: {
parameters: {
query?: never;
Expand Down Expand Up @@ -3403,10 +3469,9 @@ export interface operations {
};
};
};
getQuizSetByCollection: {
getQuizSet: {
parameters: {
query: {
"collection-id"?: number;
"quiz-set-type": "TODAY_QUIZ_SET" | "DOCUMENT_QUIZ_SET" | "COLLECTION_QUIZ_SET" | "FIRST_QUIZ_SET";
};
header?: never;
Expand Down Expand Up @@ -3614,6 +3679,24 @@ export interface operations {
};
};
};
getInviteLinkMember: {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
requestBody?: never;
responses: {
/** @description OK */
200: {
headers: {
[name: string]: unknown;
};
content?: never;
};
};
};
getMemberInfo: {
parameters: {
query?: never;
Expand Down

0 comments on commit 6f99eb6

Please sign in to comment.