Skip to content

Commit c580260

Browse files
authored
Latest posts highlighting (#143)
1 parent 2746469 commit c580260

File tree

9 files changed

+51
-133
lines changed

9 files changed

+51
-133
lines changed

app/NoteDisplay.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const NoteDisplay = ({ event }: any) => {
6565
/>
6666
<div className="grow">
6767
<CodeEditor
68-
className={`w-full focus:border focus:border-blue-500 p-3 outline-none min-h-full "note-cursor-text"`}
68+
className="w-full focus:border focus:border-blue-500 p-3 outline-none min-h-full note-cursor-text"
6969
value={event.content}
7070
language={event.tags[0][1]}
7171
autoCapitalize="none"

app/Posts.tsx

+1-22
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,18 @@
11
import { HTMLAttributes, ReactNode, useContext } from "react";
2-
import Button from "./Button";
3-
import { PostDirContext } from "./context/post-dir-provider";
4-
import { CardCol, CardRow } from "./icons";
52

63
interface PostsProps extends HTMLAttributes<HTMLDivElement> {
74
children: ReactNode;
85
title: string;
9-
noPosts?: boolean;
106
}
117

12-
const Posts = ({
13-
title,
14-
noPosts,
15-
children,
16-
className,
17-
...props
18-
}: PostsProps) => {
19-
const { isCol, togglePostDir } = useContext(PostDirContext);
8+
const Posts = ({ title, children, className, ...props }: PostsProps) => {
209
return (
2110
<div
2211
className={`flex flex-col justify-center gap-3 px-2 w-full max-w-[50rem] mx-auto ${className}`}
2312
{...props}
2413
>
2514
<div className="flex items-center justify-between gap-4">
2615
<h1 className="text-3xl">{title}</h1>
27-
{noPosts ? null : (
28-
<Button
29-
className="hidden md:block"
30-
color="neutralLight"
31-
variant="ghost"
32-
size="sm"
33-
icon={isCol ? <CardCol /> : <CardRow />}
34-
onClick={() => togglePostDir()}
35-
/>
36-
)}
3716
</div>
3817
{children}
3918
</div>

app/context/post-dir-provider.tsx

-35
This file was deleted.

app/context/providers.jsx

+1-4
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@ import KeysProvider from "./keys-provider.jsx";
55
import { CustomThemeProvider } from "./theme-provider";
66
import { NostrProvider } from "nostr-react";
77
import { RELAYS } from "../utils/constants";
8-
import PostDirProvider from "./post-dir-provider";
98

109
export default function Providers({ children }) {
1110
return (
1211
<NostrProvider relayUrls={RELAYS} debug={false}>
1312
<EventProvider>
1413
<KeysProvider>
15-
<PostDirProvider>
16-
<CustomThemeProvider>{children}</CustomThemeProvider>
17-
</PostDirProvider>
14+
<CustomThemeProvider>{children}</CustomThemeProvider>
1815
</KeysProvider>
1916
</EventProvider>
2017
</NostrProvider>

app/icons/CardCol.tsx

-12
This file was deleted.

app/icons/CardRow.tsx

-12
This file was deleted.

app/icons/index.tsx

-2
This file was deleted.

app/u/[npub]/Card.tsx

+48-44
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
import Link from "next/link";
2+
import dynamic from "next/dynamic";
23
import { useProfile } from "nostr-react";
34
import { Event, nip19 } from "nostr-tools";
4-
import {
5-
DetailedHTMLProps,
6-
FC,
7-
LiHTMLAttributes,
8-
ReactNode,
9-
useContext,
10-
} from "react";
5+
import { DetailedHTMLProps, FC, LiHTMLAttributes, ReactNode } from "react";
116
import { BsFillFileEarmarkCodeFill, BsFillTagFill } from "react-icons/bs";
127
import { FaCalendarAlt } from "react-icons/fa";
138
import { DUMMY_PROFILE_API } from "../../utils/constants";
149
import { shortenHash } from "../../lib/utils";
15-
import { PostDirContext } from "../../context/post-dir-provider";
1610
import { getTagValues } from "../../lib/utils";
11+
import "@uiw/react-textarea-code-editor/dist.css";
1712

1813
interface NoteProps
1914
extends DetailedHTMLProps<LiHTMLAttributes<HTMLLIElement>, HTMLLIElement> {
@@ -22,51 +17,49 @@ interface NoteProps
2217
dateOnly?: boolean;
2318
}
2419

20+
const CodeEditor = dynamic(
21+
() => import("@uiw/react-textarea-code-editor").then((mod) => mod.default),
22+
{ ssr: true }
23+
);
24+
2525
const Card: FC<NoteProps> = ({
2626
event,
2727
profile = false,
2828
dateOnly = false,
2929
...props
3030
}) => {
3131
const { tags, content, created_at: createdAt, id: noteId } = event;
32-
const { isCol } = useContext(PostDirContext);
3332

3433
const { data } = useProfile({
3534
pubkey: event.pubkey,
3635
});
3736

3837
const npub = nip19.npubEncode(event.pubkey);
3938

40-
// let actualTags: any = getTagValues("tags");
39+
const title = getTagValues("subject", tags);
40+
const filetype = getTagValues("filetype", tags);
41+
const actualTags = getTagValues("tags", tags);
4142

42-
// if (actualTags) {
43-
// actualTags = actualTags.split(",");
44-
// }
43+
function setupMarkdown(content: string) {
44+
var md = require("markdown-it")();
45+
var result = md.render(content);
46+
return result;
47+
}
4548

46-
const title = getTagValues("subject", tags);
47-
const markdownImageContent =
48-
/!\[[^\]]*\]\((?<filename>.*?)(?=\"|\))(?<title>\".*\")?\)/g.exec(content);
49+
const MAX_LENGTH = 300;
50+
51+
const markdown =
52+
content.length > MAX_LENGTH
53+
? setupMarkdown(content.slice(0, MAX_LENGTH)).concat("...read more")
54+
: setupMarkdown(content.slice(0, MAX_LENGTH));
4955

5056
return (
5157
<li
5258
className="rounded-md hover:shadow-sm hover:scale-101 transition-transform hover:shadow-accent bg-secondary text-accent text-left"
5359
{...props}
5460
>
55-
<Link
56-
href={`/${nip19.noteEncode(noteId!)}`}
57-
className={`p-5 flex gap-4 justify-between flex-col-reverse ${
58-
isCol ? "" : "md:flex-row"
59-
}`}
60-
>
61-
<div
62-
className={`flex flex-col gap-3
63-
${
64-
markdownImageContent?.groups?.filename && !isCol
65-
? "md:max-w-[65%] flex-[.75]"
66-
: "max-w-full"
67-
}
68-
`}
69-
>
61+
<Link href={`/${nip19.noteEncode(noteId!)}`} className="p-5 block">
62+
<div className="flex flex-col gap-3 w-full">
7063
{title ? (
7164
<h3 className="text-2xl font-semibold text-light twolines">
7265
{title}
@@ -90,22 +83,33 @@ const Card: FC<NoteProps> = ({
9083
</div>
9184
) : null}
9285
<DatePosted dateOnly={dateOnly} timestamp={createdAt} />
93-
<FileType type={getTagValues("filetype", tags)} />
94-
{/* {actualTags.length > 1 ? <NoteTags tags={actualTags} /> : null} */}
86+
<FileType type={filetype} />
87+
</div>
88+
<div>
89+
{actualTags.length > 1 ? (
90+
<NoteTags tags={actualTags.split(",")} />
91+
) : null}
9592
</div>
96-
<div className="flex flex-col sm:flex-row gap-5 opacity-70">
97-
<div className="twolines opacity-70">{content}</div>
93+
<div className="flex flex-col sm:flex-row gap-5 w-full bg-primary max-h-[50vh] overflow-hidden rounded-md">
94+
{filetype === "markdown" ? (
95+
<div className="w-full max-w-full p-4 prose prose-sm prose-invert prose-img:h-[20vh] prose-img:w-auto prose-img:object-cover prose-img:mx-auto">
96+
<div dangerouslySetInnerHTML={{ __html: markdown }} />
97+
</div>
98+
) : (
99+
<CodeEditor
100+
className="w-full outline-none min-h-full pointer-events-none"
101+
value={content}
102+
language={filetype}
103+
autoCapitalize="none"
104+
disabled
105+
padding={25}
106+
style={{
107+
fontSize: 15,
108+
}}
109+
/>
110+
)}
98111
</div>
99112
</div>
100-
{markdownImageContent?.groups?.filename ? (
101-
<img
102-
className={`rounded-md self-center w-full h-auto object-cover flex-[.25] ${
103-
isCol ? "" : "md:w-1/3"
104-
}`}
105-
src={markdownImageContent?.groups?.filename}
106-
alt={markdownImageContent?.groups?.title}
107-
/>
108-
) : null}
109113
</Link>
110114
</li>
111115
);

app/u/[npub]/LatestNotes.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export default function LatestNotes({ profilePubkey, name }: any) {
3838
? `${name ? `${name}'s l` : "L"}atest notes`
3939
: `${name ? `${name} has no notes yet` : "No notes yet"}`
4040
}
41-
noPosts={events.length === 0}
4241
>
4342
<ul className="flex flex-col gap-4 text-center md:text-start">
4443
{slicedEvents.map((event) => (

0 commit comments

Comments
 (0)