Skip to content
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

[Fix] minor code improvements #53

Merged
merged 5 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export default function NameField({
const [localErrorType, setLocalErrorType] = useState<"invalid" | null>(null);

useEffect(() => {
// 공백, 특수문자, 숫자 불가 오류가 없을 경우만 `exists` 오류를 표시
if (errorType === "exists" && !localErrorType) {
setLocalErrorType(null);
}
Expand All @@ -24,15 +23,14 @@ export default function NameField({
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const inputValue = e.target.value;

// 글자 수가 6자 이하이며 유효한 입력일 때만 상태 업데이트
if (/^[ㄱ-ㅎ가-힣a-zA-Z]*$/.test(inputValue) && inputValue.length <= 6) {
setLocalErrorType(null); // Clear local error if valid input
setLocalErrorType(null);
onChange(inputValue);
} else if (
inputValue.length <= 6 &&
!/^[ㄱ-ㅎ가-힣a-zA-Z]*$/.test(inputValue)
) {
setLocalErrorType("invalid"); // Set error type only if input is invalid
setLocalErrorType("invalid");
}
};

Expand All @@ -48,7 +46,6 @@ export default function NameField({
return "focus:ring-grayscale-80";
};

// 조건에 따라 표시할 메시지 설정
let message = null;
if (errorType === "exists" && !localErrorType) {
message = <div className="text-danger-base">이미 존재하는 이름이에요</div>;
Expand Down
2 changes: 1 addition & 1 deletion fe/src/app/event-maps/[id]/load-mappin/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function Page() {
<button
type="button"
className="w-[24px] h-[24px]"
onClick={() => router.back()} // 뒤로 가기 기능
onClick={() => router.back()}
>
<Image
src="/images/ArrowBack.svg"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@ interface Ping {
nonMembers: { nonMemberId: number; name: string }[];
}

// nonMembers가 없는 Ping 타입
export type PingWithoutNonMembers = Omit<Ping, "nonMembers">;

interface MarkerStoreState {
customMarkers: Ping[];
setCustomMarkers: (pings: Ping[] | PingWithoutNonMembers[]) => void; // PingWithoutNonMembers[]도 허용
setCustomMarkers: (pings: Ping[] | PingWithoutNonMembers[]) => void;
resetMarkers: () => void;
}

export const useMarkerStore = create<MarkerStoreState>((set) => ({
customMarkers: [],
setCustomMarkers: (pings) => set({ customMarkers: pings as Ping[] }), // 타입 단언을 사용하여 맞춤 마커 설정
setCustomMarkers: (pings) => set({ customMarkers: pings as Ping[] }),
resetMarkers: () => set({ customMarkers: [] }),
}));
9 changes: 4 additions & 5 deletions fe/src/app/event-maps/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function Page() {
const { id } = useParams();
const parsedId = Array.isArray(id) ? id[0] : id;
const [data, setData] = useState<Data | null>(null);
const [isModalOpen, setIsModalOpen] = useState(false); // 모달 열림 상태 추가
const [isModalOpen, setIsModalOpen] = useState(false);
const moveToLocation = useLocationStore((state) => state.moveToLocation);
const setCustomMarkers = useMarkerStore((state) => state.setCustomMarkers);
const router = useRouter();
Expand Down Expand Up @@ -91,16 +91,16 @@ export default function Page() {
}, [id, data, moveToLocation, setCustomMarkers]);

const handleBackbtn = () => {
setIsModalOpen(true); // 뒤로 가기 버튼 클릭 시 모달 열기
setIsModalOpen(true);
};

const handleExit = () => {
setIsModalOpen(false);
router.replace("/eventcreate-page"); // UUID 초기화 후 이벤트 생성 페이지로 이동
router.replace("/eventcreate-page");
};

const handleCancel = () => {
setIsModalOpen(false); // 모달 닫기
setIsModalOpen(false);
};

const bind = useDrag(
Expand Down Expand Up @@ -149,7 +149,6 @@ export default function Page() {
</a.div>
</>
)}
{/* isModalOpen 상태에 따라 모달을 조건부 렌더링 */}
{isModalOpen && <ExitModal onCancel={handleCancel} onExit={handleExit} />}
</div>
);
Expand Down
4 changes: 1 addition & 3 deletions fe/src/app/event-maps/[id]/stores/useDataStore.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { create } from "zustand";

// 데이터 형식을 정의
interface NonMember {
nonMemberId: number;
name: string;
Expand All @@ -12,10 +11,9 @@ interface Data {
password: string;
bookmarkUrls: string[];
storeUrls: string[];
nonMembers: NonMember[]; // nonMembers 추가
nonMembers: NonMember[];
}

// 스토어 타입 정의
interface DataStore {
data: Data | null;
setData: (data: Data) => void;
Expand Down
3 changes: 1 addition & 2 deletions fe/src/app/event-maps/[id]/stores/useLocationStore.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { create } from "zustand";
import { LocationState } from "../types/types";

// 위치 상태를 zustand로 관리
export const useLocationStore = create<LocationState>((set) => ({
center: {
latitude: 37.5665, // 초기값: 서울
latitude: 37.5665,
longitude: 126.978,
},
moveToLocation: (latitude, longitude) =>
Expand Down
3 changes: 0 additions & 3 deletions fe/src/app/event-maps/[id]/types/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// 위치 정보를 담는 타입 정의
export interface Location {
latitude: number;
longitude: number;
}

// 상태 관리용 LocationState 타입 정의
export interface LocationState {
center: {
latitude: number;
Expand All @@ -13,7 +11,6 @@ export interface LocationState {
moveToLocation: (latitude: number, longitude: number) => void;
}

// MapComponent의 props 타입 정의
export interface MapComponentProps {
mapInstance: React.MutableRefObject<naver.maps.Map>;
}
Expand Down
6 changes: 2 additions & 4 deletions fe/src/app/eventcreate-page/components/LocationInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, { useEffect, useState } from "react";
import { useRouter } from "next/navigation";
import Image from "next/image";
import { useLocationStore } from "@/app/eventcreate-page/stores/useLocationStore";
import { LocationInputProps } from "@/app/eventcreate-page/types/types"; // Place 임포트 제거
import { LocationInputProps } from "@/app/eventcreate-page/types/types";

function LocationInput({
className,
Expand All @@ -15,17 +15,15 @@ function LocationInput({
const { selectedLocation } = useLocationStore();
const [location, setLocationState] = useState(value);

// selectedLocation이 변경될 때 location 상태를 업데이트
useEffect(() => {
if (selectedLocation && selectedLocation.name !== location) {
setLocationState(selectedLocation.name);
if (onSelect) {
onSelect(selectedLocation); // selectedLocation을 상위 컴포넌트로 전달
onSelect(selectedLocation);
}
}
}, [selectedLocation, onSelect, location]);

// input 필드의 value가 변경될 때 상태를 업데이트
useEffect(() => {
setLocationState(value);
}, [value]);
Expand Down
4 changes: 2 additions & 2 deletions fe/src/app/eventcreate-page/components/SearchResultsItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ function SearchResultItem({
isHighlighted
? `highlight-${part}-${index}`
: `text-${part}-${index}`
} // Use a combination of part and index for keys
}
style={
isHighlighted ? { color: "#3a91ea" } : { color: "#4a4a4a" }
} // Use a gray color for non-highlighted text
}
className={isHighlighted ? "font-semibold" : "text-gray-800"}
>
{part}
Expand Down
7 changes: 2 additions & 5 deletions fe/src/app/eventcreate-page/location-search/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// src/app/eventcreate-page/location-search/page.tsx

"use client";

import React, { useState, useEffect, useCallback } from "react";
Expand All @@ -17,7 +15,6 @@ interface Place {
}

function LocationSearch() {
// 화살표 함수 대신 일반 함수 선언
const [location, setLocation] = useState<string>("");
const [results, setResults] = useState<Place[]>([]);
const [isFetching, setIsFetching] = useState(false);
Expand Down Expand Up @@ -81,8 +78,8 @@ function LocationSearch() {
};

const handleSelectPlace = (place: Place) => {
setStoreLocation(place); // 선택된 위치를 저장
router.push("/eventcreate-page"); // EventCreatePage로 이동
setStoreLocation(place);
router.push("/eventcreate-page");
};

const handleClearLocation = () => {
Expand Down
6 changes: 3 additions & 3 deletions fe/src/app/eventcreate-page/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useLocationStore } from "@/app/eventcreate-page/stores/useLocationStore

function EventCreatePage() {
const router = useRouter();
const { selectedLocation, setLocation } = useLocationStore(); // Get location info from useLocationStore
const { selectedLocation, setLocation } = useLocationStore();
const [eventName, setEventName] = useState("");
const [isFormComplete, setIsFormComplete] = useState(false);
const [isSubmitting, setIsSubmitting] = useState(false);
Expand All @@ -34,7 +34,7 @@ function EventCreatePage() {
px?: number;
py?: number;
}) => {
setLocation(place); // Save the selected location to LocationStore
setLocation(place);
};

useEffect(() => {
Expand Down Expand Up @@ -89,7 +89,7 @@ function EventCreatePage() {
}, [uuid, router]);

const handleBackClick = () => {
router.push("/"); // 메인 페이지로 이동
router.push("/");
};

return (
Expand Down
11 changes: 2 additions & 9 deletions fe/src/app/eventcreate-page/types/types.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
// src/types.ts

// EventNameInput 컴포넌트의 Props 타입
export interface EventNameInputProps {
value: string;
onChange: (name: string) => void;
className?: string;
selectedLocation?: string;
}

// Location 관련 타입
export interface LocationState {
center: {
latitude: number;
Expand All @@ -17,24 +13,21 @@ export interface LocationState {
moveToLocation: (latitude: number, longitude: number) => void;
}

// 장소 정보 타입
export interface Place {
name: string;
address: string;
px?: number;
py?: number;
}

// LocationInput 컴포넌트의 Props 타입
export interface LocationInputProps {
className?: string;
value: string;
onSelect: (place: Place) => void; // onSelect 함수로 Place 정보를 전달
onSelect: (place: Place) => void;
}

// Navigation 컴포넌트의 Props 타입
export interface NavigationProps {
showBackButton?: boolean;
title?: string;
onBack?: () => void; // Optional onBack function for handling back navigation
onBack?: () => void;
}
Loading