change name and add link to source
This commit is contained in:
parent
581c3626af
commit
da88a2c0ef
7 changed files with 24 additions and 41 deletions
|
|
@ -3,12 +3,12 @@
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Comunitator - Nostr</title>
|
<title>Communitator - Nostr Relay Templates</title>
|
||||||
<meta name="description" content="Create and share Nostr relay templates for your community" />
|
<meta name="description" content="Create and share Nostr relay templates for your community" />
|
||||||
<link rel="icon" type="image/svg+xml" href="/favicon.ico" />
|
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>⚡</text></svg>" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="root"></div>
|
<div id="root"></div>
|
||||||
<script type="module" src="/src/main.jsx"></script>
|
<script type="module" src="/src/main.jsx"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"name": "relay-template-app",
|
"name": "communitator",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
@ -19,4 +19,4 @@
|
||||||
"@vitejs/plugin-react": "^4.2.1",
|
"@vitejs/plugin-react": "^4.2.1",
|
||||||
"vite": "^5.0.8"
|
"vite": "^5.0.8"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
23
src/App.jsx
23
src/App.jsx
|
|
@ -14,7 +14,6 @@ function App() {
|
||||||
<h1>⚡ Communitator</h1>
|
<h1>⚡ Communitator</h1>
|
||||||
<nav>
|
<nav>
|
||||||
<Link to="/">🏠 Create Template</Link>
|
<Link to="/">🏠 Create Template</Link>
|
||||||
{/* Remove the broken link - users will access /apply/:encoded via generated links */}
|
|
||||||
</nav>
|
</nav>
|
||||||
{connectedPubkey && (
|
{connectedPubkey && (
|
||||||
<div className="user-badge">
|
<div className="user-badge">
|
||||||
|
|
@ -24,20 +23,26 @@ function App() {
|
||||||
</header>
|
</header>
|
||||||
<main>
|
<main>
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route path="/" element={
|
<Route path="/" element={<TemplateCreator />} />
|
||||||
<TemplateCreator setConnectedPubkey={setConnectedPubkey} />
|
<Route path="/apply/:encoded" element={<TemplateApplier setConnectedPubkey={setConnectedPubkey} />} />
|
||||||
} />
|
|
||||||
<Route path="/apply/:encoded" element={
|
|
||||||
<TemplateApplier connectedPubkey={connectedPubkey} setConnectedPubkey={setConnectedPubkey} />
|
|
||||||
} />
|
|
||||||
</Routes>
|
</Routes>
|
||||||
</main>
|
</main>
|
||||||
<footer>
|
<footer>
|
||||||
<p>Self-contained • Built with Nostr</p>
|
<p>
|
||||||
|
Built with Nostr ·{' '}
|
||||||
|
<a
|
||||||
|
href="https://git.basspistol.org/hq/Communitator"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
style={{ color: 'inherit', textDecoration: 'underline' }}
|
||||||
|
>
|
||||||
|
Source Code
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
</footer>
|
</footer>
|
||||||
</div>
|
</div>
|
||||||
</HashRouter>
|
</HashRouter>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default App;
|
export default App;
|
||||||
|
|
@ -4,7 +4,6 @@ const NostrConnect = ({ setConnectedPubkey }) => {
|
||||||
const [pubkey, setPubkey] = useState(null);
|
const [pubkey, setPubkey] = useState(null);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
// Check if already connected
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (window.nostr?.getPublicKey) {
|
if (window.nostr?.getPublicKey) {
|
||||||
window.nostr.getPublicKey()
|
window.nostr.getPublicKey()
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ const TemplateApplier = ({ setConnectedPubkey }) => {
|
||||||
throw new Error('Please connect your Nostr signer first');
|
throw new Error('Please connect your Nostr signer first');
|
||||||
}
|
}
|
||||||
|
|
||||||
// ✅ Collect ALL user relay URLs from the main relays
|
// Collect ALL user relay URLs from the main relays
|
||||||
const allUserRelays = template.relays.map(r => r.url);
|
const allUserRelays = template.relays.map(r => r.url);
|
||||||
|
|
||||||
const allResults = [];
|
const allResults = [];
|
||||||
|
|
@ -95,7 +95,7 @@ const TemplateApplier = ({ setConnectedPubkey }) => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Publish kind 10063 (blossom servers) - ✅ Pass all user relays
|
// 2. Publish kind 10063 (blossom servers)
|
||||||
if (template.blossomServers && template.blossomServers.length > 0) {
|
if (template.blossomServers && template.blossomServers.length > 0) {
|
||||||
publishConfigs.push({
|
publishConfigs.push({
|
||||||
name: 'Blossom Servers (kind 10063)',
|
name: 'Blossom Servers (kind 10063)',
|
||||||
|
|
@ -104,7 +104,7 @@ const TemplateApplier = ({ setConnectedPubkey }) => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Publish kind 10050 (DM relays) - ✅ Pass all user relays
|
// 3. Publish kind 10050 (DM relays)
|
||||||
if (template.dmRelays && template.dmRelays.length > 0) {
|
if (template.dmRelays && template.dmRelays.length > 0) {
|
||||||
publishConfigs.push({
|
publishConfigs.push({
|
||||||
name: 'DM Relays (kind 10050)',
|
name: 'DM Relays (kind 10050)',
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ const TemplateCreator = () => {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const [blossomServers, setBlossomServers] = useState([
|
const [blossomServers, setBlossomServers] = useState([
|
||||||
{ url: 'https://your-blossom.community' }
|
{ url: 'https://your-blossom.server' }
|
||||||
]);
|
]);
|
||||||
const [showBlossom, setShowBlossom] = useState(true);
|
const [showBlossom, setShowBlossom] = useState(true);
|
||||||
|
|
||||||
|
|
@ -51,7 +51,6 @@ const TemplateCreator = () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Relay functions
|
|
||||||
const addRelay = () => {
|
const addRelay = () => {
|
||||||
setRelays([...relays, { url: '', read: true, write: true }]);
|
setRelays([...relays, { url: '', read: true, write: true }]);
|
||||||
};
|
};
|
||||||
|
|
@ -72,7 +71,6 @@ const TemplateCreator = () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Blossom server functions
|
|
||||||
const addBlossomServer = () => {
|
const addBlossomServer = () => {
|
||||||
setBlossomServers([...blossomServers, { url: '' }]);
|
setBlossomServers([...blossomServers, { url: '' }]);
|
||||||
};
|
};
|
||||||
|
|
@ -87,7 +85,6 @@ const TemplateCreator = () => {
|
||||||
setBlossomServers(updated);
|
setBlossomServers(updated);
|
||||||
};
|
};
|
||||||
|
|
||||||
// DM relay functions
|
|
||||||
const addDmRelay = () => {
|
const addDmRelay = () => {
|
||||||
setDmRelays([...dmRelays, { url: '' }]);
|
setDmRelays([...dmRelays, { url: '' }]);
|
||||||
};
|
};
|
||||||
|
|
@ -131,7 +128,6 @@ const TemplateCreator = () => {
|
||||||
<div className="template-creator">
|
<div className="template-creator">
|
||||||
<h2>Create Relay Template</h2>
|
<h2>Create Relay Template</h2>
|
||||||
|
|
||||||
{/* Community Templates Section */}
|
|
||||||
<div className="form-group" style={{
|
<div className="form-group" style={{
|
||||||
background: '#f8f9fa',
|
background: '#f8f9fa',
|
||||||
padding: '16px',
|
padding: '16px',
|
||||||
|
|
@ -226,9 +222,8 @@ const TemplateCreator = () => {
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Main Relays Section */}
|
|
||||||
<div className="form-group">
|
<div className="form-group">
|
||||||
<label>📡 Relays *</label>
|
<label>Relays *</label>
|
||||||
<RelayList
|
<RelayList
|
||||||
relays={relays}
|
relays={relays}
|
||||||
onUpdate={updateRelay}
|
onUpdate={updateRelay}
|
||||||
|
|
@ -270,7 +265,6 @@ const TemplateCreator = () => {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Blossom Servers Section */}
|
|
||||||
<div className="form-group">
|
<div className="form-group">
|
||||||
<div style={{ display: 'flex', alignItems: 'center', gap: '10px', marginBottom: '8px' }}>
|
<div style={{ display: 'flex', alignItems: 'center', gap: '10px', marginBottom: '8px' }}>
|
||||||
<label style={{ marginBottom: 0 }}>🌺 Blossom Servers (kind 10063)</label>
|
<label style={{ marginBottom: 0 }}>🌺 Blossom Servers (kind 10063)</label>
|
||||||
|
|
@ -314,7 +308,6 @@ const TemplateCreator = () => {
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* DM Relays Section */}
|
|
||||||
<div className="form-group">
|
<div className="form-group">
|
||||||
<div style={{ display: 'flex', alignItems: 'center', gap: '10px', marginBottom: '8px' }}>
|
<div style={{ display: 'flex', alignItems: 'center', gap: '10px', marginBottom: '8px' }}>
|
||||||
<label style={{ marginBottom: 0 }}>💬 DM Relays (kind 10050)</label>
|
<label style={{ marginBottom: 0 }}>💬 DM Relays (kind 10050)</label>
|
||||||
|
|
|
||||||
|
|
@ -184,13 +184,6 @@ export const useNostr = () => {
|
||||||
// PUBLISH KIND FUNCTIONS
|
// PUBLISH KIND FUNCTIONS
|
||||||
// ============================================================
|
// ============================================================
|
||||||
|
|
||||||
/**
|
|
||||||
* Generic publish function that publishes to ALL relays
|
|
||||||
* @param {number} kind - Event kind
|
|
||||||
* @param {object} data - Event data with tags and content
|
|
||||||
* @param {string} pubkey - User's pubkey
|
|
||||||
* @param {string[]} userRelayUrls - User's relay URLs (all of them, not just for this kind)
|
|
||||||
*/
|
|
||||||
const publishKind = useCallback(async (kind, data, pubkey, userRelayUrls = []) => {
|
const publishKind = useCallback(async (kind, data, pubkey, userRelayUrls = []) => {
|
||||||
if (!extension) {
|
if (!extension) {
|
||||||
throw new Error('No Nostr extension connected');
|
throw new Error('No Nostr extension connected');
|
||||||
|
|
@ -208,7 +201,6 @@ export const useNostr = () => {
|
||||||
const signedEvent = await signEvent(event);
|
const signedEvent = await signEvent(event);
|
||||||
console.log(`Kind ${kind} event signed successfully`);
|
console.log(`Kind ${kind} event signed successfully`);
|
||||||
|
|
||||||
// ✅ Combine ALL relays: blast + ALL user relays
|
|
||||||
const allRelays = [...new Set([...BLAST_RELAYS, ...userRelayUrls])];
|
const allRelays = [...new Set([...BLAST_RELAYS, ...userRelayUrls])];
|
||||||
console.log(`Publishing kind ${kind} to ${allRelays.length} relays (${BLAST_RELAYS.length} blast + ${userRelayUrls.length} user)`);
|
console.log(`Publishing kind ${kind} to ${allRelays.length} relays (${BLAST_RELAYS.length} blast + ${userRelayUrls.length} user)`);
|
||||||
|
|
||||||
|
|
@ -225,7 +217,6 @@ export const useNostr = () => {
|
||||||
};
|
};
|
||||||
}, [extension, signEvent, publishToRelays]);
|
}, [extension, signEvent, publishToRelays]);
|
||||||
|
|
||||||
// Kind 10002 - Relays
|
|
||||||
const publishKind10002 = useCallback(async (relays, pubkey) => {
|
const publishKind10002 = useCallback(async (relays, pubkey) => {
|
||||||
const validRelays = relays.filter(r => r.url && r.url.trim() !== '');
|
const validRelays = relays.filter(r => r.url && r.url.trim() !== '');
|
||||||
if (validRelays.length === 0) {
|
if (validRelays.length === 0) {
|
||||||
|
|
@ -237,30 +228,25 @@ export const useNostr = () => {
|
||||||
if (!relay.write) params.push('write');
|
if (!relay.write) params.push('write');
|
||||||
return ['r', relay.url, ...params];
|
return ['r', relay.url, ...params];
|
||||||
});
|
});
|
||||||
// ✅ Pass ALL user relay URLs (they're the same as the relays being published)
|
|
||||||
const userRelayUrls = validRelays.map(r => r.url);
|
const userRelayUrls = validRelays.map(r => r.url);
|
||||||
return await publishKind(10002, { tags }, pubkey, userRelayUrls);
|
return await publishKind(10002, { tags }, pubkey, userRelayUrls);
|
||||||
}, [publishKind]);
|
}, [publishKind]);
|
||||||
|
|
||||||
// Kind 10063 - Blossom Servers
|
|
||||||
const publishKind10063 = useCallback(async (servers, pubkey, allUserRelays = []) => {
|
const publishKind10063 = useCallback(async (servers, pubkey, allUserRelays = []) => {
|
||||||
const validServers = servers.filter(s => s.url && s.url.trim() !== '');
|
const validServers = servers.filter(s => s.url && s.url.trim() !== '');
|
||||||
if (validServers.length === 0) {
|
if (validServers.length === 0) {
|
||||||
throw new Error('No valid blossom servers');
|
throw new Error('No valid blossom servers');
|
||||||
}
|
}
|
||||||
const tags = validServers.map(server => ['server', server.url]);
|
const tags = validServers.map(server => ['server', server.url]);
|
||||||
// ✅ Pass ALL user relays (main relays, not just blossom servers)
|
|
||||||
return await publishKind(10063, { tags }, pubkey, allUserRelays);
|
return await publishKind(10063, { tags }, pubkey, allUserRelays);
|
||||||
}, [publishKind]);
|
}, [publishKind]);
|
||||||
|
|
||||||
// Kind 10050 - DM Relays
|
|
||||||
const publishKind10050 = useCallback(async (relays, pubkey, allUserRelays = []) => {
|
const publishKind10050 = useCallback(async (relays, pubkey, allUserRelays = []) => {
|
||||||
const validRelays = relays.filter(r => r.url && r.url.trim() !== '');
|
const validRelays = relays.filter(r => r.url && r.url.trim() !== '');
|
||||||
if (validRelays.length === 0) {
|
if (validRelays.length === 0) {
|
||||||
throw new Error('No valid DM relays');
|
throw new Error('No valid DM relays');
|
||||||
}
|
}
|
||||||
const tags = validRelays.map(relay => ['relay', relay.url]);
|
const tags = validRelays.map(relay => ['relay', relay.url]);
|
||||||
// ✅ Pass ALL user relays (main relays, not just DM relays)
|
|
||||||
return await publishKind(10050, { tags }, pubkey, allUserRelays);
|
return await publishKind(10050, { tags }, pubkey, allUserRelays);
|
||||||
}, [publishKind]);
|
}, [publishKind]);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue