File size: 1,379 Bytes
58faf93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'use client'

import { useEffect } from 'react'
import { useRouter } from 'next/navigation'
import Link from 'next/link'
import { Container, Paper, Text, Title } from '@mantine/core'

import { useGetCollections, useGetConfig } from '@/lib/client/query'

export default function CollectionsPage() {
  const router = useRouter()
  const { data: config } = useGetConfig()
  const { data: collections, isError, error } = useGetCollections(config)

  useEffect(() => {
    if (collections != null && collections.length > 0) {
      router.push(`/collections/${collections[0]}`)
    }
  }, [collections, router])

  if (isError) {
    return (
      <Container ta={'center'}>
        <Paper withBorder ta={'center'} shadow="md" p={30} radius="md" mt="xl">
          <Title order={2}>Something went wrong</Title>
          <Text>{error.message}</Text>
          <Text>
            Go to <Link href={'/setup'}>Setup</Link>.
          </Text>
        </Paper>
      </Container>
    )
  }

  if (collections != null && collections.length === 0) {
    return (
      <Container ta={'center'}>
        <Paper withBorder ta={'center'} shadow="md" p={30} radius="md" mt="xl">
          <Text>There is no collections.</Text>
          <Text>
            <Link href={'/setup'}>Setup</Link> a new Chroma instance.
          </Text>
        </Paper>
      </Container>
    )
  }

  return null
}