Skip to content

feat(videos): [255,283,284] add routing, loading optimization and responsive layout fixes#156

Merged
farhan2742 merged 1 commit into
arbisoft:devfrom
arbisoft-qaisarirfan:255-283-284
Mar 19, 2026
Merged

feat(videos): [255,283,284] add routing, loading optimization and responsive layout fixes#156
farhan2742 merged 1 commit into
arbisoft:devfrom
arbisoft-qaisarirfan:255-283-284

Conversation

@arbisoft-qaisarirfan

Copy link
Copy Markdown
Contributor

🚀 Description

This PR merges related frontend improvements (255/283/284) with:

  • login redirect updates
  • loading optimization for list retrieval
  • UI fixes for medium screens
  • improved unit test coverage

📌 Summary

  • loginPage now redirects to a validated redirect_to video path (fallback /videos).
  • Middleware hardened for protected /videos* routes.
  • VideosListingPage, SearchResultsPage, and VideoDetail UI paths and state branches improved.
  • New tests added for pages + util/middleware behavior.

🔧 Changes Implemented

  • src/middleware.ts: token-based control + safe redirect resolution.
  • src/features/LoginPage/loginPage.tsx: redirect_to handling + path validation.
  • src/features/VideosListingPage/*: filter, empty state, loading, responsive padding/layout.
  • src/features/SearchResultsPage/*: search/no-result/error flows.
  • src/features/VideoDetail/*: loading/recommendations + error redirect.
  • src/utils/utils.ts: utility edge-case correctness.
  • src/features/*/*.test.tsx: Jest tests for all above.

🛠️ How It Works

  1. loginPage obtains redirect param from query/window, validates with isValidInternalRedirectPath.
  2. Valid token on /login -> redirect to requested video or /videos.
  3. Protected route /videos* uses token validation and login redirect query.
  4. Video listing uses debounced getEvents(apiParams) + state output.
  5. Video detail uses safe event lookup + redirect fallback on error or missing data.

✅ Checklist Before Merging

  • Verified behavior in unit tests.
  • npx jest --runInBand passes.
  • No unstable UI states for next line shape.
  • Conforms with internal security path rules.

📸 Screenshots

Not applicable.

🔗 Related Issues

📢 Notes for Reviewers @farhan2742 @arslanather @shaheer-alam-arbisoft

  • Verify safe redirect rules (isValidInternalRedirectPath).
  • Check middleware route logic for protected and auth paths.
  • Validate useTransition login path fallback and error notifications.
  • Confirm new tests cover all key branch conditions.

Copilot AI 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.

Pull request overview

This PR improves the videos experience and auth routing by hardening login redirects, optimizing RTK Query list caching/loading behavior, and applying responsive UI adjustments across listing/search/detail pages, with expanded Jest coverage and accompanying docs updates.

Changes:

  • Add internal redirect_to validation and apply it in both middleware and LoginPage redirect handling.
  • Improve events list caching/loading behavior (RTK Query query-arg serialization + listing/search infinite-scroll UX tweaks).
  • Update responsive layout/styling and expand Jest tests + documentation for the updated flows.

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/utils/utils.ts Adds isValidInternalRedirectPath helper for safe internal redirects.
src/utils/utils.test.ts Adds unit tests for redirect-path validation.
src/middleware.ts Uses validated redirect_to for authenticated /login requests; keeps /videos* protection.
src/middleware.test.ts Adds tests for authenticated /login redirect behavior and external redirect rejection.
src/features/LoginPage/loginPage.tsx Validates redirect_to and adds a fallback read from window.location.search.
src/features/LoginPage/loginPage.test.tsx Adds tests for invalid redirect handling and window-location fallback behavior.
src/redux/events/apiSlice.ts Expands RTK Query cache key serialization to cover more filter params (excluding page).
src/features/VideosListingPage/videosListingPage.tsx Adjusts loading detection and infinite scroll footer/loading behavior.
src/features/VideosListingPage/styled.tsx Updates grid breakpoints for better medium/large screen layouts.
src/features/SearchResultsPage/searchResultsPage.tsx Tweaks infinite scroll viewport + footer loading behavior; removes navigate onClick.
src/features/VideoDetail/videoDetail.tsx Avoids rendering the video player when no video_file is present.
src/redux/store/configureStore.tsx Switches devtools gating to use a constants export.
src/constants/constants.ts Centralizes additional env-derived constants (CLIENT_ID, GTM_ID, NODE_ENV, CI).
src/app/layout.tsx Gates GTM/Hotjar injection to production and uses centralized env constants.
src/features/HomePage/homePage.tsx Removes use client from a purely presentational component.
src/components/theme/init-color-scheme-script.tsx Removes use client from a simple wrapper component.
src/components/containers/MainLayoutContainer/styled.tsx Adjusts large-breakpoint padding when sidebar is not available.
playwright.config.ts Switches CI detection to use a constants export.
README.md Documents npm run test:cov for coverage runs.
docs/testing-guide.md Adds a test coverage section.
docs/state-management-and-api-layer.md Adds an Events API overview section.
docs/routing-and-application-flows.md Updates auth flow docs to reflect validated redirect_to redirect behavior.
Comments suppressed due to low confidence (1)

docs/testing-guide.md:66

  • In this section, the bullet list describing jest.setup.ts behavior appears to be split: the items starting with “enables jest-fetch-mock / mocks … / resets …” are currently placed under “## Test Coverage”, which makes the markdown structure confusing. Consider moving those bullets back under “## Jest Setup Behavior” (or adding a separate heading) so setup behaviors and coverage scope are clearly separated.
## Jest Setup Behavior

`jest.setup.ts` performs several important actions:

- imports `@testing-library/jest-dom`
- imports `whatwg-fetch`

## Test Coverage

Current test suite includes unit tests for:

- Utility functions (`src/utils/utils.ts`)
- Middleware authentication (`src/middleware.ts`)
- Feature pages: HomePage, LoginPage, VideosListingPage, SearchResultsPage, VideoDetail
- Redux slices and API integrations
- Reusable components (Navbar, Sidebar, etc.)

New tests added for previously untested feature pages to improve coverage on routing, loading states, and error handling.
- enables `jest-fetch-mock`
- mocks `@/hooks/useFeatureFlags`
- resets fetch mocks before each test
- populates a global `preloadedState` for Redux-backed tests

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/redux/events/apiSlice.ts Outdated
@@ -1,8 +1,28 @@
import { omit } from "lodash";
import { useTheme } from "@mui/material/styles";
import Typography from "@mui/material/Typography";
import useMediaQuery from "@mui/material/useMediaQuery";
import { isEqual, omit } from "lodash";
Comment thread playwright.config.ts
Comment on lines 1 to 11
import { defineConfig, devices } from "@playwright/test";
import { config } from "dotenv";

import { CI } from "./src/constants/constants";
/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
import { config } from "dotenv";

config({ path: ".env.local" });

Comment thread docs/routing-and-application-flows.md Outdated
Comment on lines +50 to +70
5. On success, the frontend sends the Google `access_token` as `auth_token`
6. Request is sent to `POST /users/login`
7. On success, the app navigates to the validated `redirect_to` path or defaults to `/videos`
8. On failure, a notification is shown

@farhan2742 farhan2742 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.

LGTM

@farhan2742 farhan2742 merged commit 3c9f6de into arbisoft:dev Mar 19, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants