-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Context
The current useShareTarget() hook (implemented in PR #100) uses a simplified GET-based approach that reads shared data from URL parameters. However, the PWA manifest configuration in vite.config.ts is already set up to use POST method with multipart/form-data, which supports file sharing.
Current Implementation
Hook: src/hooks/useShareTarget.ts
// Current: GET method, URL parameters only
if (url.pathname === "/share" && url.searchParams.size > 0) {
const data: SharedData = {
title: url.searchParams.get("title") || undefined,
text: url.searchParams.get("text") || undefined,
url: url.searchParams.get("url") || undefined,
};
}Manifest: vite.config.ts (lines 112-127)
share_target: {
action: "/share",
method: "POST",
enctype: "multipart/form-data",
params: {
title: "title",
text: "text",
url: "url",
files: [
{
name: "files",
accept: ["image/*", "application/pdf", ".doc", ".docx"],
},
],
},
}Gap
The hook doesn't handle:
- ❌ POST request data (currently only reads URL params)
- ❌ FormData parsing
- ❌ File handling from
filesparameter - ❌ Service Worker integration for file caching
Proposed Enhancement
Option 1: Client-Side FormData Handling
Create a dedicated /share route component that:
- Reads FormData from POST request on initial load
- Extracts text fields (title, text, url) and files
- Passes data to the hook or context
- Handles file preview/upload
Option 2: Service Worker Integration
Enhance the service worker to:
- Intercept POST requests to
/share - Cache files in IndexedDB
- Forward metadata to the client
- Allow client to retrieve cached files
Option 3: Hybrid Approach (Recommended)
- Use GET for text-only sharing (current implementation)
- Add POST handler for file sharing in a separate route component
- Keep both methods working in parallel
- Update manifest to support both:
share_target: [
{
action: "/share/text",
method: "GET",
enctype: "application/x-www-form-urlencoded",
params: { title: "title", text: "text", url: "url" }
},
{
action: "/share/files",
method: "POST",
enctype: "multipart/form-data",
params: { title: "title", text: "text", url: "url", files: [...] }
}
]Tasks
- Research best practices for POST-based Share Target API
- Decide on implementation approach (Option 1, 2, or 3)
- Create
/shareroute component for handling POST requests - Update
useShareTargethook or create newuseShareTargetFileshook - Add FormData parsing logic
- Implement file handling (preview, validation, upload)
- Add Service Worker support for file caching (if needed)
- Update tests to cover POST method and file handling
- Update
PWA_PHASE3_TESTING.mdwith file sharing test scenarios - Add examples to documentation
Benefits
- 🎯 Full utilization of existing manifest configuration
- 📁 Support for sharing files (images, PDFs, documents)
- 🔗 Richer integration with OS share dialogs
- 💪 More powerful PWA capabilities
References
- Web Share Target API - MDN
- Receiving shared data - web.dev
- Current PR: feat: Implement PWA Phase 3 features (Push Notifications, Share Target API, Offline Analytics) #100
- Related Issue: Phase 3: Advanced PWA Features #67 (PWA Phase 3)
Priority
Medium - The current GET-based implementation works for text sharing. File support is a nice-to-have enhancement that can be added incrementally.
Labels
enhancement, pwa, good-first-issue
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
Type
Projects
Status
✅ Done