mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
fix(web): add optional order field and sort tweets accordingly
This commit is contained in:
@@ -106,7 +106,7 @@ export default function Testimonials({
|
||||
preloadedTestimonialsVideos: Preloaded<typeof api.testimonials.getVideos>;
|
||||
}) {
|
||||
const videos = usePreloadedQuery(preloadedTestimonialsVideos).reverse();
|
||||
const tweets = usePreloadedQuery(preloadedTestimonialsTweet).reverse();
|
||||
const tweets = usePreloadedQuery(preloadedTestimonialsTweet);
|
||||
|
||||
const getResponsiveColumns = (numCols: number) => {
|
||||
const columns: string[][] = Array(numCols)
|
||||
|
||||
@@ -27,6 +27,7 @@ export default defineSchema({
|
||||
|
||||
tweets: defineTable({
|
||||
tweetId: v.string(),
|
||||
order: v.optional(v.number()),
|
||||
}),
|
||||
|
||||
showcase: defineTable({
|
||||
|
||||
@@ -23,9 +23,18 @@ export const getTweets = query({
|
||||
_id: v.id("tweets"),
|
||||
_creationTime: v.number(),
|
||||
tweetId: v.string(),
|
||||
order: v.optional(v.number()),
|
||||
}),
|
||||
),
|
||||
handler: async (ctx) => {
|
||||
return await ctx.db.query("tweets").collect();
|
||||
const rows = await ctx.db.query("tweets").collect();
|
||||
return rows.sort((a, b) => {
|
||||
const aHas = typeof a.order === "number";
|
||||
const bHas = typeof b.order === "number";
|
||||
if (aHas && bHas) return (a.order as number) - (b.order as number);
|
||||
if (aHas && !bHas) return -1;
|
||||
if (!aHas && bHas) return 1;
|
||||
return b._creationTime - a._creationTime;
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user