mirror of
https://github.com/AustinKelsay/plebdevs.git
synced 2025-06-06 18:31:00 +00:00
Added buttons on profile / setting to copy npub and nsec if available, email and anon users can now post in feeds
This commit is contained in:
parent
185a85e70c
commit
58d0eefc69
@ -63,15 +63,6 @@ const MessageCarousel = ({ copyToClipboard }) => {
|
||||
);
|
||||
|
||||
const messages = [
|
||||
{
|
||||
title: "Welcome to the PlebDevs Platform testing phase! 👋",
|
||||
description: "During this testing phase all prices will be reduced by 10x but all purchases, subscriptions, and progress will be reset on launch, cheers!",
|
||||
showGithub: false,
|
||||
showX: false,
|
||||
showNostr: false,
|
||||
showDonate: false,
|
||||
showFeedback: true,
|
||||
},
|
||||
{
|
||||
title: "PlebDevs 🤝👨💻🤝👩💻🤝🧑💻🤝",
|
||||
description: "Plebdevs is open source software and is still in early development. If you have any questions drop an issue on the Github repo, or reach out to me in the Community feed.",
|
||||
|
@ -4,15 +4,28 @@ import GenericButton from '@/components/buttons/GenericButton';
|
||||
import { Panel } from 'primereact/panel';
|
||||
import { useNDKContext } from "@/context/NDKContext";
|
||||
import { NDKEvent } from "@nostr-dev-kit/ndk";
|
||||
import { finalizeEvent, verifyEvent } from 'nostr-tools/pure'
|
||||
import { SimplePool } from 'nostr-tools/pool'
|
||||
import appConfig from '@/config/appConfig';
|
||||
import { useToast } from '@/hooks/useToast';
|
||||
import { useSession } from 'next-auth/react';
|
||||
|
||||
const MessageInput = () => {
|
||||
const [message, setMessage] = useState('');
|
||||
const [collapsed, setCollapsed] = useState(true);
|
||||
const { ndk, addSigner } = useNDKContext();
|
||||
const { showToast } = useToast();
|
||||
const { data: session } = useSession();
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (session && session?.user && session.user?.privkey) {
|
||||
handleManualSubmit(session.user.privkey);
|
||||
} else {
|
||||
handleExtensionSubmit();
|
||||
}
|
||||
}
|
||||
|
||||
const handleExtensionSubmit = async () => {
|
||||
if (!message.trim() || !ndk) return;
|
||||
|
||||
try {
|
||||
@ -33,6 +46,37 @@ const MessageInput = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleManualSubmit = async (privkey) => {
|
||||
try {
|
||||
let event = finalizeEvent({
|
||||
kind: 1,
|
||||
created_at: Math.floor(Date.now() / 1000),
|
||||
tags: [
|
||||
['t', 'plebdevs']
|
||||
],
|
||||
content: message,
|
||||
}, privkey)
|
||||
|
||||
let isGood = verifyEvent(event);
|
||||
|
||||
if (isGood) {
|
||||
const pool = new SimplePool();
|
||||
const published = await pool.publish(appConfig.defaultRelayUrls, event);
|
||||
if (published) {
|
||||
showToast('success', 'Message Sent', 'Your message has been sent to the PlebDevs community.');
|
||||
setMessage('');
|
||||
} else {
|
||||
showToast('error', 'Error', 'There was an error sending your message. Please try again.');
|
||||
}
|
||||
} else {
|
||||
showToast('error', 'Error', 'There was an error sending your message. Please try again.');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error finalizing event:", error);
|
||||
showToast('error', 'Error', 'There was an error sending your message. Please try again.');
|
||||
}
|
||||
}
|
||||
|
||||
const headerTemplate = (options) => {
|
||||
return (
|
||||
<div className="flex align-items-center justify-content-between my-1 py-2">
|
||||
|
@ -53,6 +53,26 @@ const UserProfile = () => {
|
||||
</div>
|
||||
);
|
||||
|
||||
const menuItems = [
|
||||
...(user?.privkey ? [{
|
||||
label: 'Copy nsec',
|
||||
icon: 'pi pi-key',
|
||||
command: () => {
|
||||
const privkeyBuffer = Buffer.from(user.privkey, 'hex');
|
||||
copyToClipboard(nip19.nsecEncode(privkeyBuffer));
|
||||
}
|
||||
}] : []),
|
||||
{
|
||||
label: 'Copy npub',
|
||||
icon: 'pi pi-user',
|
||||
command: () => {
|
||||
if (user.pubkey) {
|
||||
copyToClipboard(nip19.npubEncode(user?.pubkey));
|
||||
}
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
return (
|
||||
user && (
|
||||
<div className="p-4">
|
||||
@ -70,8 +90,21 @@ const UserProfile = () => {
|
||||
height={100}
|
||||
className="rounded-full my-4"
|
||||
/>
|
||||
<div className="absolute top-8 right-80 max-tab:right-20 max-mob:left-0">
|
||||
<i
|
||||
className="pi pi-ellipsis-h text-2xl cursor-pointer"
|
||||
onClick={(e) => menu.current.toggle(e)}
|
||||
/>
|
||||
<Menu
|
||||
model={menuItems}
|
||||
popup
|
||||
ref={menu}
|
||||
id="profile-options-menu"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<h1 className="text-center text-2xl my-2">
|
||||
{user.username || user?.email || "Anon"}
|
||||
</h1>
|
||||
|
@ -2,6 +2,7 @@ import React, { useRef, useState, useEffect, useCallback } from "react";
|
||||
import GenericButton from "@/components/buttons/GenericButton";
|
||||
import { DataTable } from "primereact/datatable";
|
||||
import { Column } from "primereact/column";
|
||||
import { Menu } from "primereact/menu";
|
||||
import { useImageProxy } from "@/hooks/useImageProxy";
|
||||
import { useSession } from 'next-auth/react';
|
||||
import { ProgressSpinner } from "primereact/progressspinner";
|
||||
@ -25,6 +26,7 @@ const UserSettings = () => {
|
||||
const { ndk, userRelays, setUserRelays, reInitializeNDK } = useNDKContext();
|
||||
const { data: session } = useSession();
|
||||
const { returnImageProxy } = useImageProxy();
|
||||
const menu = useRef(null);
|
||||
const windowWidth = useWindowWidth();
|
||||
const [newRelayUrl, setNewRelayUrl] = useState("");
|
||||
const { showToast } = useToast();
|
||||
@ -160,6 +162,24 @@ const UserSettings = () => {
|
||||
</div>
|
||||
);
|
||||
|
||||
const menuItems = [
|
||||
...(user?.privkey ? [{
|
||||
label: 'Copy nsec',
|
||||
icon: 'pi pi-key',
|
||||
command: () => {
|
||||
const privkeyBuffer = Buffer.from(user.privkey, 'hex');
|
||||
copyToClipboard(nip19.nsecEncode(privkeyBuffer));
|
||||
}
|
||||
}] : []),
|
||||
{
|
||||
label: 'Copy npub',
|
||||
icon: 'pi pi-user',
|
||||
command: () => {
|
||||
copyToClipboard(nip19.npubEncode(user?.pubkey));
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
return (
|
||||
user && (
|
||||
<div className="p-4">
|
||||
@ -177,6 +197,18 @@ const UserSettings = () => {
|
||||
height={100}
|
||||
className="rounded-full my-4"
|
||||
/>
|
||||
<div className="absolute top-8 right-80 max-tab:right-20 max-mob:left-0">
|
||||
<i
|
||||
className="pi pi-ellipsis-h text-2xl cursor-pointer user-menu-trigger"
|
||||
onClick={(e) => menu.current.toggle(e)}
|
||||
/>
|
||||
<Menu
|
||||
model={menuItems}
|
||||
popup
|
||||
ref={menu}
|
||||
id="profile-options-menu"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h1 className="text-center text-2xl my-2">
|
||||
|
Loading…
x
Reference in New Issue
Block a user