mirror of
https://github.com/ivabus/gui
synced 2025-06-07 15:50:27 +03:00
Merge pull request #71 from teaxyz/render-airtable-posts
#70 #67 use airtable data by GET /posts?tag=news/course/featured_course
This commit is contained in:
commit
91d761b050
4 changed files with 37 additions and 21 deletions
|
@ -1,9 +1,10 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import '$appcss';
|
import '$appcss';
|
||||||
import { getAllPosts } from '$libs/api/mock';
|
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 { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
|
|
||||||
let courses: AirtablePost[] = [];
|
let courses: AirtablePost[] = [];
|
||||||
|
@ -14,4 +15,10 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<PanelHeader title="Essential Workshops" ctaLabel="View all" ctaLink="/" />
|
<PanelHeader title="Essential Workshops" ctaLabel="View all" ctaLink="/" />
|
||||||
<Posts posts={courses} />
|
{#if courses.length}
|
||||||
|
<Posts posts={courses} />
|
||||||
|
{:else}
|
||||||
|
<section class="h-64 border border-gray p-4">
|
||||||
|
<Preloader />
|
||||||
|
</section>
|
||||||
|
{/if}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import '$appcss';
|
import '$appcss';
|
||||||
import { getAllPosts } from '$libs/api/mock';
|
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 { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
|
|
||||||
let news: AirtablePost[] = [];
|
let news: AirtablePost[] = [];
|
||||||
|
@ -14,4 +15,10 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<PanelHeader title="Open-source News" ctaLabel="Read more articles >" ctaLink="/" />
|
<PanelHeader title="Open-source News" ctaLabel="Read more articles >" ctaLink="/" />
|
||||||
<Posts posts={news} />
|
{#if news.length}
|
||||||
|
<Posts posts={news} />
|
||||||
|
{:else}
|
||||||
|
<section class="h-64 border border-gray p-4">
|
||||||
|
<Preloader />
|
||||||
|
</section>
|
||||||
|
{/if}
|
||||||
|
|
|
@ -14,26 +14,21 @@ import { getClient } from '@tauri-apps/api/http';
|
||||||
// import { invoke } from '@tauri-apps/api';
|
// import { invoke } from '@tauri-apps/api';
|
||||||
import { Command } from '@tauri-apps/api/shell';
|
import { Command } from '@tauri-apps/api/shell';
|
||||||
import { readDir, BaseDirectory } from '@tauri-apps/api/fs';
|
import { readDir, BaseDirectory } from '@tauri-apps/api/fs';
|
||||||
import { Buffer } from 'buffer';
|
import type { Package, Review, AirtablePost } from '@tea/ui/types';
|
||||||
import type { Package, Review } from '@tea/ui/types';
|
|
||||||
import type { GUIPackage, Course } from '../types';
|
import type { GUIPackage, Course } from '../types';
|
||||||
import * as mock from './mock';
|
import * as mock from './mock';
|
||||||
import { PackageStates } from '../types';
|
import { PackageStates } from '../types';
|
||||||
import { AirtablePost } from '../../../../ui/src/types';
|
|
||||||
|
|
||||||
const username = 'user';
|
|
||||||
const password = 'password';
|
|
||||||
const auth = 'Basic ' + Buffer.from(username + ':' + password).toString('base64');
|
|
||||||
|
|
||||||
const base = 'https://api.tea.xyz/v1';
|
const base = 'https://api.tea.xyz/v1';
|
||||||
|
|
||||||
async function get<T>(path: string) {
|
async function get<T>(path: string, query?: { [key: string]: any }) {
|
||||||
const client = await getClient();
|
const client = await getClient();
|
||||||
const uri = join(base, path);
|
const uri = join(base, path);
|
||||||
const { data } = await client.get<T>(uri.toString(), {
|
const { data } = await client.get<T>(uri.toString(), {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: auth
|
Authorization: 'public' // TODO: figure out why req w/o Authorization does not work
|
||||||
}
|
},
|
||||||
|
query: query || {}
|
||||||
});
|
});
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
@ -140,8 +135,15 @@ async function getInstalledPackages() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getFeaturedCourses(): Promise<Course[]> {
|
export async function getFeaturedCourses(): Promise<Course[]> {
|
||||||
const courses = await mock.getFeaturedCourses();
|
const posts = await get<AirtablePost[]>('posts', { tag: 'featured_course' });
|
||||||
return courses;
|
return posts.map((post) => {
|
||||||
|
return {
|
||||||
|
title: post.title,
|
||||||
|
sub_title: post.sub_title,
|
||||||
|
banner_image_url: post.thumb_image_url,
|
||||||
|
link: post.link
|
||||||
|
} as Course;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getTopPackages(): Promise<GUIPackage[]> {
|
export async function getTopPackages(): Promise<GUIPackage[]> {
|
||||||
|
@ -149,8 +151,8 @@ export async function getTopPackages(): Promise<GUIPackage[]> {
|
||||||
return packages;
|
return packages;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getAllPosts(type: string): Promise<AirtablePost[]> {
|
export async function getAllPosts(tag: string): Promise<AirtablePost[]> {
|
||||||
// add filter here someday: type = news | course
|
// add filter here someday: tag = news | course
|
||||||
const posts = await mock.getAllPosts(type);
|
const posts = await get<AirtablePost[]>('posts', { tag });
|
||||||
return posts;
|
return posts;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,9 +12,9 @@
|
||||||
<figure class="w-1/3">
|
<figure class="w-1/3">
|
||||||
<img src={article.thumb_image_url} alt={article.title} />
|
<img src={article.thumb_image_url} alt={article.title} />
|
||||||
</figure>
|
</figure>
|
||||||
<section class="p-4 font-sono">
|
<section class="w-2/3 p-4 font-sono">
|
||||||
<h1 class="text-xl text-primary">{article.title}</h1>
|
<h1 class="text-xl text-primary">{article.title}</h1>
|
||||||
<p class="my-4 text-sm">{article.short_description}</p>
|
<p class="my-4 text-sm line-clamp-4">{article.short_description}</p>
|
||||||
<a href={article.link} class="text-sm text-primary underline">Read more ...</a>
|
<a href={article.link} class="text-sm text-primary underline">Read more ...</a>
|
||||||
</section>
|
</section>
|
||||||
</article>
|
</article>
|
||||||
|
|
Loading…
Reference in a new issue