Skip to content

Commit

Permalink
Merge branch 'main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
박정민 committed Feb 17, 2024
2 parents cadd22f + 4cd61bd commit f536fa5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
23 changes: 22 additions & 1 deletion src/components/Edit/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ const Editor = () => {
}
};

const refreshUserEditTime = async () => {
try {
await axios.post(apiPath.TEAM.refresh());
} catch (error) {
console.error('Error updating user status:', error);
}
};

const {
title,
contents,
Expand All @@ -24,11 +32,24 @@ const Editor = () => {
} = useBoardCreate();

useEffect(() => {
const handleBeforeUnload = async () => {
await updateUserStatus('not_written');
};

window.addEventListener('beforeunload', handleBeforeUnload);

// 페이지 접근 시 사용자 상태를 'writing'으로 변경
updateUserStatus('writing');
// 컴포넌트가 언마운트될 때 'not_written'으로 상태 변경

const intervalId = setInterval(() => {
refreshUserEditTime();
}, 50000); // 50초마다

return () => {
// updateUserStatus('not_written');
clearInterval(intervalId);
updateUserStatus('not_written');
window.removeEventListener('beforeunload', handleBeforeUnload);
};
}, []); // 빈 배열을 넣어 처음 마운트될 때만 실행되도록 함

Expand Down
13 changes: 9 additions & 4 deletions src/components/Home/Info/TeamInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@ const TeamInfo = () => {
queryClient.setQueryData(['teamList'], (oldTeams?: MemberListResponse[]) => {
const updatedTeams = oldTeams
?.map((member) => {
const newStatus = newStatusData[member.id];
const isUpdated = newStatus && member.status !== newStatus;

let newStatus = newStatusData[member.id];
// isNotWritten : 작성중인 상태인데 받아온 데이터에는 없을 경우( 사용자가 머물지 않았음 )
const isNotWritten = !newStatus && member.status === 'writing';
const isUpdated = (newStatus && member.status !== newStatus) || isNotWritten;
// const isUpdated = newStatus && member.status !== newStatus;
if (isNotWritten) newStatus = 'not_written';
if (isUpdated) {
console.log('isUpdated', isUpdated, member);
// Reset highlight after 2 seconds
setTimeout(() => {
queryClient.setQueryData(
Expand All @@ -62,6 +66,7 @@ const TeamInfo = () => {
})
.sort(sortTeamMembers);

console.log(updatedTeams);
return updatedTeams;
});
};
Expand All @@ -75,7 +80,7 @@ const TeamInfo = () => {
};

return () => eventSource.close();
}, [queryClient]);
}, []);

// Handle poke and cheer actions
const handlePoke = async (memberId: string, body?: string) => {
Expand Down
1 change: 1 addition & 0 deletions src/util/apiPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const API_PATH = {
join: () => SERVER_URL + TEAM + '/join',
teamProfile: (teamCode: string) => SERVER_URL + TEAM + `/${teamCode}`,
updateState: () => SERVER_URL + TEAM + '/change-status',
refresh: () => SERVER_URL + TEAM + '/refresh',
},
PUSH: {
push: () => SERVER_URL + PUSH,
Expand Down

0 comments on commit f536fa5

Please sign in to comment.