Skip to content

Commit

Permalink
Adds relay url to the query params
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorpamplona committed Jun 27, 2024
1 parent 712ab17 commit cee3613
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
26 changes: 17 additions & 9 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -200,23 +200,30 @@ <h2 id="sheet-name" onclick="toggleNameEdit(this);">Your Spreadsheets</h2>
const urlParams = new URLSearchParams(window.location.search);
const authorParam = urlParams.get('author')
const dTag = urlParams.get('id')
let relay = urlParams.get('relay')

console.log("Load page for", author, dTag)
if (!relay) {
relay = "wss://nostr.mom"
urlParams.set("relay", relay);
history.pushState(null, '', window.location.pathname + '?' + urlParams.toString());
}

console.log("Load page for", relay, author, dTag)

if (dTag) {
$("#sheet-name").html(dTag)
hideDashboard()
if (authorParam) {
loadId(authorParam, dTag)
loadId(relay, authorParam, dTag)
} else {
loadId(author, dTag)
loadId(relay, author, dTag)
}
} else {
showDashboard()
if (authorParam) {
loadDashboard(authorParam)
loadDashboard(relay, authorParam)
} else {
loadDashboard(author)
loadDashboard(relay, author)
}
}
}
Expand All @@ -231,9 +238,10 @@ <h2 id="sheet-name" onclick="toggleNameEdit(this);">Your Spreadsheets</h2>
$("#dashboard").show();
}

async function loadDashboard(author) {
async function loadDashboard(relay, author) {
$("#sheets").html("");
fetchAllSpreadsheets(author, (ee) => {

fetchAllSpreadsheets(relay, author, (ee) => {
console.log("Event Received", ee)

let currentVersion = expandedEvents.get(ee.address)
Expand Down Expand Up @@ -433,8 +441,8 @@ <h2 id="sheet-name" onclick="toggleNameEdit(this);">Your Spreadsheets</h2>
}
}

async function loadId(author, dTag) {
fetchSpreadSheet(author, dTag, (ee, data) => {
async function loadId(relay, author, dTag) {
fetchSpreadSheet(relay, author, dTag, (ee, data) => {
var {
UniverCore,
UniverDesign,
Expand Down
6 changes: 2 additions & 4 deletions js/nostr-sheetstr.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,8 @@ async function blankPrivateSheet(dTag) {
}
}

async function fetchAllSpreadsheets(author, onReady, newUserMetadata) {
async function fetchAllSpreadsheets(relay, author, onReady, newUserMetadata) {
tentatives = 0
let relay = "wss://nostr.mom"

addUserMetadataIfItDoesntExist(author)

Expand Down Expand Up @@ -559,9 +558,8 @@ function hasDataTags(event) {
return event.tags.find(tag => tag[0] == "data") != undefined
}

async function fetchSpreadSheet(author, dTag, createNewSheet, newUserMetadata) {
async function fetchSpreadSheet(relay, author, dTag, createNewSheet, newUserMetadata, ) {
tentatives = 0
let relay = "wss://nostr.mom"

addUserMetadataIfItDoesntExist(author)

Expand Down

0 comments on commit cee3613

Please sign in to comment.