Skip to content

Conversation

@hexawulf
Copy link
Owner

This commit introduces a public view system, allowing unauthenticated users to browse and discover public code snippets.

Key changes include:

  • Public Landing Page (PublicHome.tsx): A new page at the root (/) for unauthenticated users, featuring a grid of public snippets, search, and language filtering.
  • Public API Endpoints (server/routes.ts):
    • GET /api/public/snippets: Serves all snippets marked as public, with support for search and filtering.
    • GET /api/public/snippets/:id: Serves a single public snippet by ID.
      These endpoints do not require authentication.
  • Storage Layer Updates (server/storage.ts):
    • getSnippets method in MemStorage and DatabaseStorage now supports an isPublic filter.
    • Sample data in MemStorage updated to include public/private snippets.
  • Authentication-Aware Components:
    • App.tsx: Main router now directs unauthenticated users to PublicHome and authenticated users to their dashboard. Shared snippet routes are accessible in both contexts.
    • Layout.tsx: Accepts an isPublicView prop to render a simplified layout (no sidebar) for public views.
    • SnippetCard.tsx: Accepts isPublicView and uses AuthContext to conditionally display action buttons (Edit, Delete, Favorite, etc.) based on ownership and view context. A "Public" badge is shown for public snippets.
    • SnippetGrid.tsx: Accepts isPublicView, passes it to SnippetCard, and customizes the empty state message.
  • Schema (shared/schema.ts): Confirmed userId and isPublic fields are present.
  • Testing:
    • Unit test structures created for server/storage.ts (isPublic filter), client/src/components/SnippetCard.tsx (conditional rendering), and server/routes.ts (public API endpoints).
    • An INTEGRATION_TESTS.md file was created outlining integration tests for PublicHome.tsx and routing behavior.

This implementation allows CodePatchwork to serve a broader audience by making public snippets accessible without requiring user login, while maintaining security for private snippets and full functionality for authenticated users.

This commit introduces a public view system, allowing unauthenticated users to browse and discover public code snippets.

Key changes include:

-   **Public Landing Page (`PublicHome.tsx`):** A new page at the root (/) for unauthenticated users, featuring a grid of public snippets, search, and language filtering.
-   **Public API Endpoints (`server/routes.ts`):**
    -   `GET /api/public/snippets`: Serves all snippets marked as public, with support for search and filtering.
    -   `GET /api/public/snippets/:id`: Serves a single public snippet by ID.
    These endpoints do not require authentication.
-   **Storage Layer Updates (`server/storage.ts`):**
    -   `getSnippets` method in `MemStorage` and `DatabaseStorage` now supports an `isPublic` filter.
    -   Sample data in `MemStorage` updated to include public/private snippets.
-   **Authentication-Aware Components:**
    -   `App.tsx`: Main router now directs unauthenticated users to `PublicHome` and authenticated users to their dashboard. Shared snippet routes are accessible in both contexts.
    -   `Layout.tsx`: Accepts an `isPublicView` prop to render a simplified layout (no sidebar) for public views.
    -   `SnippetCard.tsx`: Accepts `isPublicView` and uses `AuthContext` to conditionally display action buttons (Edit, Delete, Favorite, etc.) based on ownership and view context. A "Public" badge is shown for public snippets.
    -   `SnippetGrid.tsx`: Accepts `isPublicView`, passes it to `SnippetCard`, and customizes the empty state message.
-   **Schema (`shared/schema.ts`):** Confirmed `userId` and `isPublic` fields are present.
-   **Testing:**
    -   Unit test structures created for `server/storage.ts` (isPublic filter), `client/src/components/SnippetCard.tsx` (conditional rendering), and `server/routes.ts` (public API endpoints).
    -   An `INTEGRATION_TESTS.md` file was created outlining integration tests for `PublicHome.tsx` and routing behavior.

This implementation allows CodePatchwork to serve a broader audience by making public snippets accessible without requiring user login, while maintaining security for private snippets and full functionality for authenticated users.
@hexawulf hexawulf merged commit c42980c into main May 26, 2025
1 check failed
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.

2 participants