Skip to content
This repository was archived by the owner on Jul 7, 2026. It is now read-only.

feat(reservar): load weekly statuses asynchronously#191

Merged
marpisco merged 1 commit into
mainfrom
codex/add-weekly-reservation-availability-endpoint
Jul 6, 2026
Merged

feat(reservar): load weekly statuses asynchronously#191
marpisco merged 1 commit into
mainfrom
codex/add-weekly-reservation-availability-endpoint

Conversation

@marpisco

@marpisco marpisco commented Jul 5, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Provide a focused API to return weekly reservation availability so the reservation page can load statuses asynchronously and improve perceived performance.
  • Keep the existing server-side rendering as a functional fallback when JavaScript is not available.

Description

  • Added api/reservation_statuses.php which validates sala and optional before week parameters, enforces the same session/auth guards used elsewhere, queries tempos and reservas via prepared statements, and returns a JSON structure with days, tempos, and per-slot slots including status, label, requisitor, canInteract, and canCreateReservation flags.
  • Added assets/reservation-statuses.js to fetch the API, show skeleton cells while loading, render slot cells (including bulk-checkbox and links when allowed), update week navigation links, and push/pop history so the URL and navigation remain understandable.
  • Updated reservar/index.php to include the new script, mark the table with id='reservationTable' and data-sala/data-before, add id='reservationTableBody' and .reservation-day-header for dynamic updates, and add data-week-before attributes to the week navigation links; the original server-rendered table remains as the no-JS fallback.
  • Reused existing DB helpers, session checks, and prepared statements; did not add dependencies or change authorization logic.

Testing

  • Ran PHP syntax checks across the repo with php -l (including new api/reservation_statuses.php and modified reservar/index.php) and no syntax errors were reported. (passed)
  • Checked the new JavaScript with node --check assets/reservation-statuses.js and it reported no syntax errors. (passed)
  • Ran whitespace/diff checks with git diff --check and fixed issues where needed. (passed)

Codex Task

Copilot AI review requested due to automatic review settings July 5, 2026 02:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown

📝 Manual Update Required? It looks like you've modified core logic. Please check if the user manual needs a refresh! @marpisco

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 86f4a284d1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

window.history.pushState({ before: data.before || '' }, '', url.toString());
}
})
.catch(() => window.location.reload());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Stop reloading on unrecoverable fetch errors

If the API returns a persistent 400/404, for example from a bookmarked URL whose sala was deleted or a before value that is not accepted by api/reservation_statuses.php, this reloads the exact same page; DOMContentLoaded immediately issues the same failing fetch again, causing an endless refresh loop instead of leaving the server-rendered fallback or showing an error.

Useful? React with 👍 / 👎.

Comment on lines +45 to +47
document.querySelectorAll('.reservation-day-header').forEach((header, index) => {
if (data.days[index]) header.innerHTML = data.days[index].label;
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Recompute header styling when changing weeks

When a user navigates weeks through the new async links, this only replaces each header's label and leaves the inline style that was rendered for the original week. Because the initial PHP markup encodes today/past state in that style, moving to another week keeps the old blue highlight or opacity on the same column, so the UI can mark the wrong date as today or past even though the API returns fresh isToday/isPast values.

Useful? React with 👍 / 👎.

marpisco commented Jul 5, 2026

Copy link
Copy Markdown
Owner Author

@codex Please fix PR #191 before merge.

Local checkout/static testing passes, but there are still user-visible issues in the async reservation table:

  1. Stop the infinite reload loop on persistent API errors. In assets/reservation-statuses.js, the fetch catch currently reloads the page. If /api/reservation_statuses.php returns a persistent 400/404, such as an invalid before value or deleted sala, the page reloads forever. Show a non-looping error or leave the server-rendered fallback visible instead.

  2. Recompute day-header styling when changing weeks asynchronously. The API returns isToday and isPast, but the JS only replaces each .reservation-day-header label. The old PHP-rendered inline style for today/past remains on the same column after week navigation, so the wrong day can stay highlighted or faded.

  3. Preserve whole-cell click behavior for free slots. The server-rendered table uses availability-cell and data-href so clicking the body of a free cell opens manage.php. The async-rendered cells only put a link around the inner label, so the clickable area regresses.

Keep the fix scoped to assets/reservation-statuses.js and only adjust api/reservation_statuses.php or reservar/index.php if needed for those behaviors.

@chatgpt-codex-connector

Copy link
Copy Markdown

Summary

Testing

  • node --check assets/reservation-statuses.js
  • git diff --check

View task →

@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown

📝 Manual Update Required? It looks like you've modified core logic. Please check if the user manual needs a refresh! @marpisco

Adds a small reservation statuses API for weekly room availability.

The reservation page now renders the existing server-side table as a fallback, then fetches the weekly statuses on load and when navigating between weeks. The navigation links and browser URL stay in sync with the selected week.

Tested with PHP syntax checks for all PHP files, a JavaScript syntax check, and git diff whitespace checks.

Co-authored-by: Codex <noreply@openai.com>
@marpisco

marpisco commented Jul 5, 2026

Copy link
Copy Markdown
Owner Author

@codex my page is being force dragged down as soon as it loads, and keeps being dragged down forever. Check what is causing this behavior.

Copilot AI review requested due to automatic review settings July 5, 2026 04:02
@marpisco marpisco force-pushed the codex/add-weekly-reservation-availability-endpoint branch from 1d1de31 to 4348409 Compare July 5, 2026 04:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown

📝 Manual Update Required? It looks like you've modified core logic. Please check if the user manual needs a refresh! @marpisco

@chatgpt-codex-connector

Copy link
Copy Markdown

Summary

  • Found the likely cause of the “page being dragged down” behavior: on DOMContentLoaded, the script immediately replaced the already server-rendered reservation table with skeleton cells and then re-rendered it asynchronously. That layout churn can fight browser scroll anchoring during page load. I removed the initial automatic async reload while keeping async week navigation and browser history navigation intact. assets/reservation-statuses.jsL177-L191
  • Committed the fix on the current branch with commit 57f687b.
  • Created the follow-up PR: fix(reservar): avoid initial async table rerender scroll jump.

Testing

  • node --check assets/reservation-statuses.js
  • git diff --check

View task →

@marpisco marpisco merged commit 4348409 into main Jul 6, 2026
6 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants