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 {
|
||||
ServerIcon,
|
||||
CpuChipIcon,
|
||||
ArrowPathIcon,
|
||||
PlusCircleIcon
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { XCircleIcon } from "@heroicons/react/24/solid";
|
||||
import { useState, useEffect, useRef } from "react";
|
||||
import { UnsignedEvent, Event as NostrEvent, nip19 } from "nostr-tools";
|
||||
import { renderMedia, attachFile } from "../../utils/FileUpload";
|
||||
import EmojiPicker from "@emoji-mart/react";
|
||||
import customEmojis from './custom_emojis.json';
|
||||
import { renderMedia } from "../../utils/FileUpload";
|
||||
import { useSubmitForm } from "./handleSubmit";
|
||||
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 (
|
||||
<form
|
||||
name="post"
|
||||
@ -174,18 +133,6 @@ const NewNoteCard = ({
|
||||
</div>
|
||||
<div>
|
||||
<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
|
||||
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' : ''}`}
|
||||
|
@ -39,7 +39,7 @@ const PostCard = ({
|
||||
|
||||
const handleClick = () => {
|
||||
if (type !== "OP") {
|
||||
localStorage.setItem("cachedThread", JSON.stringify(relatedEvents));
|
||||
sessionStorage.setItem("cachedThread", JSON.stringify(relatedEvents));
|
||||
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
|
||||
return b.created_at - a.created_at;
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
// Render the component
|
||||
return (
|
||||
@ -39,7 +40,7 @@ const Home = () => {
|
||||
<PostCard
|
||||
event={event}
|
||||
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
|
||||
|
@ -18,7 +18,7 @@ const Thread = () => {
|
||||
|
||||
// Load cached thread from localStorage
|
||||
const [threadCache, setThreadCache] = useState<Event[]>(
|
||||
JSON.parse(localStorage.getItem("cachedThread") || "[]")
|
||||
JSON.parse(sessionStorage.getItem("cachedThread") || "[]")
|
||||
);
|
||||
// Combine noteEvents and threadCache into a single array
|
||||
const allEvents = [...noteEvents, ...threadCache];
|
||||
@ -50,8 +50,9 @@ const Thread = () => {
|
||||
.filter(e =>
|
||||
e.created_at < OPEvent.created_at
|
||||
)
|
||||
|
||||
const replyEvents = [...allEvents].slice(1)
|
||||
|
||||
const uniqReplyEvents = uniqBy(allEvents, "id");
|
||||
const replyEvents = [...uniqReplyEvents].slice(1)
|
||||
.filter(event =>
|
||||
!earlierEvents.map(e => e.id).includes(event.id) &&
|
||||
(OPEvent ? OPEvent.id !== event.id : true)
|
||||
|
Loading…
Reference in New Issue
Block a user