mirror of
https://github.com/smolgrrr/TAO.git
synced 2024-09-20 01:11:25 +00:00
smol clean up and fixes
This commit is contained in:
parent
6b98269cad
commit
3ef19272dc
@ -1,57 +0,0 @@
|
|||||||
import data, { Emoji } from "@emoji-mart/data";
|
|
||||||
import Picker from "@emoji-mart/react";
|
|
||||||
import { RefObject } from "react";
|
|
||||||
import customEmojis from "../custom_emojis.json";
|
|
||||||
|
|
||||||
interface EmojiPickerProps {
|
|
||||||
topOffset: number;
|
|
||||||
leftOffset: number;
|
|
||||||
onEmojiSelect: (e: Emoji) => void;
|
|
||||||
onClickOutside: () => void;
|
|
||||||
height?: number;
|
|
||||||
ref: RefObject<HTMLDivElement>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function EmojiPicker({
|
|
||||||
topOffset,
|
|
||||||
leftOffset,
|
|
||||||
onEmojiSelect,
|
|
||||||
onClickOutside,
|
|
||||||
height = 300,
|
|
||||||
ref,
|
|
||||||
}: EmojiPickerProps) {
|
|
||||||
const customEmojiList = customEmojis.map((pack) => {
|
|
||||||
return {
|
|
||||||
id: pack.id,
|
|
||||||
name: pack.name,
|
|
||||||
emojis: pack.emojis
|
|
||||||
.filter((e) => !e.static_url.endsWith('.svg'))
|
|
||||||
.map((e) => {
|
|
||||||
return {
|
|
||||||
id: e.shortcode,
|
|
||||||
name: e.shortcode,
|
|
||||||
skins: [{ src: e.static_url }],
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<div className="absolute z-25" ref={ref}>
|
|
||||||
<Picker
|
|
||||||
autoFocus
|
|
||||||
custom={customEmojiList}
|
|
||||||
data = {data}
|
|
||||||
perLine={7}
|
|
||||||
previewPosition="none"
|
|
||||||
skinTonePosition="none"
|
|
||||||
theme="dark"
|
|
||||||
onEmojiSelect={onEmojiSelect}
|
|
||||||
onClickOutside={onClickOutside}
|
|
||||||
categories={['poast']}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
@ -1,15 +1,11 @@
|
|||||||
import {
|
import {
|
||||||
ServerIcon,
|
|
||||||
CpuChipIcon,
|
CpuChipIcon,
|
||||||
ArrowPathIcon,
|
|
||||||
PlusCircleIcon
|
PlusCircleIcon
|
||||||
} from "@heroicons/react/24/outline";
|
} from "@heroicons/react/24/outline";
|
||||||
import { XCircleIcon } from "@heroicons/react/24/solid";
|
import { XCircleIcon } from "@heroicons/react/24/solid";
|
||||||
import { useState, useEffect, useRef } from "react";
|
import { useState, useEffect, useRef } from "react";
|
||||||
import { UnsignedEvent, Event as NostrEvent, nip19 } from "nostr-tools";
|
import { UnsignedEvent, Event as NostrEvent, nip19 } from "nostr-tools";
|
||||||
import { renderMedia, attachFile } from "../../utils/FileUpload";
|
import { renderMedia } from "../../utils/FileUpload";
|
||||||
import EmojiPicker from "@emoji-mart/react";
|
|
||||||
import customEmojis from './custom_emojis.json';
|
|
||||||
import { useSubmitForm } from "./handleSubmit";
|
import { useSubmitForm } from "./handleSubmit";
|
||||||
import "../../styles/Form.css";
|
import "../../styles/Form.css";
|
||||||
|
|
||||||
@ -100,43 +96,6 @@ const NewNoteCard = ({
|
|||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
//Emoji stuff
|
|
||||||
const emojiRef = useRef(null);
|
|
||||||
const [showEmojiPicker, setShowEmojiPicker] = useState(false);
|
|
||||||
|
|
||||||
interface Emoji {
|
|
||||||
native?: string;
|
|
||||||
id?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const emojiNames = customEmojis.map(p => p.emojis).flat();
|
|
||||||
function getEmojiById(id: string) {
|
|
||||||
return emojiNames.find(e => e.shortcode === id);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function onEmojiSelect(emoji: Emoji) {
|
|
||||||
setShowEmojiPicker(false);
|
|
||||||
try {
|
|
||||||
if (emoji.id) {
|
|
||||||
const e = getEmojiById(emoji.id);
|
|
||||||
if (e) {
|
|
||||||
setComment(comment + " :" + e.shortcode + ":");
|
|
||||||
unsigned.tags.push(['emoji', e.shortcode, e.url]);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
//ignore
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const topOffset = ref.current?.getBoundingClientRect().top;
|
|
||||||
const leftOffset = ref.current?.getBoundingClientRect().left;
|
|
||||||
|
|
||||||
function pickEmoji(e: React.MouseEvent) {
|
|
||||||
e.stopPropagation();
|
|
||||||
setShowEmojiPicker(!showEmojiPicker);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form
|
<form
|
||||||
name="post"
|
name="post"
|
||||||
@ -174,18 +133,6 @@ const NewNoteCard = ({
|
|||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<div className="flex items-center gap-4">
|
<div className="flex items-center gap-4">
|
||||||
<div className="items-center">
|
|
||||||
{showEmojiPicker && (
|
|
||||||
<EmojiPicker
|
|
||||||
topOffset={topOffset || 0}
|
|
||||||
leftOffset={leftOffset || 0}
|
|
||||||
onEmojiSelect={onEmojiSelect}
|
|
||||||
onClickOutside={() => setShowEmojiPicker(false)}
|
|
||||||
ref={emojiRef}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<PlusCircleIcon className="h-4 w-4 text-neutral-400 cursor-pointer" onClick={pickEmoji} />
|
|
||||||
</div>
|
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
className={`bg-black border h-9 inline-flex items-center justify-center px-4 rounded-lg text-white font-medium text-sm ${doingWorkProp || uploadingFile ? 'cursor-not-allowed' : ''}`}
|
className={`bg-black border h-9 inline-flex items-center justify-center px-4 rounded-lg text-white font-medium text-sm ${doingWorkProp || uploadingFile ? 'cursor-not-allowed' : ''}`}
|
||||||
|
@ -39,7 +39,7 @@ const PostCard = ({
|
|||||||
|
|
||||||
const handleClick = () => {
|
const handleClick = () => {
|
||||||
if (type !== "OP") {
|
if (type !== "OP") {
|
||||||
localStorage.setItem("cachedThread", JSON.stringify(relatedEvents));
|
sessionStorage.setItem("cachedThread", JSON.stringify(relatedEvents));
|
||||||
window.location.href = `/thread/${nip19.noteEncode(event.id)}`;
|
window.location.href = `/thread/${nip19.noteEncode(event.id)}`;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -25,7 +25,8 @@ const Home = () => {
|
|||||||
|
|
||||||
// If PoW is the same, sort by created_at in descending order
|
// If PoW is the same, sort by created_at in descending order
|
||||||
return b.created_at - a.created_at;
|
return b.created_at - a.created_at;
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
// Render the component
|
// Render the component
|
||||||
return (
|
return (
|
||||||
@ -39,7 +40,7 @@ const Home = () => {
|
|||||||
<PostCard
|
<PostCard
|
||||||
event={event}
|
event={event}
|
||||||
metadata={metadataEvents.find((e) => e.pubkey === event.pubkey && e.kind === 0) || null}
|
metadata={metadataEvents.find((e) => e.pubkey === event.pubkey && e.kind === 0) || null}
|
||||||
replies={sortedEvents.filter((e) => e.tags.some((tag) => tag[0] === "e" && tag[1] === event.id))}
|
replies={noteEvents.filter((e) => e.tags.some((tag) => tag[0] === "e" && tag[1] === event.id))}
|
||||||
/>
|
/>
|
||||||
:
|
:
|
||||||
<RepostCard
|
<RepostCard
|
||||||
|
@ -18,7 +18,7 @@ const Thread = () => {
|
|||||||
|
|
||||||
// Load cached thread from localStorage
|
// Load cached thread from localStorage
|
||||||
const [threadCache, setThreadCache] = useState<Event[]>(
|
const [threadCache, setThreadCache] = useState<Event[]>(
|
||||||
JSON.parse(localStorage.getItem("cachedThread") || "[]")
|
JSON.parse(sessionStorage.getItem("cachedThread") || "[]")
|
||||||
);
|
);
|
||||||
// Combine noteEvents and threadCache into a single array
|
// Combine noteEvents and threadCache into a single array
|
||||||
const allEvents = [...noteEvents, ...threadCache];
|
const allEvents = [...noteEvents, ...threadCache];
|
||||||
@ -51,7 +51,8 @@ const Thread = () => {
|
|||||||
e.created_at < OPEvent.created_at
|
e.created_at < OPEvent.created_at
|
||||||
)
|
)
|
||||||
|
|
||||||
const replyEvents = [...allEvents].slice(1)
|
const uniqReplyEvents = uniqBy(allEvents, "id");
|
||||||
|
const replyEvents = [...uniqReplyEvents].slice(1)
|
||||||
.filter(event =>
|
.filter(event =>
|
||||||
!earlierEvents.map(e => e.id).includes(event.id) &&
|
!earlierEvents.map(e => e.id).includes(event.id) &&
|
||||||
(OPEvent ? OPEvent.id !== event.id : true)
|
(OPEvent ? OPEvent.id !== event.id : true)
|
||||||
|
Loading…
Reference in New Issue
Block a user