wip: refactor chats to use zustand
This commit is contained in:
@@ -1,16 +1,8 @@
|
||||
import ArrowLeftIcon from "@icons/arrowLeft";
|
||||
import ArrowRightIcon from "@icons/arrowRight";
|
||||
import EventCollector from "@shared/eventCollector";
|
||||
import useSWR from "swr";
|
||||
|
||||
const fetcher = async () => {
|
||||
const { platform } = await import("@tauri-apps/api/os");
|
||||
return await platform();
|
||||
};
|
||||
|
||||
export default function AppHeader() {
|
||||
const { data: platform } = useSWR("platform", fetcher);
|
||||
|
||||
export function AppHeader() {
|
||||
const goBack = () => {
|
||||
window.history.back();
|
||||
};
|
||||
@@ -19,10 +11,6 @@ export default function AppHeader() {
|
||||
window.history.forward();
|
||||
};
|
||||
|
||||
const reload = () => {
|
||||
window.location.reload();
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
data-tauri-drag-region
|
||||
|
||||
@@ -2,9 +2,6 @@ import HeartBeatIcon from "@icons/heartbeat";
|
||||
import { RelayContext } from "@shared/relayProvider";
|
||||
import { useActiveAccount } from "@stores/accounts";
|
||||
import { READONLY_RELAYS } from "@stores/constants";
|
||||
import { hasNewerNoteAtom } from "@stores/note";
|
||||
import { TauriEvent } from "@tauri-apps/api/event";
|
||||
import { appWindow, getCurrent } from "@tauri-apps/api/window";
|
||||
import { dateToUnix } from "@utils/date";
|
||||
import {
|
||||
createChat,
|
||||
@@ -13,15 +10,12 @@ import {
|
||||
updateLastLogin,
|
||||
} from "@utils/storage";
|
||||
import { getParentID, nip02ToArray } from "@utils/transform";
|
||||
import { useSetAtom } from "jotai";
|
||||
import { useContext, useEffect, useRef } from "react";
|
||||
import useSWRSubscription from "swr/subscription";
|
||||
|
||||
export default function EventCollector() {
|
||||
const pool: any = useContext(RelayContext);
|
||||
|
||||
const setHasNewerNote = useSetAtom(hasNewerNoteAtom);
|
||||
|
||||
const account = useActiveAccount((state: any) => state.account);
|
||||
const now = useRef(new Date());
|
||||
|
||||
@@ -60,8 +54,6 @@ export default function EventCollector() {
|
||||
event.created_at,
|
||||
parentID,
|
||||
);
|
||||
// notify user reload to get newer note
|
||||
setHasNewerNote(true);
|
||||
break;
|
||||
}
|
||||
// contacts
|
||||
@@ -78,6 +70,7 @@ export default function EventCollector() {
|
||||
account.pubkey,
|
||||
event.pubkey,
|
||||
event.content,
|
||||
event.tags,
|
||||
event.created_at,
|
||||
);
|
||||
break;
|
||||
@@ -106,13 +99,20 @@ export default function EventCollector() {
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
// listen window close event
|
||||
getCurrent().listen(TauriEvent.WINDOW_CLOSE_REQUESTED, () => {
|
||||
// update last login time
|
||||
updateLastLogin(dateToUnix(now.current));
|
||||
// close window
|
||||
appWindow.close();
|
||||
});
|
||||
async function initWindowEvent() {
|
||||
const { TauriEvent } = await import("@tauri-apps/api/event");
|
||||
const { appWindow, getCurrent } = await import("@tauri-apps/api/window");
|
||||
|
||||
// listen window close event
|
||||
getCurrent().listen(TauriEvent.WINDOW_CLOSE_REQUESTED, () => {
|
||||
// update last login time
|
||||
updateLastLogin(dateToUnix(now.current));
|
||||
// close window
|
||||
appWindow.close();
|
||||
});
|
||||
}
|
||||
|
||||
initWindowEvent().catch(console.error);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
|
||||
@@ -2,7 +2,6 @@ import PlusIcon from "@icons/plus";
|
||||
|
||||
import { channelContentAtom } from "@stores/channel";
|
||||
import { chatContentAtom } from "@stores/chat";
|
||||
import { noteContentAtom } from "@stores/note";
|
||||
|
||||
import { createBlobFromFile } from "@utils/createBlobFromFile";
|
||||
|
||||
@@ -15,9 +14,6 @@ export function ImagePicker({ type }: { type: string }) {
|
||||
let atom;
|
||||
|
||||
switch (type) {
|
||||
case "note":
|
||||
atom = noteContentAtom;
|
||||
break;
|
||||
case "chat":
|
||||
atom = chatContentAtom;
|
||||
break;
|
||||
|
||||
@@ -5,7 +5,7 @@ import NavArrowDownIcon from "@icons/navArrowDown";
|
||||
import ThreadsIcon from "@icons/threads";
|
||||
import WorldIcon from "@icons/world";
|
||||
import ActiveLink from "@shared/activeLink";
|
||||
import AppHeader from "@shared/appHeader";
|
||||
import { AppHeader } from "@shared/appHeader";
|
||||
import { ComposerModal } from "@shared/composer/modal";
|
||||
|
||||
export default function Navigation() {
|
||||
|
||||
Reference in New Issue
Block a user