request full content when viewing feedback
All checks were successful
delpoy / build-and-deploy (push) Successful in 51s
All checks were successful
delpoy / build-and-deploy (push) Successful in 51s
This commit is contained in:
parent
1ea07f7666
commit
7ec1d8ab1d
@ -20,6 +20,7 @@
|
||||
limit?: number;
|
||||
from?: number;
|
||||
hash?: string;
|
||||
preview?: boolean;
|
||||
}): Promise<Feedback[]> {
|
||||
if (!browser) return [];
|
||||
|
||||
@ -27,6 +28,8 @@
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
...feedbackFilter,
|
||||
preview: extendedFilter?.preview ?? true,
|
||||
hash: extendedFilter?.hash ?? undefined,
|
||||
limit: extendedFilter?.limit ?? feedbacksPerRequest,
|
||||
from: extendedFilter?.from ?? feedbacks.length
|
||||
})
|
||||
@ -38,19 +41,14 @@
|
||||
if (!window.location.hash) return;
|
||||
|
||||
const requestedHash = window.location.hash.substring(1);
|
||||
let feedback = feedbacks.find((r) => r.url_hash === requestedHash);
|
||||
if (!feedback) {
|
||||
const hashFeedback = (await fetchFeedback({ hash: requestedHash }))[0];
|
||||
if (hashFeedback) {
|
||||
feedback = [hashFeedback, ...feedback];
|
||||
feedback = hashFeedback;
|
||||
} else {
|
||||
await goto(window.location.href.split('#')[0], { replaceState: true });
|
||||
return;
|
||||
}
|
||||
|
||||
const hashFeedback = await fetchFeedback({ hash: requestedHash, preview: false });
|
||||
if (!hashFeedback) {
|
||||
await goto(window.location.href.split('#')[0], { replaceState: true });
|
||||
return;
|
||||
}
|
||||
|
||||
activeFeedback = feedback;
|
||||
activeFeedback = hashFeedback[0];
|
||||
}
|
||||
|
||||
onMount(async () => {
|
||||
@ -84,11 +82,11 @@
|
||||
<tr
|
||||
class="hover [&>*]:text-sm cursor-pointer"
|
||||
class:bg-base-200={activeFeedback?.url_hash === feedback.url_hash}
|
||||
on:click={() => {
|
||||
goto(`${window.location.href.split('#')[0]}#${feedback.url_hash}`, {
|
||||
on:click={async () => {
|
||||
await goto(`${window.location.href.split('#')[0]}#${feedback.url_hash}`, {
|
||||
replaceState: true
|
||||
});
|
||||
activeFeedback = feedback;
|
||||
await openHashReport();
|
||||
}}
|
||||
>
|
||||
<td title={feedback.event}>{feedback.event}</td>
|
||||
|
@ -33,19 +33,21 @@ export const POST = (async ({ request, cookies }) => {
|
||||
where: { username: { [Op.like]: `%${data.username}%` } }
|
||||
}).then((users) => users.map((user) => user.id))
|
||||
});
|
||||
if (data.hash) Object.assign(feedbackFindOptions, { url_hash: data.hash, from: 0, limit: 1 });
|
||||
if (data.hash) Object.assign(feedbackFindOptions, { url_hash: data.hash });
|
||||
|
||||
let feedback = await Feedback.findAll({
|
||||
where: feedbackFindOptions,
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
attributes: {
|
||||
exclude: ['content'],
|
||||
include: [[sequelize.literal('SUBSTR(content, 1, 50)'), 'content']]
|
||||
},
|
||||
attributes: data.preview
|
||||
? {
|
||||
exclude: ['content'],
|
||||
include: [[sequelize.literal('SUBSTR(content, 1, 50)'), 'content']]
|
||||
}
|
||||
: undefined,
|
||||
include: { model: User, as: 'user' },
|
||||
offset: data.from || 0,
|
||||
limit: data.limit || 100
|
||||
offset: data.hash ? 0 : data.from || 0,
|
||||
limit: data.hash ? 1 : data.limit || 100
|
||||
});
|
||||
|
||||
return new Response(JSON.stringify(feedback));
|
||||
|
@ -9,5 +9,7 @@ export const FeedbackListSchema = z.object({
|
||||
|
||||
hash: z.string().nullish(),
|
||||
|
||||
username: z.string().nullish()
|
||||
username: z.string().nullish(),
|
||||
|
||||
preview: z.boolean().nullish()
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user