Skip to content

Commit

Permalink
削除時のstate更新もまとめる
Browse files Browse the repository at this point in the history
  • Loading branch information
takaishi committed May 12, 2024
1 parent 7102f38 commit d4e9cc7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
27 changes: 13 additions & 14 deletions src/components/CheckIn/CheckIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,7 @@ export const CheckIn: React.FC<Props> = ({ checkInType }) => {
useEffect(() => {
const interval = setInterval(() => {
console.log('Send check-in logs to dreamkast api:')
console.log(storedKeys)

for (const key of storedKeys) {
console.log(
`Success to send check-in log: key:L ${key}, value: ${JSON.stringify(
localStorage.getItem(key),
)}`,
)
deleteItem(key)
}
deleteItems(storedKeys)
}, 10000)
return () => clearInterval(interval)
}, [storedKeys])
Expand All @@ -62,9 +53,17 @@ export const CheckIn: React.FC<Props> = ({ checkInType }) => {
setOpen(false)
}

const deleteItem = (key: string) => {
localStorage.removeItem(key)
setStoredKeys(storedKeys.filter((k) => k !== key))
const deleteItems = (keys: string[]) => {
console.log(keys)
for (const key of keys) {
console.log(
`Success to send check-in log: key:L ${key}, value: ${JSON.stringify(
localStorage.getItem(key),
)}`,
)
localStorage.removeItem(key)
}
setStoredKeys(storedKeys.filter((k) => !keys.includes(k)))
}

return (
Expand All @@ -74,7 +73,7 @@ export const CheckIn: React.FC<Props> = ({ checkInType }) => {
<DummyCheckInButton onClick={checkInConference} />
<ConfirmDialog open={open} handleClose={handleClose} />
<Typography variant="h5">↓Debug↓</Typography>
<Debug storedKeys={storedKeys} deleteItem={deleteItem} />
<Debug storedKeys={storedKeys} deleteItems={deleteItems} />
</div>
)
}
6 changes: 3 additions & 3 deletions src/components/CheckIn/internal/Debug/Debug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import React from 'react'

type Props = {
storedKeys: string[]
deleteItem: (key: string) => void
deleteItems: (keys: string[]) => void
}

export const Debug: React.FC<Props> = ({ storedKeys, deleteItem }) => {
export const Debug: React.FC<Props> = ({ storedKeys, deleteItems }) => {
return (
<TableContainer>
<Table>
Expand All @@ -37,7 +37,7 @@ export const Debug: React.FC<Props> = ({ storedKeys, deleteItem }) => {
<TableCell>
<Button
type="submit"
onClick={() => deleteItem(key)}
onClick={() => deleteItems([key])}
variant="contained"
>
Delete
Expand Down

0 comments on commit d4e9cc7

Please sign in to comment.