ATlast — you'll never need to find your favorites on another platform again. Find your favs in the ATmosphere.
atproto
1import { parseDataFile } from "../lib/parsers/fileExtractor"; 2import type { SearchResult, UserSettings } from "../types"; 3 4export function useFileUpload( 5 onSearchStart: (results: SearchResult[], platform: string) => void, 6 onStatusUpdate: (message: string) => void, 7 userSettings: UserSettings, 8) { 9 async function handleFileUpload( 10 e: React.ChangeEvent<HTMLInputElement>, 11 platform: string = "tiktok", 12 ) { 13 const file = e.target.files?.[0]; 14 if (!file) return; 15 16 onStatusUpdate(`Processing ${file.name}...`); 17 let usernames: string[] = []; 18 19 try { 20 usernames = await parseDataFile(file, platform); 21 22 console.log(`Loaded ${usernames.length} users from ${platform} data`); 23 onStatusUpdate(`Loaded ${usernames.length} users from ${platform} data`); 24 } catch (error) { 25 console.error("Error processing file:", error); 26 27 const errorMsg = 28 error instanceof Error 29 ? error.message 30 : "There was a problem processing the file. Please check that it's a valid data export."; 31 32 onStatusUpdate(errorMsg); 33 alert(errorMsg); 34 return; 35 } 36 37 if (usernames.length === 0) { 38 const errorMsg = "No users found in the file."; 39 onStatusUpdate(errorMsg); 40 alert(errorMsg); 41 return; 42 } 43 44 const initialResults: SearchResult[] = usernames.map((username) => ({ 45 sourceUser: { 46 username: username, 47 date: "", 48 }, 49 atprotoMatches: [], 50 isSearching: false, 51 selectedMatches: new Set<string>(), 52 sourcePlatform: platform, 53 })); 54 55 onStatusUpdate(`Starting search for ${usernames.length} users...`); 56 onSearchStart(initialResults, platform); 57 } 58 59 return { 60 handleFileUpload, 61 }; 62}