|
1 |
| - |
| 1 | +/* eslint-disable @typescript-eslint/no-explicit-any */ |
2 | 2 | import Pagination from "@/components/Pagination";
|
3 | 3 | import { answerCollection, db, questionCollection, voteCollection } from "@/models/name";
|
4 | 4 | import { databases } from "@/models/server/config";
|
@@ -30,46 +30,72 @@ const Page = async (
|
30 | 30 |
|
31 | 31 | const votes = await databases.listDocuments(db, voteCollection, query);
|
32 | 32 |
|
33 |
| - votes.documents = await Promise.all( |
| 33 | + votes.documents = (await Promise.all( |
34 | 34 | votes.documents.map(async vote => {
|
35 |
| - const questionOfTypeQuestion = |
36 |
| - vote.type === "question" |
37 |
| - ? await databases.getDocument(db, questionCollection, vote.typeId, [ |
38 |
| - Query.select(["title"]), |
39 |
| - ]) |
40 |
| - : null; |
| 35 | + try { |
| 36 | + // For votes on questions |
| 37 | + if (vote.type === "question") { |
| 38 | + const questionOfTypeQuestion = await databases.getDocument( |
| 39 | + db, |
| 40 | + questionCollection, |
| 41 | + vote.typeId, |
| 42 | + [Query.select(["title"])] |
| 43 | + ); |
| 44 | + |
| 45 | + return { |
| 46 | + ...vote, |
| 47 | + question: questionOfTypeQuestion, |
| 48 | + }; |
| 49 | + } |
| 50 | + |
| 51 | + // For votes on answers |
| 52 | + try { |
| 53 | + const answer = await databases.getDocument(db, answerCollection, vote.typeId); |
| 54 | + const questionOfTypeAnswer = await databases.getDocument( |
| 55 | + db, |
| 56 | + questionCollection, |
| 57 | + answer.questionId, |
| 58 | + [Query.select(["title"])] |
| 59 | + ); |
41 | 60 |
|
42 |
| - if (questionOfTypeQuestion) { |
| 61 | + return { |
| 62 | + ...vote, |
| 63 | + question: questionOfTypeAnswer, |
| 64 | + }; |
| 65 | + } catch (error:any) { |
| 66 | + // If answer or its question is deleted, mark it |
| 67 | + console.log(error) |
| 68 | + return { |
| 69 | + ...vote, |
| 70 | + question: { |
| 71 | + $id: vote.typeId, |
| 72 | + title: "[Deleted Content]", |
| 73 | + }, |
| 74 | + }; |
| 75 | + } |
| 76 | + } catch (error:any) { |
| 77 | + console.log(error) |
| 78 | + // Return a placeholder for deleted content |
43 | 79 | return {
|
44 | 80 | ...vote,
|
45 |
| - question: questionOfTypeQuestion, |
| 81 | + question: { |
| 82 | + $id: vote.typeId, |
| 83 | + title: "[Deleted Content]", |
| 84 | + }, |
46 | 85 | };
|
47 | 86 | }
|
48 |
| - |
49 |
| - const answer = await databases.getDocument(db, answerCollection, vote.typeId); |
50 |
| - const questionOfTypeAnswer = await databases.getDocument( |
51 |
| - db, |
52 |
| - questionCollection, |
53 |
| - answer.questionId, |
54 |
| - [Query.select(["title"])] |
55 |
| - ); |
56 |
| - |
57 |
| - return { |
58 |
| - ...vote, |
59 |
| - question: questionOfTypeAnswer, |
60 |
| - }; |
61 | 87 | })
|
62 |
| - ); |
| 88 | + )).filter(vote => vote !== null); // Remove any null entries |
63 | 89 |
|
64 | 90 | return (
|
65 | 91 | <div className="px-4">
|
66 | 92 | <Particles
|
67 |
| - className="fixed inset-0 h-full w-full" |
68 |
| - quantity={500} |
69 |
| - ease={100} |
70 |
| - color="#ffffff" |
71 |
| - refresh |
72 |
| - /> |
| 93 | + className="fixed inset-0 h-full w-full" |
| 94 | + quantity={500} |
| 95 | + ease={100} |
| 96 | + color="#ffffff" |
| 97 | + refresh |
| 98 | + /> |
73 | 99 | <div className="mb-4 flex justify-between">
|
74 | 100 | <p>{votes.total} votes</p>
|
75 | 101 | <ul className="flex gap-1">
|
@@ -118,12 +144,18 @@ const Page = async (
|
118 | 144 | <div className="flex">
|
119 | 145 | <p className="mr-4 shrink-0">{vote.voteStatus}</p>
|
120 | 146 | <p>
|
121 |
| - <Link |
122 |
| - href={`/questions/${vote.question.$id}/${slugify(vote.question.title)}`} |
123 |
| - className="text-orange-500 hover:text-orange-600" |
124 |
| - > |
125 |
| - {vote.question.title} |
126 |
| - </Link> |
| 147 | + {vote.question.title === "[Deleted Content]" ? ( |
| 148 | + <span className="text-gray-500 italic"> |
| 149 | + {vote.question.title} |
| 150 | + </span> |
| 151 | + ) : ( |
| 152 | + <Link |
| 153 | + href={`/questions/${vote.question.$id}/${slugify(vote.question.title)}`} |
| 154 | + className="text-orange-500 hover:text-orange-600" |
| 155 | + > |
| 156 | + {vote.question.title} |
| 157 | + </Link> |
| 158 | + )} |
127 | 159 | </p>
|
128 | 160 | </div>
|
129 | 161 | <p className="text-right text-sm">
|
|
0 commit comments