-
Notifications
You must be signed in to change notification settings - Fork 28
/
Suggestions.svelte
143 lines (129 loc) · 4.3 KB
/
Suggestions.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<script lang="ts">
import { ClickableTile, Tile, Tag } from 'carbon-components-svelte';
import CaretRight from 'carbon-icons-svelte/lib/CaretRight.svelte';
import BookmarkAdd from 'carbon-icons-svelte/lib/BookmarkAdd.svelte';
import { EventWatcher } from '../stores/Events';
import {
selectedPlugin,
selectedMedia,
selectedItem,
contentscreen,
} from '../stores/Stores';
import type { Bookmark } from '../../../engine/providers/Bookmark';
import MediaIcon from '../../../img/media.webp';
import { Key as GlobalKey } from '../../../engine/SettingsGlobal';
import type { Check } from '../../../engine/SettingsManager';
import type {
MediaContainer,
MediaItem,
} from '../../../engine/providers/MediaPlugin';
const setting = HakuNeko.SettingsManager.OpenScope().Get<Check>(GlobalKey.CheckNewContent);
let checkNewContent = setting.Value;
setting.Subscribe(value => {
if(value) refreshSuggestions();
checkNewContent = value;
});
let suggestions: Bookmark[] = [];
let isRefreshing = false;
async function refreshSuggestions() {
if (isRefreshing) return;
isRefreshing = true;
await new Promise((resolve) => setTimeout(resolve, 1000));
suggestions =
await HakuNeko.BookmarkPlugin.GetEntriesWithUnflaggedContent();
isRefreshing = false;
}
refreshSuggestions();
// on bookmark change
EventWatcher(
HakuNeko.BookmarkPlugin.Entries,
HakuNeko.BookmarkPlugin.EntriesUpdated,
).subscribe(() => refreshSuggestions());
// on marks change
EventWatcher(null, HakuNeko.ItemflagManager.MediaFlagsChanged).subscribe(
() => refreshSuggestions(),
);
async function selectBookmark(bookmark: Bookmark) {
let unFlaggedContent = await bookmark.GetUnflaggedContent();
$selectedPlugin = HakuNeko.BookmarkPlugin;
$selectedMedia = bookmark;
$selectedItem = unFlaggedContent[
unFlaggedContent.length - 1
] as MediaContainer<MediaItem>;
}
</script>
{#if checkNewContent}
<Tile id="Suggestions" class="border">
<ClickableTile
id="Continue"
on:click={() => ($contentscreen = '/bookmarks')}
>
<h4 style="text-align:center;">
Continue
<BookmarkAdd size={24} />
</h4>
</ClickableTile>
{#each suggestions as bookmark (bookmark)}
<ClickableTile
class="suggesttile"
light
on:click={() => selectBookmark(bookmark)}
>
<div
class="mediaitem"
style="background-image: url({bookmark.Icon ?? MediaIcon});"
>
<Tag class="suggesttitle" type="outline" interactive>
<span title={bookmark.Title}>{bookmark.Title}</span>
</Tag>
{#await bookmark.GetUnflaggedContent() then value}
<Tag
class="suggestcount"
type="outline"
icon={CaretRight}
interactive
>
{value.length}
</Tag>
{/await}
</div>
</ClickableTile>
{/each}
</Tile>
{/if}
<style>
:global(#Suggestions) {
display: grid;
grid-template-columns: repeat(auto-fit, 10em);
grid-gap: 0.5em;
overflow-y: hidden;
max-height: 18em;
}
:global(#Suggestions .suggesttile) {
height: 8em;
padding: 0;
}
:global(#Suggestions .suggesttile .bx--tag span) {
width: 100%;
overflow: hidden;
text-overflow: ellipsis;
}
:global(#Suggestions .suggesttitle) {
width: 95%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
:global(#Suggestions .suggestcount) {
position: absolute;
bottom: 0;
right: 0.2em;
}
.mediaitem {
height: 100%;
position: relative;
background-position: center;
background-size: contain;
background-repeat: no-repeat;
}
</style>