mirror of
https://github.com/ivabus/gui
synced 2025-06-07 15:50:27 +03:00
#106 move specialized endpont usage into centralized posts store
This commit is contained in:
parent
e3002a77c9
commit
40c60a5f74
4 changed files with 20 additions and 16 deletions
|
@ -1,17 +1,14 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import '$appcss';
|
import '$appcss';
|
||||||
import { getAllPosts } from '@api';
|
|
||||||
import type { AirtablePost } from '@tea/ui/types';
|
import type { AirtablePost } from '@tea/ui/types';
|
||||||
import Posts from '@tea/ui/Posts/Posts.svelte';
|
import Posts from '@tea/ui/Posts/Posts.svelte';
|
||||||
import PanelHeader from '@tea/ui/PanelHeader/PanelHeader.svelte';
|
import PanelHeader from '@tea/ui/PanelHeader/PanelHeader.svelte';
|
||||||
import Preloader from '@tea/ui/Preloader/Preloader.svelte';
|
import Preloader from '@tea/ui/Preloader/Preloader.svelte';
|
||||||
import { onMount } from 'svelte';
|
import { postsStore } from '$libs/stores';
|
||||||
|
|
||||||
let courses: AirtablePost[] = [];
|
let courses: AirtablePost[] = [];
|
||||||
|
|
||||||
onMount(async () => {
|
postsStore.subscribeByTag('course', (posts) => (courses = posts));
|
||||||
courses = await getAllPosts('course');
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<PanelHeader title="Essential Workshops" ctaLabel="View all" ctaLink="/" />
|
<PanelHeader title="Essential Workshops" ctaLabel="View all" ctaLink="/" />
|
||||||
|
|
|
@ -1,17 +1,21 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import '$appcss';
|
import '$appcss';
|
||||||
import { onMount } from 'svelte';
|
import { postsStore } from '$libs/stores';
|
||||||
import type { Course } from '$libs/types';
|
import type { Course } from '$libs/types';
|
||||||
|
|
||||||
import Gallery from '@tea/ui/Gallery/Gallery.svelte';
|
import Gallery from '@tea/ui/Gallery/Gallery.svelte';
|
||||||
import { getFeaturedCourses } from '@api';
|
|
||||||
|
|
||||||
let courses: Course[] = [];
|
let courses: Course[] = [];
|
||||||
|
|
||||||
onMount(async () => {
|
postsStore.subscribeByTag('featured_course', (posts) => {
|
||||||
if (!courses.length) {
|
courses = posts.map((post) => {
|
||||||
courses = await getFeaturedCourses();
|
return {
|
||||||
}
|
title: post.title,
|
||||||
|
sub_title: post.sub_title,
|
||||||
|
banner_image_url: post.thumb_image_url,
|
||||||
|
link: post.link
|
||||||
|
} as Course;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,14 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import '$appcss';
|
import '$appcss';
|
||||||
import { getAllPosts } from '@api';
|
import { postsStore } from '$libs/stores';
|
||||||
import type { AirtablePost } from '@tea/ui/types';
|
import type { AirtablePost } from '@tea/ui/types';
|
||||||
import Posts from '@tea/ui/Posts/Posts.svelte';
|
import Posts from '@tea/ui/Posts/Posts.svelte';
|
||||||
import PanelHeader from '@tea/ui/PanelHeader/PanelHeader.svelte';
|
import PanelHeader from '@tea/ui/PanelHeader/PanelHeader.svelte';
|
||||||
import Preloader from '@tea/ui/Preloader/Preloader.svelte';
|
import Preloader from '@tea/ui/Preloader/Preloader.svelte';
|
||||||
import { onMount } from 'svelte';
|
|
||||||
|
|
||||||
let news: AirtablePost[] = [];
|
let news: AirtablePost[] = [];
|
||||||
|
|
||||||
onMount(async () => {
|
postsStore.subscribeByTag('news', (posts) => (news = posts));
|
||||||
news = await getAllPosts('news');
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<PanelHeader title="Open-source News" ctaLabel="Read more articles >" ctaLink="/" />
|
<PanelHeader title="Open-source News" ctaLabel="Read more articles >" ctaLink="/" />
|
||||||
|
|
|
@ -113,6 +113,12 @@ function initPosts() {
|
||||||
const res = postsIndex.search(term, { limit });
|
const res = postsIndex.search(term, { limit });
|
||||||
const matchingPosts: AirtablePost[] = res.map((v) => v.item);
|
const matchingPosts: AirtablePost[] = res.map((v) => v.item);
|
||||||
return matchingPosts;
|
return matchingPosts;
|
||||||
|
},
|
||||||
|
subscribeByTag: (tag: string, cb: (posts: AirtablePost[]) => void) => {
|
||||||
|
subscribe((newPosts: AirtablePost[]) => {
|
||||||
|
const filteredPosts = newPosts.filter((post) => post.tags.includes(tag));
|
||||||
|
cb(filteredPosts);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue