Skip to content

Commit f27d261

Browse files
Add advanced settings panel for repo URL and branch
- Settings toggle button in header - Repo URL and branch inputs with localStorage persistence - Apply button clears old data and reinitializes with new settings - Footer shows current repo dynamically
1 parent d4d2e25 commit f27d261

1 file changed

Lines changed: 92 additions & 11 deletions

File tree

demo.html

Lines changed: 92 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
.dot.error { background: #ef4444; }
6262
@keyframes pulse { 50% { opacity: 0.5; } }
6363

64-
.edit-mode-toggle {
64+
.toggle-btn {
6565
display: inline-flex;
6666
align-items: center;
6767
gap: 8px;
@@ -72,8 +72,8 @@
7272
cursor: pointer;
7373
border: 1px solid #2a2a3a;
7474
}
75-
.edit-mode-toggle:hover { border-color: #a78bfa; }
76-
.edit-mode-toggle.active {
75+
.toggle-btn:hover { border-color: #a78bfa; }
76+
.toggle-btn.active {
7777
background: #7c3aed;
7878
border-color: #7c3aed;
7979
}
@@ -342,9 +342,12 @@ <h1>📝 Live Notes</h1>
342342
<span class="dot" id="statusDot"></span>
343343
<span id="statusText">Connecting...</span>
344344
</div>
345-
<div class="edit-mode-toggle" id="editToggle" onclick="toggleEditMode()">
345+
<div class="toggle-btn" id="editToggle" onclick="toggleEditMode()">
346346
✏️ Edit Mode
347347
</div>
348+
<div class="toggle-btn" id="settingsToggle" onclick="toggleSettings()">
349+
⚙️ Settings
350+
</div>
348351
</div>
349352
<div id="lastUpdated" class="last-updated"></div>
350353
</header>
@@ -356,6 +359,16 @@ <h1>📝 Live Notes</h1>
356359
<div id="pubkeyDisplay" class="pubkey"></div>
357360
</div>
358361

362+
<div id="settingsPanel" class="key-panel">
363+
<label>Repository URL</label>
364+
<input type="text" id="repoInput" placeholder="https://example.com/user/repo" oninput="onSettingsChange()">
365+
<div class="hint" style="margin-bottom: 15px;">Git repository URL (must support CORS)</div>
366+
<label>Branch</label>
367+
<input type="text" id="branchInput" placeholder="main" oninput="onSettingsChange()">
368+
<div class="hint">Branch to sync (default: main)</div>
369+
<button id="applySettingsBtn" onclick="applySettings()" style="margin-top: 15px; padding: 10px 20px; background: #7c3aed; border: none; border-radius: 6px; color: white; cursor: pointer; font-size: 14px;">Apply & Reload</button>
370+
</div>
371+
359372
<button id="newNoteBtn" class="new-note-btn" onclick="newNote()">+ New Note</button>
360373

361374
<div id="notesList" class="notes-list"></div>
@@ -376,7 +389,7 @@ <h1>📝 Live Notes</h1>
376389

377390
<div class="footer">
378391
Powered by <a href="https://github.com/JavaScriptSolidServer/nostr-git-client">nostr-git-client</a>
379-
• Syncing from <a href="https://solid.social/mel/public/notes">solid.social</a>
392+
• Syncing from <a id="repoLink" href=""></a>
380393
</div>
381394
</div>
382395

@@ -415,19 +428,84 @@ <h1>📝 Live Notes</h1>
415428
return bytes;
416429
}
417430

418-
const REPO = 'https://solid.social/mel/public/notes';
419-
const REPO_ID = 'notes';
431+
const DEFAULT_REPO = 'https://solid.social/mel/public/notes';
432+
const DEFAULT_BRANCH = 'main';
420433
const RELAYS = ['wss://relay.damus.io', 'wss://nos.lol'];
421434

435+
// Load settings from localStorage
436+
let REPO = localStorage.getItem('ngc-repo') || DEFAULT_REPO;
437+
let BRANCH = localStorage.getItem('ngc-branch') || DEFAULT_BRANCH;
438+
let REPO_ID = REPO.split('/').pop();
439+
422440
let client;
423441
let notes = [];
424442
let currentNote = null;
425443
let currentContent = '';
426444
let editMode = false;
445+
let settingsOpen = false;
427446
let isEditing = false;
428447
let isNewNote = false;
429448
let privkey = localStorage.getItem('nostr-privkey') || '';
430449

450+
// Initialize settings inputs
451+
function initSettings() {
452+
document.getElementById('repoInput').value = REPO;
453+
document.getElementById('branchInput').value = BRANCH;
454+
updateRepoLink();
455+
}
456+
457+
function updateRepoLink() {
458+
const link = document.getElementById('repoLink');
459+
link.href = REPO;
460+
link.textContent = new URL(REPO).hostname + new URL(REPO).pathname;
461+
}
462+
463+
window.toggleSettings = function() {
464+
settingsOpen = !settingsOpen;
465+
document.getElementById('settingsToggle').classList.toggle('active', settingsOpen);
466+
document.getElementById('settingsPanel').classList.toggle('show', settingsOpen);
467+
};
468+
469+
window.onSettingsChange = function() {
470+
// Just track changes, apply on button click
471+
};
472+
473+
window.applySettings = async function() {
474+
const newRepo = document.getElementById('repoInput').value.trim();
475+
const newBranch = document.getElementById('branchInput').value.trim() || 'main';
476+
477+
if (!newRepo) {
478+
alert('Please enter a repository URL');
479+
return;
480+
}
481+
482+
// Save to localStorage
483+
localStorage.setItem('ngc-repo', newRepo);
484+
localStorage.setItem('ngc-branch', newBranch);
485+
486+
// Update globals
487+
REPO = newRepo;
488+
BRANCH = newBranch;
489+
REPO_ID = REPO.split('/').pop();
490+
491+
updateRepoLink();
492+
493+
// Clear old data and reinitialize
494+
if (client) {
495+
client.disconnect();
496+
await client.clear();
497+
}
498+
499+
notes = [];
500+
currentNote = null;
501+
document.getElementById('notesList').innerHTML = '';
502+
document.getElementById('noteView').classList.remove('active');
503+
504+
await init();
505+
toggleSettings(); // Close panel
506+
showToast('Switched to ' + REPO_ID);
507+
};
508+
431509
function renderMarkdown(text) {
432510
return marked.parse(text);
433511
}
@@ -638,7 +716,7 @@ <h3>${titleCased}</h3>
638716
http,
639717
dir,
640718
url: REPO,
641-
ref: 'main',
719+
ref: BRANCH,
642720
singleBranch: true,
643721
depth: 1
644722
});
@@ -665,7 +743,7 @@ <h3>${titleCased}</h3>
665743
http,
666744
dir,
667745
url: REPO,
668-
ref: 'main',
746+
ref: BRANCH,
669747
force: true
670748
});
671749

@@ -770,7 +848,7 @@ <h3>${titleCased}</h3>
770848
created_at: Math.floor(Date.now() / 1000),
771849
tags: [
772850
['d', REPO_ID],
773-
['refs/heads/main', commit]
851+
[`refs/heads/${BRANCH}`, commit]
774852
],
775853
content: ''
776854
};
@@ -796,9 +874,12 @@ <h3>${titleCased}</h3>
796874

797875
// Initialize
798876
async function init() {
877+
initSettings();
878+
799879
client = new NostrGitClient({
800880
repo: REPO,
801-
branch: 'main',
881+
repoId: REPO_ID,
882+
branch: BRANCH,
802883
relays: RELAYS
803884
});
804885

0 commit comments

Comments
 (0)