feat: improve performance (#234)

* feat: use negentropy as much as possible

* update

* update
This commit is contained in:
雨宮蓮
2024-09-29 16:53:39 +07:00
committed by GitHub
parent afa9327bb7
commit f0fc89724d
26 changed files with 566 additions and 373 deletions

View File

@@ -224,7 +224,7 @@ function ReplyList() {
{isLoading ? (
<div className="flex items-center justify-center w-full mb-3 h-12 bg-black/5 dark:bg-white/5 rounded-xl">
<div className="flex items-center justify-center gap-2">
<Spinner className="size-5" />
<Spinner className="size-4" />
<span className="text-sm font-medium">Getting replies...</span>
</div>
</div>

View File

@@ -48,7 +48,7 @@ export function Screen() {
initialPageParam: 0,
queryFn: async ({ pageParam }: { pageParam: number }) => {
const until = pageParam > 0 ? pageParam.toString() : undefined;
const res = await commands.getEventsFromContacts(until);
const res = await commands.getLocalEvents(until);
if (res.status === "error") {
throw new Error(res.error);

View File

@@ -11,7 +11,7 @@ export const Route = createLazyFileRoute("/columns/_layout/trending")({
component: Screen,
});
export function Screen() {
function Screen() {
const { isLoading, isError, data } = useQuery({
queryKey: ["trending-notes"],
queryFn: async ({ signal }) => {

View File

@@ -64,11 +64,21 @@ function Screen() {
appSettings.setState(() => settings.data);
}
navigate({
to: "/$account/home",
params: { account: res.data },
replace: true,
});
const status = await commands.isAccountSync(res.data);
if (status) {
navigate({
to: "/$account/home",
params: { account: res.data },
replace: true,
});
} else {
navigate({
to: "/loading",
search: { account: res.data },
replace: true,
});
}
} else {
await message(res.error, { title: "Login", kind: "error" });
return;

47
src/routes/loading.tsx Normal file
View File

@@ -0,0 +1,47 @@
import { Spinner } from "@/components";
import { createFileRoute } from "@tanstack/react-router";
import { listen } from "@tauri-apps/api/event";
import { useEffect } from "react";
type RouteSearch = {
account: string;
};
export const Route = createFileRoute("/loading")({
validateSearch: (search: Record<string, string>): RouteSearch => {
return {
account: search.account,
};
},
component: Screen,
});
function Screen() {
const navigate = Route.useNavigate();
const search = Route.useSearch();
useEffect(() => {
const unlisten = listen("synchronized", () => {
navigate({
to: "/$account/home",
params: { account: search.account },
replace: true,
});
});
return () => {
unlisten.then((f) => f());
};
}, []);
return (
<div className="size-full flex items-center justify-center">
<div className="flex flex-col gap-2 items-center justify-center text-center">
<Spinner />
<p className="text-sm">
Fetching necessary data for the first time login...
</p>
</div>
</div>
);
}