diff --git a/src/components/Members/LeftPanel/Channels.tsx b/src/components/Members/LeftPanel/Channels.tsx index 994b920..973d025 100644 --- a/src/components/Members/LeftPanel/Channels.tsx +++ b/src/components/Members/LeftPanel/Channels.tsx @@ -1,7 +1,15 @@ import { FaCog } from "react-icons/fa"; +import { Pb } from "../../EspaceMembres"; +import { useContext, useState } from "preact/hooks"; +import type { ChannelsRecord } from "../../../types/pb_types"; export default function Channels() { - const channels = ["Discussion", "Nature", "Portrait", "Architecture"]; + const pb = useContext(Pb); + const [channels, setChannels] = useState>([]); + pb.collection('channels').getFullList().then((data) => { + if (!data) return; + setChannels(data); + }); return (
@@ -15,7 +23,7 @@ export default function Channels() { {channels.map((channel) => (
  • - # {channel} + # {channel.name}

  • diff --git a/src/types/pb_types.d.ts b/src/types/pb_types.d.ts index 5b0dfdc..3255c93 100644 --- a/src/types/pb_types.d.ts +++ b/src/types/pb_types.d.ts @@ -6,9 +6,11 @@ import type PocketBase from 'pocketbase' import type { RecordService } from 'pocketbase' export enum Collections { + Albums = "albums", Channels = "channels", - Files = "files", + Messages = "messages", Pages = "pages", + Photos = "photos", Users = "users", } @@ -36,14 +38,22 @@ export type AuthSystemFields = { // Record types for each collection +export type AlbumsRecord = { + description?: string + pictures?: RecordIdString[] + title?: string +} + export type ChannelsRecord = { - field1?: RecordIdString[] + creator?: RecordIdString name?: string } -export type FilesRecord = { - alt?: string - file: string +export type MessagesRecord = { + attachment?: string + author?: RecordIdString + channel?: RecordIdString + content?: string } export type PagesRecord = { @@ -52,6 +62,13 @@ export type PagesRecord = { title?: string } +export type PhotosRecord = { + alt?: string + description?: string + image?: string + title?: string +} + export type UsersRecord = { avatar?: string firstname?: string @@ -59,24 +76,30 @@ export type UsersRecord = { } // Response types include system fields and match responses from the PocketBase API +export type AlbumsResponse = Required & BaseSystemFields export type ChannelsResponse = Required & BaseSystemFields -export type FilesResponse = Required & BaseSystemFields +export type MessagesResponse = Required & BaseSystemFields export type PagesResponse = Required> & BaseSystemFields +export type PhotosResponse = Required & BaseSystemFields export type UsersResponse = Required & AuthSystemFields // Types containing all Records and Responses, useful for creating typing helper functions export type CollectionRecords = { + albums: AlbumsRecord channels: ChannelsRecord - files: FilesRecord + messages: MessagesRecord pages: PagesRecord + photos: PhotosRecord users: UsersRecord } export type CollectionResponses = { + albums: AlbumsResponse channels: ChannelsResponse - files: FilesResponse + messages: MessagesResponse pages: PagesResponse + photos: PhotosResponse users: UsersResponse } @@ -84,8 +107,10 @@ export type CollectionResponses = { // https://github.com/pocketbase/js-sdk#specify-typescript-definitions export type TypedPocketBase = PocketBase & { + collection(idOrName: 'albums'): RecordService collection(idOrName: 'channels'): RecordService - collection(idOrName: 'files'): RecordService + collection(idOrName: 'messages'): RecordService collection(idOrName: 'pages'): RecordService + collection(idOrName: 'photos'): RecordService collection(idOrName: 'users'): RecordService }