feat(improvement): add pagination to endpoints and pages + sync navbar when data changes
This commit is contained in:
@@ -38,12 +38,14 @@ export const WorkspaceProvider = ({ children }: { children: ReactNode }) => {
|
||||
|
||||
const loadWorkspaces = async () => {
|
||||
try {
|
||||
const data = await fetchWorkspaces()
|
||||
const response = await fetchWorkspaces()
|
||||
|
||||
const data = Array.isArray(response) ? response : (response?.results || [])
|
||||
setWorkspaces(data)
|
||||
|
||||
if (data.length > 0) {
|
||||
const storedId = localStorage.getItem("activeWorkspaceId")
|
||||
const stored = data.find((w) => w.id === storedId)
|
||||
const stored = data.find((w: Workspace) => w.id === storedId)
|
||||
if (stored) {
|
||||
setActiveWorkspaceState(stored)
|
||||
} else {
|
||||
@@ -69,7 +71,7 @@ export const WorkspaceProvider = ({ children }: { children: ReactNode }) => {
|
||||
const addWorkspace = async (name: string) => {
|
||||
try {
|
||||
setIsCreatingFirst(true)
|
||||
const newWs = await createWorkspace(name)
|
||||
const newWs = await createWorkspace({ name, description: "" })
|
||||
setWorkspaces((prev) => [...prev, newWs])
|
||||
setActiveWorkspace(newWs)
|
||||
toast.success(t.workspace?.createSuccess || "Workspace created!")
|
||||
|
||||
Reference in New Issue
Block a user