diff --git a/.eslintrc.json b/.eslintrc.json index b6e23d8d..baf8b697 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -25,6 +25,7 @@ ], "unused-imports/no-unused-imports": "error", "no-else-return": ["error", { "allowElseIf": false }], + "jsx-a11y/label-has-associated-control": "off", "@typescript-eslint/consistent-type-imports": [ "error", { "fixStyle": "inline-type-imports" } diff --git a/middleware.ts b/middleware.ts index 104b0f54..2ac9cc12 100644 --- a/middleware.ts +++ b/middleware.ts @@ -1,6 +1,7 @@ import type { NextRequest } from 'next/server'; import { NextResponse } from 'next/server'; +import { ROUTES } from '@constants/routes'; import { STORAGE_KEY } from '@models/storage'; export const middleware = async (request: NextRequest) => { @@ -9,7 +10,9 @@ export const middleware = async (request: NextRequest) => { if (request.nextUrl.pathname.startsWith('/terms')) return; if (refreshToken?.value && request.nextUrl.pathname === '/') { - return NextResponse.redirect(new URL('/main', request.url)); + return NextResponse.redirect( + new URL(`${ROUTES.MAIN}?tab=write`, request.url), + ); } if ( @@ -17,7 +20,7 @@ export const middleware = async (request: NextRequest) => { request.nextUrl.pathname !== '/' && !request.nextUrl.pathname.startsWith('/redirect') ) { - return NextResponse.redirect(new URL('/', request.url)); + return NextResponse.redirect(new URL(ROUTES.LANDING, request.url)); } }; diff --git a/pages/main/index.tsx b/pages/main/index.tsx index 2130efb3..48a5d16d 100644 --- a/pages/main/index.tsx +++ b/pages/main/index.tsx @@ -1,23 +1,27 @@ -import { useState } from 'react'; +import { useRouter, useSearchParams } from 'next/navigation'; import Layout from '@components/Layout'; import MainPageTab from '@components/Layout/MainPageTab'; +import { ROUTES } from '@constants/routes'; import WriteTabContent from '@domain/끄적이는/components/WriteTabContent'; import 참고하는TabContent from '@domain/참고하는/components'; import useGetMyProfile from '@queries/useGetMyProfile'; import { COLORS } from '@styles/tokens'; const MainPage = () => { - useGetMyProfile(); + const router = useRouter(); + const searchParams = useSearchParams(); + + const selectedTab = searchParams.get('tab') || 'write'; - const [selectedTab, setSelectedTab] = useState('끄적이는'); + useGetMyProfile(); const handleTabSelect = (selectedTab: string) => { - setSelectedTab(selectedTab); + router.push(`${ROUTES.MAIN}?tab=${selectedTab}`); }; const backgroundColor = - selectedTab === '참고하는' ? COLORS['Grey/100'] : undefined; + selectedTab === 'refer' ? COLORS['Grey/100'] : undefined; return ( diff --git a/pages/redirect/[authType]/index.tsx b/pages/redirect/[authType]/index.tsx index 1e1fb016..5fe7e87e 100644 --- a/pages/redirect/[authType]/index.tsx +++ b/pages/redirect/[authType]/index.tsx @@ -31,7 +31,7 @@ const Bridge = () => { saveToken({ accessToken, refreshToken }); localStorage.setItem(STORAGE_KEY.RECENT_LOGIN_TYPE, authType); - router.replace(ROUTES.MAIN); + router.replace(`${ROUTES.MAIN}?tab=write`); })(); }, [router.query, router]); diff --git a/src/components/Input/WriteInput/index.tsx b/src/components/Input/WriteInput/index.tsx index bebdc1ae..d4f89b7e 100644 --- a/src/components/Input/WriteInput/index.tsx +++ b/src/components/Input/WriteInput/index.tsx @@ -23,7 +23,7 @@ const WriteInput = ({ maxLength = MAIN_INPUT_MAX_LENGTH, onSubmit, }: WriteInputProps) => { - const { id, value } = inputProps; + const { id, value, onChange } = inputProps; const inputRef = useRef(null); const [textareaHeight, setTextareaHeight] = useState<{ @@ -62,12 +62,15 @@ const WriteInput = ({ }; const handleKeydownEnter = (e: KeyboardEvent) => { - if (e.code === 'Enter') { - setTextareaHeight((prev) => ({ - row: prev.row + 1, - lineBreak: { ...prev.lineBreak, [value.length]: true }, - })); - return; + if (e.nativeEvent.isComposing) return; + + if (e.code === 'Enter' && !e.shiftKey) { + e.preventDefault(); + setTextareaHeight({ + row: 1, + lineBreak: {}, + }); + value.trim() && onSubmit(); } }; @@ -81,13 +84,15 @@ const WriteInput = ({ >