blowater/app/UI/note-card.tsx

57 lines
1.7 KiB
TypeScript
Raw Normal View History

/** @jsx h */
import { h } from "https://esm.sh/preact@10.17.1";
import { ProfileData } from "../features/profile.ts";
2023-11-23 04:28:45 +00:00
import {
cardBackgroundColor,
HintLinkColor,
HintTextColor,
LinkColor,
PrimaryTextColor,
} from "./style/colors.ts";
import { emitFunc } from "../event-bus.ts";
2023-11-23 04:28:45 +00:00
import { OpenNote, ViewUserDetail } from "./message-panel.tsx";
2024-01-01 17:28:10 +00:00
import { NostrEvent } from "../../libs/nostr.ts/nostr.ts";
import { PublicKey } from "../../libs/nostr.ts/key.ts";
export function NoteCard(props: {
profileData?: ProfileData;
event: NostrEvent;
2023-11-23 04:28:45 +00:00
emit: emitFunc<OpenNote | ViewUserDetail>;
publicKey: PublicKey;
}) {
2023-11-23 04:28:45 +00:00
const { profileData, event, emit, publicKey } = props;
const styles = {
container:
2023-12-18 10:23:15 +00:00
`px-4 mb-1 mobile:px-2 py-1 text-[${PrimaryTextColor}] rounded bg-[${cardBackgroundColor}] border-l-2 border-[${HintLinkColor}] w-4/5 mobile:w-full`,
name: `truncate font-bold text-[${LinkColor}] text-base cursor-pointer hover:underline`,
content: `text-sm text-[${HintTextColor}] hover:underline cursor-pointer`,
};
2023-11-23 04:28:45 +00:00
const viewNoteDetail = () =>
emit({
type: "OpenNote",
event: event,
});
2023-11-23 04:28:45 +00:00
const viewUserDetail = () => {
emit({
type: "ViewUserDetail",
pubkey: publicKey,
});
};
2023-11-21 08:44:09 +00:00
const content = event.content.slice(0, 200);
return (
2023-11-23 04:28:45 +00:00
<div class={styles.container}>
<p class={styles.name} onClick={viewUserDetail}>
{profileData?.name || publicKey.bech32()}
</p>
<p onClick={viewNoteDetail} class={styles.content}>
{content}
{event.content.length > 200 ? "..." : ""}
</p>
</div>
);
}