mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2026-02-03 10:34:43 +08:00
[questions][fix] encounter last seen sorting (#530)
Co-authored-by: Jeff Sieu <jeffsy00@gmail.com>
This commit is contained in:
@@ -223,7 +223,7 @@ export default function ContributeQuestionForm({
|
||||
createEncounterButtonText="Yes, this is my question"
|
||||
questionId={question.id}
|
||||
roles={roleCounts}
|
||||
timestamp={question.seenAt}
|
||||
timestamp={question.lastSeenAt}
|
||||
type={question.type}
|
||||
onReceivedSubmit={async (data) => {
|
||||
await addEncounterAsync({
|
||||
|
||||
@@ -210,7 +210,7 @@ export default function QuestionPage() {
|
||||
questionId={question.id}
|
||||
receivedCount={undefined}
|
||||
roles={relabeledAggregatedEncounters?.roleCounts ?? {}}
|
||||
timestamp={question.seenAt}
|
||||
timestamp={question.lastSeenAt}
|
||||
upvoteCount={question.numVotes}
|
||||
onReceivedSubmit={async (data) => {
|
||||
await addEncounterAsync({
|
||||
|
||||
@@ -558,9 +558,7 @@ export default function QuestionsBrowsePage() {
|
||||
questionId={question.id}
|
||||
receivedCount={question.receivedCount}
|
||||
roles={roleCounts}
|
||||
timestamp={
|
||||
question.aggregatedQuestionEncounters.latestSeenAt
|
||||
}
|
||||
timestamp={question.lastSeenAt}
|
||||
type={question.type}
|
||||
upvoteCount={question.numVotes}
|
||||
/>
|
||||
|
||||
@@ -220,7 +220,7 @@ export default function ListPage() {
|
||||
questionId={question.id}
|
||||
receivedCount={question.receivedCount}
|
||||
roles={roleCounts}
|
||||
timestamp={question.seenAt}
|
||||
timestamp={question.lastSeenAt}
|
||||
type={question.type}
|
||||
onDelete={() => {
|
||||
deleteQuestionEntry({ id: entryId });
|
||||
|
||||
@@ -39,7 +39,7 @@ export const questionsQuestionRouter = createRouter()
|
||||
{
|
||||
id: input.sortOrder,
|
||||
},
|
||||
]
|
||||
];
|
||||
break;
|
||||
case SortType.NEW:
|
||||
sortCondition = [
|
||||
@@ -61,7 +61,7 @@ export const questionsQuestionRouter = createRouter()
|
||||
},
|
||||
];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const questionsData = await ctx.prisma.questionsQuestion.findMany({
|
||||
cursor: cursor ? { id: cursor } : undefined,
|
||||
@@ -309,9 +309,8 @@ export const questionsQuestionRouter = createRouter()
|
||||
|
||||
let relatedQuestionsId: Array<{ id: string }> = [];
|
||||
|
||||
if (input.content !== "") {
|
||||
relatedQuestionsId = await ctx.prisma
|
||||
.$queryRaw`
|
||||
if (input.content !== '') {
|
||||
relatedQuestionsId = await ctx.prisma.$queryRaw`
|
||||
SELECT id FROM "QuestionsQuestion"
|
||||
WHERE
|
||||
ts_rank_cd(to_tsvector("content"), to_tsquery(${query}), 32) > 0.1
|
||||
@@ -319,8 +318,6 @@ export const questionsQuestionRouter = createRouter()
|
||||
`;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const relatedQuestionsIdArray = relatedQuestionsId.map(
|
||||
(current) => current.id,
|
||||
);
|
||||
@@ -338,7 +335,7 @@ export const questionsQuestionRouter = createRouter()
|
||||
{
|
||||
id: input.sortOrder,
|
||||
},
|
||||
]
|
||||
];
|
||||
break;
|
||||
case SortType.NEW:
|
||||
sortCondition = [
|
||||
@@ -360,7 +357,7 @@ export const questionsQuestionRouter = createRouter()
|
||||
},
|
||||
];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const questionsData = await ctx.prisma.questionsQuestion.findMany({
|
||||
cursor: cursor ? { id: cursor } : undefined,
|
||||
@@ -391,9 +388,12 @@ export const questionsQuestionRouter = createRouter()
|
||||
orderBy: sortCondition,
|
||||
take: input.limit + 1,
|
||||
where: {
|
||||
id: input.content !== "" ? {
|
||||
in: relatedQuestionsIdArray,
|
||||
} : undefined,
|
||||
id:
|
||||
input.content !== ''
|
||||
? {
|
||||
in: relatedQuestionsIdArray,
|
||||
}
|
||||
: undefined,
|
||||
...(input.questionTypes.length > 0
|
||||
? {
|
||||
questionType: {
|
||||
|
||||
3
apps/portal/src/types/questions.d.ts
vendored
3
apps/portal/src/types/questions.d.ts
vendored
@@ -4,11 +4,11 @@ export type Question = {
|
||||
aggregatedQuestionEncounters: AggregatedQuestionEncounter;
|
||||
content: string;
|
||||
id: string;
|
||||
lastSeenAt: Date | null;
|
||||
numAnswers: number;
|
||||
numComments: number;
|
||||
numVotes: number;
|
||||
receivedCount: number;
|
||||
seenAt: Date;
|
||||
type: QuestionsQuestionType;
|
||||
updatedAt: Date;
|
||||
user: string;
|
||||
@@ -47,7 +47,6 @@ export type Location = CityLocation | CountryLocation | StateLocation;
|
||||
export type AggregatedQuestionEncounter = {
|
||||
companyCounts: Record<string, number>;
|
||||
countryCounts: Record<string, CountryInfo>;
|
||||
latestSeenAt: Date;
|
||||
roleCounts: Record<string, number>;
|
||||
};
|
||||
|
||||
|
||||
@@ -61,11 +61,11 @@ export function createQuestionWithAggregateData(
|
||||
),
|
||||
content: data.content,
|
||||
id: data.id,
|
||||
lastSeenAt: data.lastSeenAt,
|
||||
numAnswers: data._count.answers,
|
||||
numComments: data._count.comments,
|
||||
numVotes: votes,
|
||||
receivedCount: data.encounters.length,
|
||||
seenAt: data.encounters[0].seenAt,
|
||||
type: data.questionType,
|
||||
updatedAt: data.updatedAt,
|
||||
user: data.user?.name ?? '',
|
||||
@@ -80,12 +80,7 @@ export function createAggregatedQuestionEncounter(
|
||||
const companyCounts: Record<string, number> = {};
|
||||
const roleCounts: Record<string, number> = {};
|
||||
|
||||
let latestSeenAt = encounters[0].seenAt;
|
||||
|
||||
for (const encounter of encounters) {
|
||||
latestSeenAt =
|
||||
latestSeenAt < encounter.seenAt ? encounter.seenAt : latestSeenAt;
|
||||
|
||||
if (encounter.company !== null) {
|
||||
if (!(encounter.company.name in companyCounts)) {
|
||||
companyCounts[encounter.company!.name] = 0;
|
||||
@@ -137,7 +132,6 @@ export function createAggregatedQuestionEncounter(
|
||||
return {
|
||||
companyCounts,
|
||||
countryCounts,
|
||||
latestSeenAt,
|
||||
roleCounts,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user