Upgrade database schema to version 2 and remove unused meta_* columns
- Increment `SCHEMA_VERSION` to 2 in `schema.ts`. - Remove all `meta_*` columns from database tables. - Add migration logic to handle schema upgrades and clean up unused columns. - Modify database models and repository methods to exclude `meta_*` fields for stricter typings and improved structure. - Refactor and optimize query statements across repositories to align with new schema changes.
This commit is contained in:
@@ -11,10 +11,12 @@ import AlertBox from "@/components/AlertBox";
|
||||
import {useTranslations} from "next-intl";
|
||||
import InlineAddInput from "@/components/form/InlineAddInput";
|
||||
import {LangContext} from "@/context/LangContext";
|
||||
import OfflineContext, {OfflineContextType} from "@/context/OfflineContext";
|
||||
|
||||
export default function ScribeChapterComponent() {
|
||||
const t = useTranslations();
|
||||
const {lang} = useContext(LangContext)
|
||||
const {lang} = useContext(LangContext);
|
||||
const {isCurrentlyOffline} = useContext<OfflineContextType>(OfflineContext);
|
||||
|
||||
const {book} = useContext(BookContext);
|
||||
const {chapter, setChapter} = useContext(ChapterContext);
|
||||
@@ -43,18 +45,16 @@ export default function ScribeChapterComponent() {
|
||||
|
||||
useEffect((): void => {
|
||||
if (chapter?.chapterId && scrollContainerRef.current) {
|
||||
// Small delay to ensure DOM is ready
|
||||
setTimeout(() => {
|
||||
const element = chapterRefs.current.get(chapter.chapterId);
|
||||
const container = scrollContainerRef.current;
|
||||
|
||||
if (element && container) {
|
||||
const containerRect = container.getBoundingClientRect();
|
||||
const elementRect = element.getBoundingClientRect();
|
||||
const containerRect:DOMRect = container.getBoundingClientRect();
|
||||
const elementRect:DOMRect = element.getBoundingClientRect();
|
||||
|
||||
// Calculate relative position
|
||||
const relativeTop = elementRect.top - containerRect.top + container.scrollTop;
|
||||
const scrollPosition = relativeTop - (containerRect.height / 2) + (elementRect.height / 2);
|
||||
const relativeTop:number = elementRect.top - containerRect.top + container.scrollTop;
|
||||
const scrollPosition:number = relativeTop - (containerRect.height / 2) + (elementRect.height / 2);
|
||||
|
||||
container.scrollTo({
|
||||
top: Math.max(0, scrollPosition),
|
||||
@@ -72,7 +72,12 @@ export default function ScribeChapterComponent() {
|
||||
|
||||
async function getChapterList(): Promise<void> {
|
||||
try {
|
||||
const response: ChapterListProps[] = await System.authGetQueryToServer<ChapterListProps[]>(`book/chapters?id=${book?.bookId}`, userToken, lang);
|
||||
let response: ChapterListProps[]|null;
|
||||
if (isCurrentlyOffline()){
|
||||
response = await window.electron.invoke<ChapterListProps[]>('db:book:chapters', book?.bookId)
|
||||
} else {
|
||||
response = await System.authGetQueryToServer<ChapterListProps[]>(`book/chapters?id=${book?.bookId}`, userToken, lang);
|
||||
}
|
||||
if (response) {
|
||||
setChapters(response);
|
||||
}
|
||||
@@ -88,11 +93,20 @@ export default function ScribeChapterComponent() {
|
||||
async function getChapter(chapterId: string): Promise<void> {
|
||||
const version: number = chapter?.chapterContent.version ? chapter?.chapterContent.version : 2;
|
||||
try {
|
||||
const response: ChapterProps = await System.authGetQueryToServer<ChapterProps>(`chapter/whole`, userToken, lang, {
|
||||
bookid: book?.bookId,
|
||||
id: chapterId,
|
||||
version: version,
|
||||
});
|
||||
let response: ChapterProps | null = null
|
||||
if (isCurrentlyOffline()) {
|
||||
response = await window.electron.invoke<ChapterProps>('db:chapter:whole', {
|
||||
bookid: book?.bookId,
|
||||
id: chapterId,
|
||||
version: version,
|
||||
})
|
||||
} else {
|
||||
response = await System.authGetQueryToServer<ChapterProps>(`chapter/whole`, userToken, lang, {
|
||||
bookid: book?.bookId,
|
||||
id: chapterId,
|
||||
version: version,
|
||||
});
|
||||
}
|
||||
if (!response) {
|
||||
errorMessage(t("scribeChapterComponent.errorFetchChapter"));
|
||||
return;
|
||||
@@ -173,11 +187,20 @@ export default function ScribeChapterComponent() {
|
||||
}
|
||||
const chapterTitle: string = chapterOrder >= 0 ? newChapterName : book?.title as string;
|
||||
try {
|
||||
const chapterId: string = await System.authPostToServer<string>('chapter/add', {
|
||||
bookId: book?.bookId,
|
||||
chapterOrder: chapterOrder,
|
||||
title: chapterTitle
|
||||
}, userToken, lang);
|
||||
let chapterId:string|null = null;
|
||||
if (isCurrentlyOffline()){
|
||||
chapterId = await window.electron.invoke<string>('db:chapter:create', {
|
||||
bookId: book?.bookId,
|
||||
chapterOrder: chapterOrder,
|
||||
title: chapterTitle
|
||||
})
|
||||
} else {
|
||||
chapterId = await System.authPostToServer<string>('chapter/add', {
|
||||
bookId: book?.bookId,
|
||||
chapterOrder: chapterOrder,
|
||||
title: chapterTitle
|
||||
}, userToken, lang);
|
||||
}
|
||||
if (!chapterId) {
|
||||
errorMessage(t("scribeChapterComponent.errorChapterSubmit", {chapterName: newChapterName}));
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user