Conversation
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit introduces a public view system, allowing unauthenticated users to browse and discover public code snippets.
Key changes include:
PublicHome.tsx): A new page at the root (/) for unauthenticated users, featuring a grid of public snippets, search, and language filtering.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.
server/storage.ts):getSnippetsmethod inMemStorageandDatabaseStoragenow supports anisPublicfilter.MemStorageupdated to include public/private snippets.App.tsx: Main router now directs unauthenticated users toPublicHomeand authenticated users to their dashboard. Shared snippet routes are accessible in both contexts.Layout.tsx: Accepts anisPublicViewprop to render a simplified layout (no sidebar) for public views.SnippetCard.tsx: AcceptsisPublicViewand usesAuthContextto conditionally display action buttons (Edit, Delete, Favorite, etc.) based on ownership and view context. A "Public" badge is shown for public snippets.SnippetGrid.tsx: AcceptsisPublicView, passes it toSnippetCard, and customizes the empty state message.shared/schema.ts): ConfirmeduserIdandisPublicfields are present.server/storage.ts(isPublic filter),client/src/components/SnippetCard.tsx(conditional rendering), andserver/routes.ts(public API endpoints).INTEGRATION_TESTS.mdfile was created outlining integration tests forPublicHome.tsxand 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.