fix(lint): resolve react-hooks/set-state-in-effect in storage and suggestions clients
This commit is contained in:
@@ -101,7 +101,6 @@ export function StorageClient() {
|
|||||||
const isSearchChangeRef = useRef(false)
|
const isSearchChangeRef = useRef(false)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setStatsLoading(true)
|
|
||||||
fetch("/api/admin/storage/stats")
|
fetch("/api/admin/storage/stats")
|
||||||
.then((res) => res.json())
|
.then((res) => res.json())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import { useCallback, useEffect, useMemo, useState } from "react"
|
import { useEffect, useMemo, useState } from "react"
|
||||||
import Link from "next/link"
|
import Link from "next/link"
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
import { ConfirmDialog } from "@/components/ui/modal"
|
import { ConfirmDialog } from "@/components/ui/modal"
|
||||||
@@ -65,24 +65,25 @@ export function SuggestionsClient() {
|
|||||||
{ label: "Rejected", value: "rejected" },
|
{ label: "Rejected", value: "rejected" },
|
||||||
]
|
]
|
||||||
|
|
||||||
const fetchSuggestions = useCallback(async () => {
|
|
||||||
setLoading(true)
|
|
||||||
try {
|
|
||||||
const res = await fetch(`/api/community-suggestions/admin?limit=${LIMIT}`)
|
|
||||||
if (res.ok) {
|
|
||||||
const json = (await res.json()) as SuggestionsApiResponse
|
|
||||||
setSuggestions(json.data)
|
|
||||||
setTotal(json.total)
|
|
||||||
}
|
|
||||||
setOffset(0)
|
|
||||||
} finally {
|
|
||||||
setLoading(false)
|
|
||||||
}
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchSuggestions()
|
let cancelled = false
|
||||||
}, [fetchSuggestions])
|
const run = async () => {
|
||||||
|
try {
|
||||||
|
const res = await fetch(`/api/community-suggestions/admin?limit=${LIMIT}`)
|
||||||
|
if (res.ok && !cancelled) {
|
||||||
|
const json = (await res.json()) as SuggestionsApiResponse
|
||||||
|
setSuggestions(json.data)
|
||||||
|
setTotal(json.total)
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// ignore
|
||||||
|
} finally {
|
||||||
|
if (!cancelled) setLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
run()
|
||||||
|
return () => { cancelled = true }
|
||||||
|
}, [])
|
||||||
|
|
||||||
const filtered = useMemo(() => {
|
const filtered = useMemo(() => {
|
||||||
let result = suggestions
|
let result = suggestions
|
||||||
|
|||||||
Reference in New Issue
Block a user