feat: add retry option
This commit is contained in:
1 parent
ef74a4e6d2
commit
25b1ab8d8e
6 files changed
+84
-36
No files matched your search
@@ -1,6 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation'
|
||||
import { page } from '$app/stores'
|
||||
import { t } from '$lib/translations'
|
||||
import { Button } from 'mono-svelte'
|
||||
import { Icon, XMark } from 'svelte-hero-icons'
|
||||
</script>
|
||||
@@ -18,6 +19,6 @@
|
||||
{$page.error?.message}
|
||||
</code>
|
||||
<Button size="sm" class="w-max" on:click={() => goto($page.url)}>
|
||||
Retry
|
||||
{$t('message.retry')}
|
||||
</Button>
|
||||
</div>
|
||||
+56
-14
@@ -12,13 +12,20 @@
|
||||
import ViewSelect from '$lib/components/lemmy/dropdowns/ViewSelect.svelte'
|
||||
import { searchParam } from '$lib/util.js'
|
||||
import PostFeed from '$lib/components/lemmy/post/PostFeed.svelte'
|
||||
import { ChartBar, GlobeAmericas, Icon, ServerStack } from 'svelte-hero-icons'
|
||||
import {
|
||||
ChartBar,
|
||||
ExclamationCircle,
|
||||
ExclamationTriangle,
|
||||
GlobeAmericas,
|
||||
Icon,
|
||||
ServerStack,
|
||||
} from 'svelte-hero-icons'
|
||||
import { getClient, site } from '$lib/lemmy.js'
|
||||
import Location from '$lib/components/lemmy/dropdowns/Location.svelte'
|
||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||
import { t } from '$lib/translations.js'
|
||||
import InfiniteScroll from 'svelte-infinite-scroll'
|
||||
import { Spinner } from 'mono-svelte'
|
||||
import { Button, Material, Spinner } from 'mono-svelte'
|
||||
import { writable } from 'svelte/store'
|
||||
import type { GetPostsResponse } from 'lemmy-js-client'
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
@@ -27,24 +34,40 @@
|
||||
|
||||
const limit = 20
|
||||
let hasMore = data.posts.posts.length != 0
|
||||
let error: any = undefined
|
||||
let loading = false
|
||||
|
||||
async function loadMore() {
|
||||
if (!hasMore) return
|
||||
|
||||
const newPosts = await getClient().getPosts({
|
||||
limit: limit,
|
||||
page: data.page,
|
||||
sort: data.sort,
|
||||
type_: data.listingType,
|
||||
page_cursor: data.cursor.next,
|
||||
})
|
||||
try {
|
||||
loading = true
|
||||
const newPosts = await getClient()
|
||||
.getPosts({
|
||||
limit: limit,
|
||||
page: data.page,
|
||||
sort: data.sort,
|
||||
type_: data.listingType,
|
||||
page_cursor: data.cursor.next,
|
||||
})
|
||||
.catch((e) => {
|
||||
throw new Error(e)
|
||||
})
|
||||
|
||||
hasMore = newPosts.posts.length != 0
|
||||
error = null
|
||||
|
||||
data.cursor.next = newPosts.next_page
|
||||
data.posts.posts = [...data.posts.posts, ...newPosts.posts]
|
||||
hasMore = newPosts.posts.length != 0
|
||||
|
||||
_posts.update((ps) => ({ data: data.posts, params: ps.params }))
|
||||
data.cursor.next = newPosts.next_page
|
||||
data.posts.posts = [...data.posts.posts, ...newPosts.posts]
|
||||
|
||||
_posts.update((ps) => ({ data: data.posts, params: ps.params }))
|
||||
|
||||
loading = false
|
||||
} catch (e) {
|
||||
error = e
|
||||
loading = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -62,7 +85,26 @@
|
||||
|
||||
<PostFeed posts={data.posts.posts}>
|
||||
{#if $userSettings.infiniteScroll}
|
||||
{#if hasMore}
|
||||
{#if error}
|
||||
<div
|
||||
class="flex flex-col justify-center items-center
|
||||
rounded-xl gap-2 py-8 mt-6
|
||||
border !border-b !border-red-500 bg-red-500/5"
|
||||
>
|
||||
<div class="bg-red-500/30 rounded-full p-3 text-red-500">
|
||||
<Icon src={ExclamationTriangle} size="24" solid></Icon>
|
||||
</div>
|
||||
<pre class="py-0.5">{error}</pre>
|
||||
<Button
|
||||
color="primary"
|
||||
{loading}
|
||||
disabled={loading}
|
||||
on:click={loadMore}
|
||||
>
|
||||
{$t('message.retry')}
|
||||
</Button>
|
||||
</div>
|
||||
{:else if hasMore}
|
||||
<div class="w-full flex flex-col skeleton gap-2 animate-pulse pt-6">
|
||||
<div class="w-96 h-8"></div>
|
||||
<div class="w-full h-48"></div>
|
||||
|
||||
@@ -20,9 +20,6 @@ export async function load({ url, fetch }) {
|
||||
|
||||
const cached = get(_posts)
|
||||
|
||||
console.log(url.searchParams.toString())
|
||||
console.log(cached?.params?.toString())
|
||||
|
||||
const posts =
|
||||
cached && url.searchParams.toString() == cached.params.toString()
|
||||
? cached.data
|
||||
|
||||
@@ -215,6 +215,7 @@
|
||||
</div>
|
||||
</Setting>
|
||||
<ToggleSetting
|
||||
beta
|
||||
bind:checked={$userSettings.infiniteScroll}
|
||||
title={$t('settings.app.infiniteScroll.title')}
|
||||
description={$t('settings.app.infiniteScroll.description')}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
export let title: string
|
||||
export let description: string | undefined = undefined
|
||||
export let checked: boolean = false
|
||||
export let beta = false
|
||||
|
||||
export let supportedPlatforms = {
|
||||
desktop: true,
|
||||
@@ -20,25 +21,30 @@
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col w-full justify-between gap-2 max-w-full">
|
||||
{#if Object.values(supportedPlatforms).some((v) => v == false)}
|
||||
{#if Object.values(supportedPlatforms).some((v) => v == false) || beta}
|
||||
<div class="flex items-center gap-2 flex-wrap">
|
||||
{#if supportedPlatforms.desktop}
|
||||
<Badge>
|
||||
<Icon src={ComputerDesktop} micro size="14" slot="icon" />
|
||||
{$t('settings.desktop')}
|
||||
</Badge>
|
||||
{#if beta}
|
||||
<Badge>Beta</Badge>
|
||||
{/if}
|
||||
{#if supportedPlatforms.tablet}
|
||||
<Badge>
|
||||
<Icon src={DeviceTablet} micro size="14" slot="icon" />
|
||||
{$t('settings.tablet')}
|
||||
</Badge>
|
||||
{/if}
|
||||
{#if supportedPlatforms.mobile}
|
||||
<Badge>
|
||||
<Icon src={DevicePhoneMobile} micro size="14" slot="icon" />
|
||||
{$t('settings.mobile')}
|
||||
</Badge>
|
||||
{#if Object.values(supportedPlatforms).some((v) => v == false)}
|
||||
{#if supportedPlatforms.desktop}
|
||||
<Badge>
|
||||
<Icon src={ComputerDesktop} micro size="14" slot="icon" />
|
||||
{$t('settings.desktop')}
|
||||
</Badge>
|
||||
{/if}
|
||||
{#if supportedPlatforms.tablet}
|
||||
<Badge>
|
||||
<Icon src={DeviceTablet} micro size="14" slot="icon" />
|
||||
{$t('settings.tablet')}
|
||||
</Badge>
|
||||
{/if}
|
||||
{#if supportedPlatforms.mobile}
|
||||
<Badge>
|
||||
<Icon src={DevicePhoneMobile} micro size="14" slot="icon" />
|
||||
{$t('settings.mobile')}
|
||||
</Badge>
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
Reference in new issue
Block a user