feat: Implement public view system #1
Merged
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.