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