feat: add community publishing and news syndication
This commit is contained in:
@@ -4,26 +4,33 @@ import { databaseCategories } from '$lib/database/categories';
|
||||
import type { PageServerLoad } from './$types';
|
||||
|
||||
const tables = {
|
||||
gear: 'gear',
|
||||
weapons: 'weapons',
|
||||
'weapon-mods': 'weapon_mods',
|
||||
'gear-mods': 'gear_mods',
|
||||
'os-protocols': 'os_protocols',
|
||||
talents: 'talents',
|
||||
brands: 'brand_sets',
|
||||
'skill-chips': 'skill_chip_sets',
|
||||
specializations: 'specializations'
|
||||
gear: 'gear',
|
||||
weapons: 'weapons',
|
||||
'weapon-mods': 'weapon_mods',
|
||||
'gear-mods': 'gear_mods',
|
||||
'os-protocols': 'os_protocols',
|
||||
talents: 'talents',
|
||||
brands: 'brand_sets',
|
||||
'skill-chips': 'skill_chip_sets',
|
||||
specializations: 'specializations',
|
||||
} as const;
|
||||
|
||||
export const load: PageServerLoad = async ({ url }) => {
|
||||
const database = await getDatabase();
|
||||
const { search, pattern } = getRegistrySearch(url);
|
||||
const counts = await Promise.all(databaseCategories.map(async (category) => {
|
||||
const row = await (await database.prepare(`SELECT COUNT(*) AS count FROM ${tables[category.slug]} WHERE active=1`)).get();
|
||||
return { ...category, count: Number(row?.count ?? 0) };
|
||||
}));
|
||||
const searchResults = search
|
||||
? await (await database.prepare(`
|
||||
const database = await getDatabase();
|
||||
const { search, pattern } = getRegistrySearch(url);
|
||||
const counts = await Promise.all(
|
||||
databaseCategories.map(async (category) => {
|
||||
const row = await (
|
||||
await database.prepare(
|
||||
`SELECT COUNT(*) AS count FROM ${tables[category.slug]} WHERE active=1`,
|
||||
)
|
||||
).get();
|
||||
return { ...category, count: Number(row?.count ?? 0) };
|
||||
}),
|
||||
);
|
||||
const searchResults = search
|
||||
? await (
|
||||
await database.prepare(`
|
||||
SELECT * FROM (
|
||||
SELECT 'gear' AS slug,'Gear' AS category,item.name,
|
||||
item.slot || ' · T' || item.tier AS detail
|
||||
@@ -113,17 +120,18 @@ export const load: PageServerLoad = async ({ url }) => {
|
||||
) matches
|
||||
ORDER BY name COLLATE NOCASE
|
||||
LIMIT 40
|
||||
`)).all(...Array(27).fill(pattern))
|
||||
: [];
|
||||
return {
|
||||
registries: counts,
|
||||
total: counts.reduce((total, registry) => total + registry.count, 0),
|
||||
search,
|
||||
searchResults: searchResults.map((result) => ({
|
||||
slug: String(result.slug),
|
||||
category: String(result.category),
|
||||
name: String(result.name),
|
||||
detail: String(result.detail ?? '')
|
||||
}))
|
||||
};
|
||||
`)
|
||||
).all(...Array(27).fill(pattern))
|
||||
: [];
|
||||
return {
|
||||
registries: counts,
|
||||
total: counts.reduce((total, registry) => total + registry.count, 0),
|
||||
search,
|
||||
searchResults: searchResults.map((result) => ({
|
||||
slug: String(result.slug),
|
||||
category: String(result.category),
|
||||
name: String(result.name),
|
||||
detail: String(result.detail ?? ''),
|
||||
})),
|
||||
};
|
||||
};
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,15 @@
|
||||
import DatabaseCategoryNav from '$lib/components/DatabaseCategoryNav.svelte';
|
||||
import DatabaseItemCard from '$lib/components/DatabaseItemCard.svelte';
|
||||
import DatabaseDiscoveryConsole from '$lib/components/DatabaseDiscoveryConsole.svelte';
|
||||
let { data } = $props();
|
||||
import DatabaseDiscussionDialog from '$lib/components/DatabaseDiscussionDialog.svelte';
|
||||
import { page } from '$app/state';
|
||||
let { data, form } = $props();
|
||||
const discussionCloseHref = () => {
|
||||
const target = new URL(page.url);
|
||||
target.searchParams.delete('discussion');
|
||||
target.hash = data.selectedItem ? `database-item-${data.selectedItem.id}` : '';
|
||||
return `${target.pathname}${target.search}${target.hash}`;
|
||||
};
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
@@ -27,4 +35,7 @@
|
||||
</div>
|
||||
{/each}
|
||||
</section>
|
||||
{#if data.selectedItem}
|
||||
<DatabaseDiscussionDialog item={data.selectedItem} comments={data.discussionComments} viewer={data.viewer} {form} signInHref={`/sign-in?returnTo=${encodeURIComponent(`/database/${data.category.slug}?discussion=${data.selectedItem.id}`)}`} closeHref={discussionCloseHref()}/>
|
||||
{/if}
|
||||
</main>
|
||||
|
||||
Reference in New Issue
Block a user