a tool for shared writing and social publishing

sort posts properly

+22 -22
+22 -22
feeds/index.ts
··· 32 32 .from("publication_subscriptions") 33 33 .select(`publications(documents_in_publications(documents(*)))`) 34 34 .eq("identity", auth); 35 - const feed = (publications || []).flatMap((pub) => { 36 - let posts = pub.publications?.documents_in_publications || []; 37 - return posts 38 - .sort((a, b) => { 39 - let aRecord = a.documents?.data! as PubLeafletDocument.Record; 40 - let bRecord = b.documents?.data! as PubLeafletDocument.Record; 41 - const aDate = aRecord.publishedAt 42 - ? new Date(aRecord.publishedAt) 43 - : new Date(0); 44 - const bDate = bRecord.publishedAt 45 - ? new Date(bRecord.publishedAt) 46 - : new Date(0); 47 - return bDate.getTime() - aDate.getTime(); // Sort by most recent first 48 - }) 49 - .flatMap((p) => { 50 - if (!p.documents?.data) return []; 51 - let record = p.documents.data as PubLeafletDocument.Record; 52 - if (!record.postRef) return []; 53 - return { post: record.postRef.uri }; 54 - }); 55 - }); 56 - 35 + const feed = (publications || []) 36 + .flatMap((pub) => { 37 + let posts = pub.publications?.documents_in_publications || []; 38 + return posts; 39 + }) 40 + .sort((a, b) => { 41 + let aRecord = a.documents?.data! as PubLeafletDocument.Record; 42 + let bRecord = b.documents?.data! as PubLeafletDocument.Record; 43 + const aDate = aRecord.publishedAt 44 + ? new Date(aRecord.publishedAt) 45 + : new Date(0); 46 + const bDate = bRecord.publishedAt 47 + ? new Date(bRecord.publishedAt) 48 + : new Date(0); 49 + return bDate.getTime() - aDate.getTime(); // Sort by most recent first 50 + }) 51 + .flatMap((p) => { 52 + if (!p.documents?.data) return []; 53 + let record = p.documents.data as PubLeafletDocument.Record; 54 + if (!record.postRef) return []; 55 + return { post: record.postRef.uri }; 56 + }); 57 57 return c.json({ 58 58 feed, 59 59 });