update space screen

This commit is contained in:
Ren Amamiya
2023-08-22 09:10:04 +07:00
parent 917e49b25d
commit 4830f0b236
33 changed files with 766 additions and 255 deletions

View File

@@ -1,7 +1,6 @@
import { useStorage } from '@libs/storage/provider';
import { widgetKinds } from '@stores/constants';
import { useWidgets } from '@stores/widgets';
import { WidgetKinds, useWidgets } from '@stores/widgets';
export function Hashtag({ tag }: { tag: string }) {
const { db } = useStorage();
@@ -12,7 +11,7 @@ export function Hashtag({ tag }: { tag: string }) {
type="button"
onClick={() =>
setWidget(db, {
kind: widgetKinds.hashtag,
kind: WidgetKinds.hashtag,
title: tag,
content: tag.replace('#', ''),
})

View File

@@ -8,28 +8,28 @@ import { Image } from '@shared/image';
import { MentionUser, NoteSkeleton } from '@shared/notes';
import { User } from '@shared/user';
import { widgetKinds } from '@stores/constants';
import { useWidgets } from '@stores/widgets';
import { WidgetKinds, useWidgets } from '@stores/widgets';
import { useEvent } from '@utils/hooks/useEvent';
import { isImage } from '@utils/isImage';
export const MentionNote = memo(function MentionNote({ id }: { id: string }) {
const { db } = useStorage();
const { status, data } = useEvent(id);
const { status, data, error } = useEvent(id);
const setWidget = useWidgets((state) => state.setWidget);
const openThread = (event, thread: string) => {
const selection = window.getSelection();
if (selection.toString().length === 0) {
setWidget(db, { kind: widgetKinds.thread, title: 'Thread', content: thread });
setWidget(db, { kind: WidgetKinds.thread, title: 'Thread', content: thread });
} else {
event.stopPropagation();
}
};
const renderItem = useCallback(() => {
if (!data) return;
switch (data.event.kind) {
case 1: {
return (
@@ -85,6 +85,14 @@ export const MentionNote = memo(function MentionNote({ id }: { id: string }) {
);
}
if (error) {
return (
<div className="mb-2 mt-3 cursor-default rounded-lg bg-white/10 px-3 py-3">
<p>Can&apos;t get event from relay</p>
</div>
);
}
return (
<div
onClick={(e) => openThread(e, id)}
@@ -93,7 +101,7 @@ export const MentionNote = memo(function MentionNote({ id }: { id: string }) {
tabIndex={0}
className="mb-2 mt-3 cursor-default rounded-lg bg-white/10 px-3 py-3"
>
<User pubkey={data?.event?.pubkey} time={data?.event?.created_at} size="small" />
<User pubkey={data.event.pubkey} time={data.event.created_at} size="small" />
<div className="mt-2">{renderItem()}</div>
</div>
);

View File

@@ -1,7 +1,6 @@
import { useStorage } from '@libs/storage/provider';
import { widgetKinds } from '@stores/constants';
import { useWidgets } from '@stores/widgets';
import { WidgetKinds, useWidgets } from '@stores/widgets';
import { useProfile } from '@utils/hooks/useProfile';
import { displayNpub } from '@utils/shortenKey';
@@ -17,7 +16,7 @@ export function MentionUser({ pubkey }: { pubkey: string }) {
type="button"
onClick={() =>
setWidget(db, {
kind: widgetKinds.user,
kind: WidgetKinds.user,
title: user?.nip05 || user?.name || user?.display_name,
content: pubkey,
})