Skip to content

Commit

Permalink
fix(issue #646): improves upon the load more functionality of the table
Browse files Browse the repository at this point in the history
  • Loading branch information
Vayras committed Dec 1, 2023
1 parent 7349507 commit 15a717c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
13 changes: 10 additions & 3 deletions src/components/SourcesTableModal/SourcesView/Topics/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Filter } from './Sort'
import { Table } from './Table'

export const TopicSources = () => {
const [loading, setLoading] = useState(true)
const [loading, setLoading] = useState(false)

const [data, ids, total, setTopics, filters, setFilters, terminate] = useTopicsStore((s) => [
s.data,
Expand Down Expand Up @@ -63,8 +63,15 @@ export const TopicSources = () => {
init()
}, [setTopics, filters])

const handleLoadMore = () => {
setFilters({ page: filters.page + 1 })
const handleLoadMore = async () => {
try {
setLoading(true)
setFilters({ page: filters.page + 1 })
} catch (error) {
console.error('Error loading more data:', error)
} finally {
setLoading(false)
}
}

useEffect(
Expand Down
5 changes: 3 additions & 2 deletions src/stores/useTopicsStore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ export const useTopicsStore = create<TopicsStore>((set, get) => ({

const responseData: FetchTopicResponse = await getTopicsData(payload)

const newData: Record<string, Topic> = filters.page > 0 ? data || {} : {}
const newIds: string[] = filters.page > 0 ? ids : []
// Instead of replacing the data, append new data to existing data
const newData: Record<string, Topic> = { ...(data || {}) }
const newIds: string[] = [...ids]

responseData.data.forEach((topic) => {
newData[topic.ref_id] = topic
Expand Down

0 comments on commit 15a717c

Please sign in to comment.