This commit is contained in:
louiscklaw
2025-04-26 07:44:55 +08:00
parent 9be92b41d1
commit caa224cbb6
4 changed files with 24 additions and 18 deletions

View File

@@ -48,7 +48,7 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
const [rowsPerPage, setRowsPerPage] = React.useState<number>(5);
//
const [f, setF] = React.useState<Vocabulary[]>([]);
const [currentPage, setCurrentPage] = React.useState<number>(1);
const [currentPage, setCurrentPage] = React.useState<number>(0);
//
const [recordCount, setRecordCount] = React.useState<number>(0);
const [listOption, setListOption] = React.useState({});
@@ -57,12 +57,14 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
//
const reloadRows = async (): Promise<void> => {
try {
const models: ListResult<RecordModel> = await pb.collection(COL_VOCABULARIES).getList(1, 5, {
expand: 'cat_id',
});
const models: ListResult<RecordModel> = await pb
.collection(COL_VOCABULARIES)
.getList(currentPage + 1, rowsPerPage, {
...listOption,
expand: 'cat_id',
});
const { items, totalItems } = models;
const tempVocabularies: Vocabulary[] = items.map((v) => {
return { ...defaultVocabulary, ...v };
});

View File

@@ -27,16 +27,17 @@ export interface Vocabulary {
// RULES: for use with vocabulary-create-form.tsx
// when you update, please take a look into `vocabulary-create-form.tsx`
export interface CreateForm {
image?: string;
sound?: string;
word?: string;
word_c?: string;
sample_e?: string;
sample_c?: string;
cat_id?: string;
category?: string;
lesson_type_id?: string;
export interface CreateFormProps {
image: File[] | null;
sound: string;
word: string;
word_c: string;
sample_e: string;
sample_c: string;
cat_id: string;
category: string;
lesson_type_id: string;
visible: string;
}
// RULES: for use with vocabulary-edit-form.tsx
@@ -51,6 +52,7 @@ export interface EditFormProps {
cat_id: string;
category: string;
lesson_type_id: string;
visible: string;
}
// RULES:

View File

@@ -37,7 +37,7 @@ import { toast } from '@/components/core/toaster';
import FormLoading from '@/components/loading';
import ErrorDisplay from '../error';
import type { EditFormProps } from './type';
import type { CreateFormProps, EditFormProps } from './type';
import { listLessonCategories } from '@/db/LessonCategories/listLessonCategories';
import isDevelopment from '@/lib/check-is-development';
@@ -94,7 +94,7 @@ export function VocabularyCreateForm(): React.JSX.Element {
async (values: Values): Promise<void> => {
setIsCreating(true);
const tempUpdate: EditFormProps = {
const tempUpdate: CreateFormProps = {
image: values.avatar ? [await base64ToFile(values.avatar)] : null,
sound: '',
word: values.word,
@@ -104,13 +104,14 @@ export function VocabularyCreateForm(): React.JSX.Element {
cat_id: values.cat_id,
category: '',
lesson_type_id: '',
visible: values.visible,
};
try {
const result = await pb.collection(COL_VOCABULARIES).create(tempUpdate);
logger.debug(result);
toast.success(t('create.success'));
// router.push(paths.dashboard.lesson_categories.details('1'));
router.push(paths.dashboard.vocabularies.list);
} catch (err) {
logger.error(err);
toast.error(t('create.failed'));

View File

@@ -101,6 +101,7 @@ export function VocabularyEditForm(): React.JSX.Element {
cat_id: values.cat_id,
category: '',
lesson_type_id: '',
visible: values.visible,
};
//
try {