feat: use memo for some components

This commit is contained in:
reya 2024-06-26 17:49:36 +07:00
parent 717c3e17df
commit 5c9b599b1e
6 changed files with 519 additions and 731 deletions

View File

@ -4,14 +4,14 @@ import { cn } from "@lume/utils";
import { invoke } from "@tauri-apps/api/core"; import { invoke } from "@tauri-apps/api/core";
import { listen } from "@tauri-apps/api/event"; import { listen } from "@tauri-apps/api/event";
import { getCurrent } from "@tauri-apps/api/webviewWindow"; import { getCurrent } from "@tauri-apps/api/webviewWindow";
import { useCallback, useEffect, useRef, useState } from "react"; import { memo, useCallback, useEffect, useRef, useState } from "react";
type WindowEvent = { type WindowEvent = {
scroll: boolean; scroll: boolean;
resize: boolean; resize: boolean;
}; };
export function Column({ export const Column = memo(function Column({
column, column,
account, account,
}: { }: {
@ -98,7 +98,7 @@ export function Column({
</div> </div>
</div> </div>
); );
} });
function Header({ label, name }: { label: string; name: string }) { function Header({ label, name }: { label: string; name: string }) {
const [title, setTitle] = useState(name); const [title, setTitle] = useState(name);

View File

@ -1,10 +1,10 @@
import { ThreadIcon } from "@lume/icons";
import { Note } from "@/components/note"; import { Note } from "@/components/note";
import { cn } from "@lume/utils"; import { ThreadIcon } from "@lume/icons";
import type { LumeEvent } from "@lume/system"; import type { LumeEvent } from "@lume/system";
import { useMemo } from "react"; import { cn } from "@lume/utils";
import { memo, useMemo } from "react";
export function Conversation({ export const Conversation = memo(function Conversation({
event, event,
className, className,
}: { }: {
@ -44,4 +44,4 @@ export function Conversation({
</Note.Root> </Note.Root>
</Note.Provider> </Note.Provider>
); );
} });

View File

@ -1,9 +1,10 @@
import { QuoteIcon } from "@lume/icons";
import { Note } from "@/components/note"; import { Note } from "@/components/note";
import { cn } from "@lume/utils"; import { QuoteIcon } from "@lume/icons";
import type { LumeEvent } from "@lume/system"; import type { LumeEvent } from "@lume/system";
import { cn } from "@lume/utils";
import { memo } from "react";
export function Quote({ export const Quote = memo(function Quote({
event, event,
className, className,
}: { }: {
@ -40,4 +41,4 @@ export function Quote({
</Note.Root> </Note.Root>
</Note.Provider> </Note.Provider>
); );
} });

View File

@ -1,11 +1,12 @@
import { Spinner } from "@lume/ui";
import { Note } from "@/components/note"; import { Note } from "@/components/note";
import { User } from "@/components/user"; import { User } from "@/components/user";
import { type LumeEvent, NostrQuery } from "@lume/system";
import { Spinner } from "@lume/ui";
import { cn } from "@lume/utils"; import { cn } from "@lume/utils";
import { useQuery } from "@tanstack/react-query"; import { useQuery } from "@tanstack/react-query";
import { type LumeEvent, NostrQuery } from "@lume/system"; import { memo } from "react";
export function RepostNote({ export const RepostNote = memo(function RepostNote({
event, event,
className, className,
}: { }: {
@ -78,4 +79,4 @@ export function RepostNote({
)} )}
</Note.Root> </Note.Root>
); );
} });

View File

@ -1,14 +1,17 @@
import { cn } from "@lume/utils";
import { Note } from "@/components/note"; import { Note } from "@/components/note";
import type { LumeEvent } from "@lume/system"; import type { LumeEvent } from "@lume/system";
import { cn } from "@lume/utils";
import { memo } from "react";
export function TextNote({ export const TextNote = memo(function TextNote({
event, event,
className, className,
}: { }: {
event: LumeEvent; event: LumeEvent;
className?: string; className?: string;
}) { }) {
console.log("Rendered at: ", event.id, new Date().toLocaleTimeString());
return ( return (
<Note.Provider event={event}> <Note.Provider event={event}>
<Note.Root <Note.Root
@ -31,4 +34,4 @@ export function TextNote({
</Note.Root> </Note.Root>
</Note.Provider> </Note.Provider>
); );
} });

File diff suppressed because it is too large Load Diff