Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for threads #505

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/routes/support-threads/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,21 @@
};
};

const tags = ['Web', 'Flutter', 'Javascript', 'Dart', 'Apple'];
const tags = ['Web', 'Flutter', 'GraphQL', 'Cloud', 'Self Hosted'];
const moreTags = [
'Self hosted',
'Tools',
'Accounts',
'Users',
'Teams',
'Databases',
'Storage',
'Functions',
'Cloud',
'Android',
'Windows',
'Linux',
'MacOS',
'iOS',
'iPadOS',
'WatchOS'
'Realtime',
'Locale',
'Avatars',
'Webhooks',
'General',
'REST API'
];
const _selectedTags = queryParam<string[]>('tags', {
encode(value) {
Expand Down
1 change: 1 addition & 0 deletions src/routes/support-threads/TagsDropdown.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
class="aw-card is-normal has-border-gradient menu"
use:melt={menu}
transition:fly={{ y: 8, duration: 250 }}
style:z-index="1"
>
{#each tags as tag}
{@const checked = selectedTags?.includes(tag)}
Expand Down
9 changes: 1 addition & 8 deletions src/routes/support-threads/[id]/+page.server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { random } from '$lib/utils/random.js';
import { error } from '@sveltejs/kit';
import { getRelatedThreads, getThread, getThreadMessages, getThreadTldr } from '../helpers.js';
import { getRelatedThreads, getThread, getThreadMessages } from '../helpers.js';

export const prerender = false;

Expand All @@ -12,16 +11,10 @@ export const load = async ({ params }) => {
const related = await getRelatedThreads(thread);
const messages = await getThreadMessages(id);

const upvotes = random(1, 60);

return {
...thread,
related,
upvotes,
messages,
streamed: {
tldr: getThreadTldr(thread)
}
};
} catch (e) {
console.log(e);
Expand Down
25 changes: 4 additions & 21 deletions src/routes/support-threads/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<ul class="tags">
<li class="aw-tag">
<span class="aw-icon-arrow-up" />
<span class="text">{data.upvotes}</span>
<span class="text">{data.vote_count}</span>
</li>
{#each data.tags ?? [] as tag}
<li class="aw-tag">
Expand All @@ -58,7 +58,7 @@
<div class="buttons">
<a
class="aw-button"
href="https://discord.com/channels/1096473701832200302/{data.discord_id}"
href="https://discord.com/channels/564160730845151244/{data.discord_id}"
>
<span class="aw-icon-discord" />
<span class="text">View on Discord</span>
Expand All @@ -79,24 +79,7 @@
>
TL;DR
</span>
{#if data.tldr}
{data.tldr}
{:else}
{#await data.streamed.tldr}
<div class="dots" aria-label="loading">
<!-- eslint-disable-next-line @typescript-eslint/no-unused-vars -->
{#each { length: 3 } as _, i}
<div
class="dot"
aria-hidden="true"
style:--p-index={i}
/>
{/each}
</div>
{:then res}
{res}
{/await}
{/if}
{data.tldr}
</div>
{/if}
</MessageCard>
Expand All @@ -108,7 +91,7 @@
</p>
<a
class="aw-button u-margin-block-start-24"
href="https://discord.com/channels/1096473701832200302/{data.discord_id}"
href="https://discord.com/channels/564160730845151244/{data.discord_id}"
>
<span class="aw-icon-discord" />
<span class="text">Reply on Discord</span>
Expand Down
17 changes: 1 addition & 16 deletions src/routes/support-threads/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,4 @@ export async function getThreadMessages(threadId: string) {
return (data.documents as unknown as DiscordMessage[]).sort(
(a, b) => new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime()
);
}

export async function getThreadTldr(thread: DiscordThread) {
if (thread.tldr) return thread.tldr;

const execution = await functions.createExecution(
PUBLIC_APPWRITE_FN_TLDR_ID,
JSON.stringify({ thread: thread.$id }),
false,
'/',
'POST'
);
const { tldr } = JSON.parse(execution.responseBody);

return tldr;
}
}