Skip to content

Commit

Permalink
Merge pull request #13 from shaniit-org/dev
Browse files Browse the repository at this point in the history
update on related details issue
  • Loading branch information
Riley1101 authored Nov 25, 2023
2 parents 431fc21 + d5e2da9 commit 692525e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
8 changes: 7 additions & 1 deletion src/lib/components/common/RelatedArticle.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script>
import NewsCard from '$lib/components/common/NewsCard.svelte';
import EventCard from './EventCard.svelte';
/** @type {import('../../types').RelatedArticle[] | undefined} */
export let data;
</script>
Expand All @@ -10,7 +11,12 @@
<h3 class="text-xl mb-4">Related Articles</h3>
<div class="grid grid-cols-1 md:grid-cols-3 lg:grid-cols-4 gap-4 pb-12">
{#each data as itm}
<NewsCard data={itm} />
{#if itm._type == 'event'}
<EventCard data={itm} />
{/if}
{#if itm._type != 'event'}
<NewsCard data={itm} />
{/if}
{/each}
</div>
</div>
Expand Down
25 changes: 13 additions & 12 deletions src/routes/events/[slug]/+page.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getPageData } from '$lib/sanity/query';
const query = `*[_type =="event" && slug.current==$slug][0]{
...,
"related": *[_type == "event" && _id != ^._id && count(categories[@._ref in ^.^.categories[]._ref]) > 0] | order(publishedAt desc, _createdAt desc) [0..2] {
_type,
title,
coverImage,
_id,
Expand All @@ -16,16 +17,16 @@ const query = `*[_type =="event" && slug.current==$slug][0]{
* @type {import('@sveltejs/kit').Load}
*/
export const load = async ({ params }) => {
/** @type {string} */
if (params.slug) {
/**
* @type {import('$lib/types').EventDetail}
*/
const data = await getPageData(query, {
slug: params.slug
});
if (data) return { data };
else throw error(404, 'not found');
}
throw error(404, 'not found');
/** @type {string} */
if (params.slug) {
/**
* @type {import('$lib/types').EventDetail}
*/
const data = await getPageData(query, {
slug: params.slug
});
if (data) return { data };
else throw error(404, 'not found');
}
throw error(404, 'not found');
};

0 comments on commit 692525e

Please sign in to comment.