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
60 changes: 29 additions & 31 deletions src/entities/main/ui/DateContainer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const DateContainer = () => {
}, []);
const pastDays = Math.floor(totalDays / 2);

const { setSelectDate } = useSelectDateStore();
const { selectDate, setSelectDate } = useSelectDateStore();

const { stageId } = useMyStageIdStore();

Expand All @@ -42,39 +42,37 @@ const DateContainer = () => {
return { short: `${month}-${day}`, full: `${year}-${month}-${day}` };
});

const syncSelectedDate = (fullDate: string) => {
const matchedDate = dates.find((d) => d.full === fullDate);

if (matchedDate) {
setSelectedDate(matchedDate.short);
setSelectDate(matchedDate.full);
setStartIndex(dates.findIndex((d) => d.full === fullDate));
} else {
const date = new Date(fullDate);
const short = `${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;
setSelectedDate(short);
setSelectDate(fullDate);
setStartIndex(dates.findIndex((d) => d.full === fullDate));
}
};

useEffect(() => {
const localSelectDate = sessionStorage.getItem('selectDate');

if (localSelectDate) {
const { selectDate: localDate, stageId: localStageId } =
JSON.parse(localSelectDate);

if (localDate !== '') {
if (stageId === localStageId) {
const matchedDate = dates.find((d) => d.full === localDate);

if (matchedDate) {
setSelectedDate(matchedDate.short);
setSelectDate(matchedDate.full);
const matchedIndex = dates.findIndex((d) => d.full === localDate);
setStartIndex(matchedIndex);
} else {
const date = new Date(localDate);
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
const short = `${month}-${day}`;

setSelectedDate(short);
setSelectDate(localDate);
const matchedIndex = dates.findIndex((d) => d.full === localDate);
setStartIndex(matchedIndex);
}
}
}
if (selectDate) syncSelectedDate(selectDate);
}, []);

useEffect(() => {
const local = sessionStorage.getItem('selectDate');
if (!local) return;

const { selectDate: localDate, stageId: localStageId } = JSON.parse(local);
sessionStorage.removeItem('selectDate');

sessionStorage.removeItem('selectDate');
if (localDate && stageId === localStageId) {
syncSelectedDate(localDate);
}
}, [dates]);
}, [dates, stageId]);

const todayIndex = dates.findIndex(
(d) =>
Expand Down
1 change: 1 addition & 0 deletions src/views/main/ui/MainPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ const MainPage = () => {
text={isToday ? '오늘 최신 매치' : `${selectDate.slice(5)} 매치`}
icon={<MatchClockIcon />}
path={`/match/list/${stageId}`}
onClick={() => setSelectDate(selectDate)}
>
<StageMatchSection
matches={searchMatchData}
Expand Down
4 changes: 4 additions & 0 deletions src/views/match/ui/MatchPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ const MatchPage = () => {
setSelectDate('');
}, [stageId]);

useEffect(() => {
setSelectDate(selectDate);
}, []);

const today = new Date();

const [year, month, day] = selectDate
Expand Down