Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Production deployment #49

Merged
merged 4 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9,971 changes: 0 additions & 9,971 deletions data/author-bios.json

This file was deleted.

803 changes: 0 additions & 803 deletions data/distinct-genres.json

This file was deleted.

3,539 changes: 0 additions & 3,539 deletions data/distinct-locations-with-regions.json

This file was deleted.

467 changes: 0 additions & 467 deletions data/distinct-locations.json

This file was deleted.

158 changes: 0 additions & 158 deletions data/regions.json

This file was deleted.

12 changes: 12 additions & 0 deletions public/sitemap.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
<loc>https://usul.ai/sitemap/1.xml</loc>
<lastmod>2024-12-19T12:00:00Z</lastmod>
</sitemap>

<sitemap>
<loc>https://usul.ai/sitemap/2.xml</loc>
<lastmod>2024-12-19T12:00:00Z</lastmod>
</sitemap>
</sitemapindex>
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ function PageReference({
...props
}: PageReferenceProps) {
const number = props["data-number"];
const idx = Number(number) - 1;

const idx = Number(number) - 1;
const sourceNode = sourceNodes[idx]!;

return (
Expand Down
4 changes: 2 additions & 2 deletions src/app/[locale]/t/[bookId]/_components/ai-tab/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import SidebarContainer from "../sidebar/sidebar-container";
import { Badge } from "@/components/ui/badge";
import { OpenAILogo } from "@/components/Icons";

export default function AITab({ bookSlug, bookResponse }: TabProps) {
export default function AITab({ bookResponse }: TabProps) {
const { getVirtuosoScrollProps } = usePageNavigation(bookResponse);
const t = useTranslations();
const {
Expand All @@ -38,7 +38,7 @@ export default function AITab({ bookSlug, bookResponse }: TabProps) {
messages,
clearChat,
regenerateResponse,
} = useChat({ bookSlug: bookSlug });
} = useChat({ bookId: bookResponse.book.id });

const onSubmit = useCallback(async () => {
await sendQuestion();
Expand Down
14 changes: 5 additions & 9 deletions src/app/[locale]/t/[bookId]/_components/ai-tab/useChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,7 @@ const handleEventSource = async (
});
};

export default function useChat({
bookSlug,
}: {
bookSlug: string;
}): UseChatResult {
export default function useChat({ bookId }: { bookId: string }): UseChatResult {
const {
messages,
setMessages,
Expand All @@ -100,7 +96,7 @@ export default function useChat({

try {
const { eventSource, messageId } = await chatWithBook({
bookSlug,
bookId,
question: q,
messages,
});
Expand All @@ -119,7 +115,7 @@ export default function useChat({

setIsPending(false);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [bookSlug, question]);
}, [bookId, question]);

const regenerateResponse = useCallback(
async (messageIndex?: number) => {
Expand Down Expand Up @@ -149,7 +145,7 @@ export default function useChat({

try {
const { eventSource, messageId } = await chatWithBook({
bookSlug,
bookId,
question: question.text,
messages: previousMessages,
});
Expand All @@ -167,7 +163,7 @@ export default function useChat({

setIsPending(false);
},
[bookSlug, messages],
[bookId, messages],
);

return {
Expand Down
54 changes: 41 additions & 13 deletions src/app/[locale]/t/[bookId]/_components/search-tab/SearchResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ import { useBookShareUrl } from "@/lib/share";
import Spinner from "@/components/ui/spinner";
import { useRouter } from "@/navigation";
import { navigation } from "@/lib/urls";
import type { OpenitiContent } from "@/types/api/content/openiti";
import type { TurathContent } from "@/types/api/content/turath";

const SearchResult = ({
result,
getVirtuosoScrollProps,
headings,
}: {
result: SemanticSearchBookNode;
getVirtuosoScrollProps: UsePageNavigationReturnType["getVirtuosoScrollProps"];
headings: OpenitiContent["headings"] | TurathContent["headings"];
}) => {
const virtuosoRef = useReaderVirtuoso();
const mobileSidebar = useMobileSidebar();
Expand Down Expand Up @@ -56,16 +60,21 @@ const SearchResult = ({
const handleNavigate = async () => {
if (!page || page.page === -1 || isPending) return;

const result = await mutateAsync({ page: page.page, vol: page.vol });

if (!result || result.index === null) return;
let index: number;
if ("index" in page) {
index = page.index as number;
} else {
const result = await mutateAsync({ page: page.page, vol: page.volume });
if (!result || result.index === null) return;
index = result.index;
}

if (isSinglePage) {
router.push(
`${navigation.books.pageReader(slug, result.index + 1)}${searchParams.size > 0 ? `?${searchParams.toString()}` : ""}`,
`${navigation.books.pageReader(slug, index + 1)}${searchParams.size > 0 ? `?${searchParams.toString()}` : ""}`,
);
} else {
const props = getVirtuosoScrollProps(result.index);
const props = getVirtuosoScrollProps(index);
virtuosoRef.current?.scrollToIndex(props.index, { align: props.align });
}

Expand All @@ -76,11 +85,14 @@ const SearchResult = ({
if (!page || page.page === -1 || isPending) return;

let idx: number;
if (data) {

if ("index" in page) {
idx = page.index as number;
} else if (data) {
if (data.index === null) return;
idx = data.index;
} else {
const result = await mutateAsync({ page: page.page, vol: page.vol });
const result = await mutateAsync({ page: page.page, vol: page.volume });
if (!result || result.index === null) return;
idx = result.index;
}
Expand All @@ -92,7 +104,14 @@ const SearchResult = ({
});
};

const content = removeDiacritics(result.text);
const content =
result.highlights && result.highlights.length > 0
? result.highlights.join("<br>...<br>")
: removeDiacritics(result.text);

const chapter = result.metadata.chapters.at(-1);
// const volume =
// page && (("volume" in page ? page.volume : page.vol) as string | undefined);

return (
<div
Expand All @@ -119,9 +138,15 @@ const SearchResult = ({
</Button>
</div>

<div className="flex gap-2">
<p>{result.metadata.chapters.at(-1)}</p>
</div>
{chapter && (
<div className="flex max-w-[80%] gap-2" dir="rtl">
<p>
{typeof chapter === "number"
? headings?.[chapter]?.title
: chapter}
</p>
</div>
)}
</div>

<p
Expand All @@ -139,8 +164,11 @@ const SearchResult = ({
matchRate: Math.floor(result.score * 100),
})}
</span>
) : null}
<p> {t("common.pagination.page-x", { page: page ? page.page : -1 })}</p>
) : (
<span />
)}

<p>{t("common.pagination.page-x", { page: page ? page.page : -1 })}</p>
</div>
</div>
);
Expand Down
Loading