fix small errors
This commit is contained in:
@@ -15,11 +15,11 @@ button {
|
||||
}
|
||||
|
||||
.markdown {
|
||||
@apply prose prose-zinc max-w-none select-text break-words dark:prose-invert prose-p:mb-2 prose-p:mt-0 prose-p:last:mb-0 prose-a:break-all prose-a:font-normal prose-a:leading-tight prose-a:text-fuchsia-400 hover:prose-a:text-fuchsia-500 prose-blockquote:m-0 prose-ol:m-0 prose-ol:mb-1 prose-ul:mb-1 prose-li:leading-tight prose-img:mt-1.5 prose-img:mb-1 prose-hr:mx-0 prose-hr:my-2;
|
||||
@apply prose prose-zinc max-w-none select-text break-words dark:prose-invert prose-p:mb-2 prose-p:mt-0 prose-p:last:mb-0 prose-a:break-all prose-a:font-normal prose-a:leading-tight prose-a:text-fuchsia-400 hover:prose-a:text-fuchsia-500 prose-blockquote:m-0 prose-ol:m-0 prose-ol:mb-1 prose-ul:mb-1 prose-li:leading-tight prose-img:mt-3 prose-img:mb-2 prose-hr:mx-0 prose-hr:my-2;
|
||||
}
|
||||
|
||||
.ProseMirror p.is-empty::before {
|
||||
@apply text-zinc-400;
|
||||
@apply text-zinc-500;
|
||||
content: attr(data-placeholder);
|
||||
float: left;
|
||||
height: 0;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import destr from 'destr';
|
||||
import Database from 'tauri-plugin-sql-api';
|
||||
|
||||
import { parser } from '@utils/parser';
|
||||
import { getParentID } from '@utils/transform';
|
||||
import { Account, Block, Chats, LumeEvent, Profile, Settings } from '@utils/types';
|
||||
|
||||
@@ -160,8 +161,16 @@ export async function getNotesByAuthors(authors: string, limit: number, offset:
|
||||
// get note by id
|
||||
export async function getNoteByID(event_id: string) {
|
||||
const db = await connect();
|
||||
const result = await db.select(`SELECT * FROM notes WHERE event_id = "${event_id}";`);
|
||||
return result[0];
|
||||
const result: LumeEvent[] = await db.select(
|
||||
`SELECT * FROM notes WHERE event_id = "${event_id}";`
|
||||
);
|
||||
if (result[0]) {
|
||||
// @ts-expect-error, todo
|
||||
if (result[0].kind === 1) result[0]['content'] = parser(result[0]);
|
||||
return result[0];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// create note
|
||||
@@ -458,8 +467,11 @@ export async function getAllMetadata() {
|
||||
const profile: Profile = destr(el.content);
|
||||
return {
|
||||
pubkey: el.pubkey,
|
||||
ident: profile.name || profile.display_name || profile.username,
|
||||
picture: profile.picture || profile.image,
|
||||
ident: profile.name || profile.display_name || profile.username || 'anon',
|
||||
picture:
|
||||
profile.picture ||
|
||||
profile.image ||
|
||||
'https://void.cat/d/5VKmKyuHyxrNMf9bWSVPih.jpg',
|
||||
};
|
||||
});
|
||||
return users;
|
||||
@@ -470,7 +482,7 @@ export async function getUserMetadata(pubkey: string) {
|
||||
const db = await connect();
|
||||
const result = await db.select(`SELECT * FROM metadata WHERE pubkey = "${pubkey}";`);
|
||||
if (result[0]) {
|
||||
return result[0];
|
||||
return JSON.parse(result[0].content) as Profile;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import { TauriEvent } from '@tauri-apps/api/event';
|
||||
import { getCurrent } from '@tauri-apps/api/window';
|
||||
import Image from '@tiptap/extension-image';
|
||||
import Mention from '@tiptap/extension-mention';
|
||||
import Placeholder from '@tiptap/extension-placeholder';
|
||||
@@ -7,7 +5,7 @@ import { EditorContent, useEditor } from '@tiptap/react';
|
||||
import StarterKit from '@tiptap/starter-kit';
|
||||
import { convert } from 'html-to-text';
|
||||
import { nip19 } from 'nostr-tools';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useState } from 'react';
|
||||
import { twMerge } from 'tailwind-merge';
|
||||
|
||||
import { Button } from '@shared/button';
|
||||
@@ -24,11 +22,7 @@ import { sendNativeNotification } from '@utils/notification';
|
||||
|
||||
export function Composer() {
|
||||
const [status, setStatus] = useState<null | 'loading' | 'done'>(null);
|
||||
const [reply, clearReply, toggleModal] = useComposer((state) => [
|
||||
state.reply,
|
||||
state.clearReply,
|
||||
state.toggleModal,
|
||||
]);
|
||||
const [reply, clearReply] = useComposer((state) => [state.reply, state.clearReply]);
|
||||
|
||||
const editor = useEditor({
|
||||
extensions: [
|
||||
@@ -110,22 +104,17 @@ export function Composer() {
|
||||
|
||||
// update state
|
||||
setStatus('done');
|
||||
// reset editor
|
||||
editor.commands.clearContent();
|
||||
if (reply.id) {
|
||||
clearReply();
|
||||
}
|
||||
} catch {
|
||||
setStatus(null);
|
||||
console.log('failed to publish');
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
getCurrent().listen(TauriEvent.WINDOW_FILE_DROP, (event) => {
|
||||
const filepath: string = event.payload[0];
|
||||
if (filepath.match(/\.(jpg|jpeg|png|gif)$/gi)) {
|
||||
// open modal
|
||||
toggleModal(true);
|
||||
}
|
||||
});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col px-4 pb-4">
|
||||
<div className="flex h-full w-full gap-3">
|
||||
|
||||
@@ -29,7 +29,7 @@ export function ComposerModal() {
|
||||
return (
|
||||
<>
|
||||
<Button onClick={() => toggle(true)} preset="small">
|
||||
<ComposeIcon width={14} height={14} />
|
||||
<ComposeIcon className="h-4 w-4" />
|
||||
Compose
|
||||
</Button>
|
||||
<Transition appear show={open} as={Fragment}>
|
||||
@@ -68,7 +68,7 @@ export function ComposerModal() {
|
||||
</span>
|
||||
<div className="inline-flex h-7 w-max items-center justify-center gap-0.5 rounded bg-zinc-800 pl-3 pr-1.5 text-sm font-medium text-zinc-400">
|
||||
New Post
|
||||
<ChevronDownIcon width={14} height={14} />
|
||||
<ChevronDownIcon className="h-4 w-4" />
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
|
||||
@@ -35,13 +35,13 @@ export function NoteContent({
|
||||
},
|
||||
}}
|
||||
>
|
||||
{content.parsed}
|
||||
{content?.parsed}
|
||||
</ReactMarkdown>
|
||||
{content.images?.length > 0 && <ImagePreview urls={content.images} />}
|
||||
{content.videos?.length > 0 && <VideoPreview urls={content.videos} />}
|
||||
{content.links?.length > 0 && <LinkPreview urls={content.links} />}
|
||||
{content.notes?.length > 0 &&
|
||||
content.notes.map((note: string) => <MentionNote key={note} id={note} />)}
|
||||
{content?.images?.length > 0 && <ImagePreview urls={content.images} />}
|
||||
{content?.videos?.length > 0 && <VideoPreview urls={content.videos} />}
|
||||
{content?.links?.length > 0 && <LinkPreview urls={content.links} />}
|
||||
{content?.notes?.length > 0 &&
|
||||
content?.notes.map((note: string) => <MentionNote key={note} id={note} />)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,58 +7,46 @@ import { parser } from '@utils/parser';
|
||||
|
||||
export function useEvent(id: string, fallback?: string) {
|
||||
const { ndk } = useNDK();
|
||||
const { status, data, error, isFetching } = useQuery(
|
||||
['note', id],
|
||||
async () => {
|
||||
const result = await getNoteByID(id);
|
||||
if (result) {
|
||||
if (result.kind === 1) {
|
||||
result['content'] = parser(result);
|
||||
}
|
||||
return result;
|
||||
const { status, data, error, isFetching } = useQuery(['note', id], async () => {
|
||||
const result = await getNoteByID(id);
|
||||
if (result) {
|
||||
return result;
|
||||
} else {
|
||||
if (fallback) {
|
||||
const embed = JSON.parse(fallback);
|
||||
await createNote(
|
||||
embed.id,
|
||||
embed.pubkey,
|
||||
embed.kind,
|
||||
embed.tags,
|
||||
embed.content,
|
||||
embed.created_at
|
||||
);
|
||||
return embed;
|
||||
} else {
|
||||
if (fallback) {
|
||||
const embed = JSON.parse(fallback);
|
||||
const event = await ndk.fetchEvent(id);
|
||||
if (event) {
|
||||
await createNote(
|
||||
embed.id,
|
||||
embed.pubkey,
|
||||
embed.kind,
|
||||
embed.tags,
|
||||
embed.content,
|
||||
embed.created_at
|
||||
event.id,
|
||||
event.pubkey,
|
||||
event.kind,
|
||||
event.tags,
|
||||
event.content,
|
||||
event.created_at
|
||||
);
|
||||
return embed;
|
||||
} else {
|
||||
const event = await ndk.fetchEvent(id);
|
||||
if (event) {
|
||||
await createNote(
|
||||
event.id,
|
||||
event.pubkey,
|
||||
event.kind,
|
||||
event.tags,
|
||||
event.content,
|
||||
event.created_at
|
||||
);
|
||||
event['event_id'] = event.id;
|
||||
if (event.kind === 1) {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
event['content'] = parser(event);
|
||||
}
|
||||
return event;
|
||||
} else {
|
||||
throw new Error('Event not found');
|
||||
event['event_id'] = event.id;
|
||||
if (event.kind === 1) {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
event['content'] = parser(event);
|
||||
}
|
||||
return event;
|
||||
} else {
|
||||
throw new Error('Event not found');
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
refetchOnWindowFocus: false,
|
||||
refetchOnMount: false,
|
||||
refetchOnReconnect: false,
|
||||
staleTime: Infinity,
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
return { status, data, error, isFetching };
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ export function useProfile(pubkey: string, fallback?: string) {
|
||||
const current = Math.floor(Date.now() / 1000);
|
||||
const cache = await getUserMetadata(pubkey);
|
||||
if (cache && parseInt(cache.created_at) + 86400 >= current) {
|
||||
console.log('cache hit:', cache);
|
||||
return JSON.parse(cache.content);
|
||||
} else {
|
||||
const filter: NDKFilter = { kinds: [0], authors: [pubkey] };
|
||||
@@ -27,7 +28,7 @@ export function useProfile(pubkey: string, fallback?: string) {
|
||||
await createMetadata(latest.id, latest.pubkey, latest.content);
|
||||
return JSON.parse(latest.content);
|
||||
} else {
|
||||
return null;
|
||||
throw new Error('User not found');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -38,7 +39,6 @@ export function useProfile(pubkey: string, fallback?: string) {
|
||||
{
|
||||
refetchOnWindowFocus: false,
|
||||
refetchOnReconnect: false,
|
||||
staleTime: Infinity,
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user