Browse Source

Enhance Event Loading Logic and Update Permissions

- Updated event loading logic in App.svelte to reset the attempt flag when toggling filters or switching tabs, preventing infinite load loops.
- Modified role-based permissions to include "read" access for viewing events, ensuring users with "read", "write", "admin", or "owner" roles can access the event list.
- Adjusted alert messages to reflect the updated permission structure.
- Incremented the version number to v0.19.5 to reflect these changes.
main
mleku 3 months ago
parent
commit
f4358eeee0
No known key found for this signature in database
  1. 2
      app/web/dist/bundle.css
  2. 24
      app/web/dist/bundle.js
  3. 2
      app/web/dist/bundle.js.map
  4. 40
      app/web/src/App.svelte
  5. 2
      pkg/version/version

2
app/web/dist/bundle.css vendored

File diff suppressed because one or more lines are too long

24
app/web/dist/bundle.js vendored

File diff suppressed because one or more lines are too long

2
app/web/dist/bundle.js.map vendored

File diff suppressed because one or more lines are too long

40
app/web/src/App.svelte

@ -370,6 +370,9 @@
// Toggle state is already updated by bind:checked // Toggle state is already updated by bind:checked
console.log("Toggle changed, showOnlyMyEvents:", showOnlyMyEvents); console.log("Toggle changed, showOnlyMyEvents:", showOnlyMyEvents);
// Reset the attempt flag to allow reloading with new filter
hasAttemptedEventLoad = false;
// Reload events with the new filter // Reload events with the new filter
const authors = const authors =
showOnlyMyEvents && isLoggedIn && userPubkey ? [userPubkey] : null; showOnlyMyEvents && isLoggedIn && userPubkey ? [userPubkey] : null;
@ -2088,11 +2091,12 @@
async function loadAllEvents(reset = false, authors = null) { async function loadAllEvents(reset = false, authors = null) {
if ( if (
!isLoggedIn || !isLoggedIn ||
(userRole !== "write" && (userRole !== "read" &&
userRole !== "write" &&
userRole !== "admin" && userRole !== "admin" &&
userRole !== "owner") userRole !== "owner")
) { ) {
alert("Write, admin, or owner permission required"); alert("Read, write, admin, or owner permission required");
return; return;
} }
@ -2117,11 +2121,15 @@
authors, authors,
"including delete events", "including delete events",
); );
// For reset, use current timestamp to get the most recent events
const untilTimestamp = reset
? Math.floor(Date.now() / 1000)
: oldestEventTimestamp;
const events = await fetchAllEvents({ const events = await fetchAllEvents({
limit: reset ? 100 : 200, limit: reset ? 100 : 200,
until: reset until: untilTimestamp,
? Math.floor(Date.now() / 1000)
: oldestEventTimestamp,
authors: authors, authors: authors,
}); });
console.log("Received events:", events.length, "events"); console.log("Received events:", events.length, "events");
@ -2210,6 +2218,9 @@
} }
// Load events when events tab is selected (only if no events loaded yet) // Load events when events tab is selected (only if no events loaded yet)
// Track if we've already attempted to load events to prevent infinite loops
let hasAttemptedEventLoad = false;
$: if ( $: if (
selectedTab === "events" && selectedTab === "events" &&
isLoggedIn && isLoggedIn &&
@ -2217,12 +2228,23 @@
userRole === "write" || userRole === "write" ||
userRole === "admin" || userRole === "admin" ||
userRole === "owner") && userRole === "owner") &&
allEvents.length === 0 allEvents.length === 0 &&
!hasAttemptedEventLoad &&
!isLoadingEvents
) { ) {
hasAttemptedEventLoad = true;
const authors = showOnlyMyEvents && userPubkey ? [userPubkey] : null; const authors = showOnlyMyEvents && userPubkey ? [userPubkey] : null;
loadAllEvents(true, authors); loadAllEvents(true, authors);
} }
// Reset the attempt flag when switching tabs or when showOnlyMyEvents changes
$: if (
selectedTab !== "events" ||
(selectedTab === "events" && allEvents.length > 0)
) {
hasAttemptedEventLoad = false;
}
// NIP-98 authentication helper // NIP-98 authentication helper
async function createNIP98AuthHeader(url, method) { async function createNIP98AuthHeader(url, method) {
if (!isLoggedIn || !userPubkey) { if (!isLoggedIn || !userPubkey) {
@ -2985,6 +3007,11 @@
{/if} {/if}
{:else if isLoggedIn && userPubkey} {:else if isLoggedIn && userPubkey}
<div class="profile-loading-section"> <div class="profile-loading-section">
<!-- Logout button in top-right corner -->
<button
class="logout-btn floating"
on:click={handleLogout}>Log out</button
>
<h3>Profile Loading</h3> <h3>Profile Loading</h3>
<p>Your profile metadata is being loaded...</p> <p>Your profile metadata is being loaded...</p>
<button <button
@ -3370,6 +3397,7 @@
.profile-loading-section { .profile-loading-section {
padding: 1rem; padding: 1rem;
text-align: center; text-align: center;
position: relative; /* Allow absolute positioning of floating logout button */
} }
.profile-loading-section h3 { .profile-loading-section h3 {

2
pkg/version/version

@ -1 +1 @@
v0.19.4 v0.19.5
Loading…
Cancel
Save