forked from hplush/slowreader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scene.svelte
104 lines (91 loc) · 2.22 KB
/
scene.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<script lang="ts">
import {
addCategory,
addFeed,
Category,
type CategoryValue,
clearPreview,
client,
DEFAULT_REFRESH_STATISTICS,
fastCategories,
Feed,
type FeedValue,
Filter,
hasFeeds,
isRefreshing,
type NetworkTypeDetector,
Post,
refreshStatistics,
type RefreshStatistics,
type Route,
testFeed
} from '@slowreader/core'
import { cleanStores } from 'nanostores'
import { onMount } from 'svelte'
import {
baseRouter,
type PreparedResponse,
prepareResponses,
setNetworkType
} from './environment.js'
const DEFAULT_NETWORK: ReturnType<NetworkTypeDetector> = {
saveData: false,
type: 'free'
}
export let refreshing: false | Partial<RefreshStatistics> = false
export let route: Route = {
params: {},
route: 'slow'
}
export let fast = false
export let networkType = DEFAULT_NETWORK
export let categories: CategoryValue[] = []
export let feeds: Partial<FeedValue>[] = [{ title: 'Example' }]
export let responses: Record<string, PreparedResponse | string> = {}
function cleanLogux(): void {
clearPreview()
client.get()?.clean()
cleanStores(Feed, Filter, Category, Post, hasFeeds, fastCategories)
}
$: {
cleanLogux()
prepareResponses(responses)
setNetworkType(networkType)
for (let category of categories) {
addCategory(category)
}
for (let feed of feeds) {
addFeed(testFeed(feed))
}
// TODO: Replace with Nano Stores Context
if (refreshing) {
// @ts-expect-error
isRefreshing.set(true)
// @ts-expect-error
refreshStatistics.set({ ...DEFAULT_REFRESH_STATISTICS, ...refreshing })
} else {
// @ts-expect-error
isRefreshing.set(false)
// @ts-expect-error
refreshStatistics.set({ ...DEFAULT_REFRESH_STATISTICS })
}
if (fast) {
baseRouter.set({
params: { category: 'general' },
route: 'fast'
})
} else {
baseRouter.set(route)
}
}
onMount(() => {
return () => {
// @ts-expect-error
isRefreshing.set(false)
baseRouter.set({ params: {}, route: 'slow' })
setNetworkType(DEFAULT_NETWORK)
cleanLogux()
}
})
</script>
<slot />