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

#484 방 검색 안되었을때 방 생성하기 버튼 추가 #505

Draft
wants to merge 4 commits into
base: dev
Choose a base branch
from
Draft
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
17 changes: 17 additions & 0 deletions src/hooks/useLocationSearch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useLocation } from "react-router-dom";
import { useMemo } from "react";

interface ReadOnlyURLSearchParams extends URLSearchParams {
append: never;
delete: never;
sort: never;
}

export default function useLocationSearch() {
const { search } = useLocation();

return useMemo(
() => new URLSearchParams(search) as ReadOnlyURLSearchParams,
[search]
);
}
33 changes: 33 additions & 0 deletions src/pages/Addroom/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import { randomRoomNameGenerator } from "tools/random";
import regExpTest from "tools/regExpTest";
import theme from "tools/theme";

import useLocationSearch from "hooks/useLocationSearch";

const AddRoom = () => {
const axios = useAxios();
const history = useHistory();
Expand Down Expand Up @@ -60,6 +62,37 @@ const AddRoom = () => {
const myRooms = useValueRecoilState("myRooms");
const fetchMyRooms = useFetchRecoilState("myRooms");

const locationSearch = useLocationSearch();

useEffect(() => {
if (locationSearch.get("from") && locationSearch.get("to")) {
setPlace([locationSearch.get("from")!, locationSearch.get("to")!]);
}
if (locationSearch.get("name")) {
setName(locationSearch.get("name")!);
}
if (locationSearch.get("date")) {
const date = locationSearch.get("date")!.split("-");
setDate([Number(date[0]), Number(date[1]), Number(date[2])]);
}
if (locationSearch.get("time")) {
const time = locationSearch.get("time")!.split(":");
setTime([Number(time[0]), Number(time[1])]);
}
if (locationSearch.get("maxPeople")) {
setMaxPeople(Number(locationSearch.get("maxPeople")!));
}
}, [locationSearch]);

useEffect(() => {
locationSearch.set("from", valuePlace[0] || "");
locationSearch.set("to", valuePlace[1] || "");
locationSearch.set("name", valueName);
locationSearch.set("date", date2str(valueDate));
locationSearch.set("time", valueTime.join(":"));
locationSearch.set("maxPeople", valueMaxPeople.toString());
}, [valueName, valuePlace, valueDate, valueTime, valueMaxPeople]);

useEffect(() => {
const expirationDate = new Date();
expirationDate.setFullYear(expirationDate.getFullYear() + 10);
Expand Down
5 changes: 4 additions & 1 deletion src/pages/Search/SideResult.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,10 @@ const SideResult = (props) => {
/>
<DottedLine direction="row" />
{rooms.length == 0 ? (
<Empty screen="pc">검색 결과가 없습니다</Empty>
<Empty screen="pc">
<div>검색 결과가 없습니다</div>
{/* <div></div> */}
</Empty>
) : (
<>
{rooms
Expand Down