Skip to content
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
4 changes: 2 additions & 2 deletions src/components/WikiMiniButton.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Link } from "react-router-dom";

export default function WikiMiniButton({ name }) {
export default function WikiMiniButton({ name, id }) {
return (
<>
<Link to={`/wiki/${name}`} className="person-tag">
<Link to={`/wiki/${id}`} className="person-tag">
{name}
</Link>
</>
Expand Down
26 changes: 17 additions & 9 deletions src/pages/BoothHome.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,26 @@ export default function BoothHome() {
};
}, []);


return isMobile ? <BoothMobileView recentPeople={recentPeople} /> : <Home />;
return isMobile ? (
<BoothMobileView
recentPeople={recentPeople}
setRecentPeople={setRecentPeople}
/>
) : (
<Home />
);
}

function BoothMobileView({ recentPeople }) {
function BoothMobileView({ recentPeople, setRecentPeople }) {
const [query, setQuery] = useState("");
const navigate = useNavigate();
const [errorMessage, setErrorMessage] = useState("");
const [errorMessage, setErrorMessage] = useState("");

const handleSearch = () => {
if (query.trim() === "") return;
navigate(`/search?name=${encodeURIComponent(query)}`);
};


useEffect(() => {
if (getCookie("access_token") === undefined) {
navigate("/login");
Expand All @@ -65,10 +70,13 @@ function BoothMobileView({ recentPeople }) {
console.log("✅ API 응답:", response.data);

if (response.data.errorCode) {

console.warn("최근 수정된 목록 불러오기 실패:", response.data.message);
console.warn(
"최근 수정된 목록 불러오기 실패:",
response.data.message
);
setRecentPeople([]); // 최근 목록 초기화
setErrorMessage(response.data.message); // 오류 메시지 저장
alert(errorMessage);
} else {
setRecentPeople(response.data.result.modifiedWikiList || []); // 정상 데이터 저장
setErrorMessage("");
Expand All @@ -77,6 +85,7 @@ function BoothMobileView({ recentPeople }) {
console.error("최근 수정된 위키 불러오기 실패:", error);
setRecentPeople([]);
setErrorMessage("최근 수정된 위키를 불러오는 중 오류가 발생했습니다."); // 네트워크 오류 메시지
alert(errorMessage);
}
};

Expand All @@ -93,7 +102,6 @@ function BoothMobileView({ recentPeople }) {
</Link>
</header>


<div className="booth-search-box">
<img
src={searchIcon}
Expand Down Expand Up @@ -122,7 +130,7 @@ function BoothMobileView({ recentPeople }) {
<div className="recent-people">
{recentPeople.length > 0 ? (
recentPeople.map((wiki) => (
<WikiMiniButton key={wiki.id} name={wiki.name} />
<WikiMiniButton key={wiki.id} name={wiki.name} id={wiki.id} />
))
) : (
<p>최근 수정된 인물이 없습니다.</p> // ✅ API 응답이 없을 때 대비
Expand Down
19 changes: 12 additions & 7 deletions src/pages/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import apply from "../assets/apply.svg";
import "./Home.css";
import WikiMiniButton from "../components/WikiMiniButton";
import { EventTrigger } from "../utils/gatriggers";
import axios from "axios";

export default function Home() {
const [isMobile, setIsMobile] = useState(window.innerWidth <= 768); // 768px 이하를 모바일로 간주
Expand Down Expand Up @@ -37,13 +38,13 @@ function PcView() {
navigate(`/search?name=${query}`); // ✅ 검색 페이지로 이동
};
const handleKeyDown = (event) => {
if (event.key === "Enter") { // ✅ Enter 키 입력 시 검색 실행
if (event.key === "Enter") {
// ✅ Enter 키 입력 시 검색 실행
event.preventDefault();
handleSearch();
}
};


return (
<div className="home-container">
<header className="home-header"></header>
Expand All @@ -62,7 +63,7 @@ function PcView() {
className="home-search-icon"
onClick={handleSearch} // ✅ 아이콘 클릭 시 검색 실행
style={{ cursor: "pointer" }} // 버튼처럼 동작하도록 변경
/>
/>
<input
type="text"
placeholder="찾고싶은 인물의 이름을 검색해주세요!"
Expand All @@ -88,8 +89,8 @@ function PcView() {
function PublicMobileView() {
const [query, setQuery] = useState("");
const [recentPeople, setRecentPeople] = useState([]);
const [errorMessage, setErrorMessage] = useState("");
const navigate = useNavigate();


useEffect(() => {
const fetchRecentWikis = async () => {
Expand All @@ -101,10 +102,13 @@ function PublicMobileView() {
console.log("API 응답:", response.data);

if (response.data.errorCode) {

console.warn("최근 수정된 목록 불러오기 실패:", response.data.message);
console.warn(
"최근 수정된 목록 불러오기 실패:",
response.data.message
);
setRecentPeople([]); // 최근 목록 초기화
setErrorMessage(response.data.message); // 오류 메시지 저장
alert(errorMessage);
} else {
setRecentPeople(response.data.result.modifiedWikiList || []); // 정상 데이터 저장
setErrorMessage("");
Expand All @@ -113,6 +117,7 @@ function PublicMobileView() {
console.error("최근 수정된 위키 불러오기 실패:", error);
setRecentPeople([]);
setErrorMessage("최근 수정된 위키를 불러오는 중 오류가 발생했습니다."); // 네트워크 오류 메시지
alert(errorMessage);
}
};

Expand Down Expand Up @@ -177,7 +182,7 @@ function PublicMobileView() {
<div className="recent-people">
{recentPeople.length > 0 ? (
recentPeople.map((wiki) => (
<WikiMiniButton key={wiki.id} name={wiki.name} />
<WikiMiniButton key={wiki.id} name={wiki.name} id={wiki.id} />
))
) : (
<p>최근 수정된 인물이 없습니다.</p>
Expand Down
1 change: 1 addition & 0 deletions src/pages/RegisterForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const Register = () => {
if (error) {
alert(`Error: ${error.message}`);
} else {
alert("등록이 완료되었습니다.");
navigate("/booth");
}
};
Expand Down
7 changes: 4 additions & 3 deletions src/stores/PostListStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ const usePostListStore = create((set) => ({
searchPosts: async (query, page = 1) => {
try {
const response = await axios.get(
`${import.meta.env.VITE_API_URL}/api/wiki?page=${page}&name=${query}`
`${
import.meta.env.VITE_API_URL
}/api/wiki/public?page=${page}&name=${query}`
);

const data = response.data;

if (data.errorCode) {

console.warn("검색 실패:", data.message);
set({ posts: [], errorMessage: data.message });
set({ posts: [], errorMessage: data.message });
} else {
set({ posts: data.result.wikiList, errorMessage: "" });
}
Expand Down
2 changes: 1 addition & 1 deletion src/stores/PostStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const usePostStore = create((set) => ({
set({ loading: true, error: null });
try {
const response = await axios.get(
`${import.meta.env.VITE_API_URL}/api/wiki/${id}`
`${import.meta.env.VITE_API_URL}/api/wiki/public/${id}`
);
const { data } = response;
const { result } = data;
Expand Down
Loading