Skip to content

Commit

Permalink
small change
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomorebonato committed Nov 1, 2024
1 parent 747cc72 commit ba811ac
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
7 changes: 0 additions & 7 deletions frontend/App.tsx

This file was deleted.

4 changes: 3 additions & 1 deletion frontend/components/create-note-dialog.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { usePocketBase } from '@/use-pocketbase'
import { useMutation } from '@tanstack/react-query'
import { useMutation, useQueryClient } from '@tanstack/react-query'
import { useNavigate } from '@tanstack/react-router'
import { type RefObject, forwardRef } from 'react'

Expand All @@ -9,6 +9,7 @@ export const CreateNoteDialog = forwardRef<
inputTitleRef: RefObject<HTMLInputElement>
}
>((props, dialogRef) => {
const queryClient = useQueryClient()
const pb = usePocketBase()
const navigate = useNavigate()
const createNotes = useMutation({
Expand All @@ -17,6 +18,7 @@ export const CreateNoteDialog = forwardRef<
},
onSuccess(data) {
if (dialogRef && typeof dialogRef !== 'function') {
queryClient.invalidateQueries({ queryKey: ['notes'] })
dialogRef?.current?.close()
}

Expand Down
10 changes: 10 additions & 0 deletions frontend/pocketbase-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type PocketBase from 'pocketbase'
import type { RecordService } from 'pocketbase'

export enum Collections {
Notes = "notes",
Users = "users",
}

Expand Down Expand Up @@ -33,27 +34,36 @@ export type AuthSystemFields<T = never> = {

// Record types for each collection

export type NotesRecord = {
content?: string
title?: string
}

export type UsersRecord = {
avatar?: string
name?: string
}

// Response types include system fields and match responses from the PocketBase API
export type NotesResponse<Texpand = unknown> = Required<NotesRecord> & BaseSystemFields<Texpand>
export type UsersResponse<Texpand = unknown> = Required<UsersRecord> & AuthSystemFields<Texpand>

// Types containing all Records and Responses, useful for creating typing helper functions

export type CollectionRecords = {
notes: NotesRecord
users: UsersRecord
}

export type CollectionResponses = {
notes: NotesResponse
users: UsersResponse
}

// Type for usage with type asserted PocketBase instance
// https://github.com/pocketbase/js-sdk#specify-typescript-definitions

export type TypedPocketBase = PocketBase & {
collection(idOrName: 'notes'): RecordService<NotesResponse>
collection(idOrName: 'users'): RecordService<UsersResponse>
}
7 changes: 5 additions & 2 deletions frontend/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createFileRoute } from '@tanstack/react-router'
import { z } from 'zod'
import { App } from '../App'

const searchSchema = z.object({
docId: z.string().optional(),
Expand All @@ -12,7 +11,11 @@ export const Route = createFileRoute('/')({
},
component: () => (
<div>
<App />
<h1 className='text-3xl font-bold'>Welcome to pocket-react</h1>
<p className='py-6'>
pocket-react is a starter kit that puts together PocketBase and React
SPA with Vite.
</p>
</div>
),
})

0 comments on commit ba811ac

Please sign in to comment.