|
6 | 6 | import { Category, UserDisplay } from "PenguinMod-SvelteUI"; |
7 | 7 | import Icon from "$lib/components/Icon/Component.svelte"; |
8 | 8 | import LocalizedString from "$lib/components/Localization/LocalizedString.svelte"; |
9 | | -
|
| 9 | + |
10 | 10 | import { CACHE_USER_FEED } from "$lib/resources/cache/cache-time"; |
11 | 11 | import CacheHelper from "$lib/resources/cache/cache-helper"; |
12 | 12 |
|
13 | 13 | import TranslationMapper from "$lib/resources/localization/translation/mapper"; |
14 | 14 | import PenguinModClient from "$lib/resources/penguinmod/client.js"; |
15 | 15 | import Locale from "$lib/resources/localization/locale"; |
16 | | -
|
| 16 | + |
17 | 17 | import StoreSettings from "$lib/stores/settings"; |
18 | 18 | import StoreSession from "$lib/stores/session"; |
19 | | -
|
| 19 | + |
20 | 20 | let props = $props(); |
21 | 21 | let loading = $state(false); |
22 | 22 | let failed = $state(false); |
23 | 23 | const loadingAttempt = async () => { |
24 | 24 | // NOTE: We only actually ask the API if our own cache is expired (or doesnt exist, which is also counted as expired) |
25 | | - if (!CacheHelper.isExpired("userFeedCachedTime", CACHE_USER_FEED)) |
26 | | - return; |
| 25 | + if (!CacheHelper.isExpired("userFeedCachedTime", CACHE_USER_FEED)) return; |
27 | 26 |
|
28 | 27 | const myFeed = await PenguinModClient.users.getMyFeed(); |
29 | 28 | CacheHelper.update({ |
30 | 29 | userFeedCachedData: myFeed, |
31 | 30 | }); |
32 | 31 | }; |
33 | 32 | onMount(async () => { |
34 | | - if (!$StoreSettings.loggedIn) return; |
| 33 | + if (!($StoreSettings.loggedIn)) return; |
35 | 34 | if (loading) return; // TODO: remove these loading false then true then false things |
36 | 35 | loading = true; |
37 | | -
|
| 36 | + |
38 | 37 | try { |
39 | 38 | await loadingAttempt(); |
40 | 39 | } catch (err) { |
|
50 | 49 | switch (type) { |
51 | 50 | // TODO: At some point we should stop including removed projects in the feed. |
52 | 51 | case "follow": |
53 | | - return TranslationMapper.mapCurrent( |
54 | | - "feed.following", |
55 | | - "$1 followed you", |
56 | | - ).replaceAll("$1", author); |
| 52 | + return TranslationMapper.mapCurrent("feed.following", "$1 followed you") |
| 53 | + .replaceAll("$1", author); |
57 | 54 | case "upload": |
58 | | - return TranslationMapper.mapCurrent( |
59 | | - "feed.uploaded", |
60 | | - "$1 uploaded $2", |
61 | | - ) |
| 55 | + return TranslationMapper.mapCurrent("feed.uploaded", "$1 uploaded $2") |
62 | 56 | .replaceAll("$1", author) |
63 | | - .replaceAll( |
64 | | - "$2", |
65 | | - content.name || |
66 | | - TranslationMapper.mapCurrent( |
67 | | - "project.status.removed", |
68 | | - "(removed)", |
69 | | - ), |
70 | | - ); |
| 57 | + .replaceAll("$2", content.name || TranslationMapper.mapCurrent("project.status.removed", "(removed)")); |
71 | 58 | case "remix": |
72 | | - return TranslationMapper.mapCurrent( |
73 | | - "feed.remixed", |
74 | | - "$1 remixed $2", |
75 | | - ) |
| 59 | + return TranslationMapper.mapCurrent("feed.remixed", "$1 remixed $2") |
76 | 60 | .replaceAll("$1", author) |
77 | | - .replaceAll( |
78 | | - "$2", |
79 | | - content.name || |
80 | | - TranslationMapper.mapCurrent( |
81 | | - "project.status.removed", |
82 | | - "(removed)", |
83 | | - ), |
84 | | - ); |
| 61 | + .replaceAll("$2", content.name || TranslationMapper.mapCurrent("project.status.removed", "(removed)")); |
85 | 62 | case "posted": |
86 | | - return TranslationMapper.mapCurrent( |
87 | | - "feed.posted", |
88 | | - "$1 made a post", |
89 | | - ).replaceAll("$1", author); |
| 63 | + return TranslationMapper.mapCurrent("feed.posted", "$1 made a post") |
| 64 | + .replaceAll("$1", author); |
90 | 65 | } |
91 | 66 | }; |
92 | 67 | const getFeedUrl = (type, author, content) => { |
|
107 | 82 | <Category {...props}> |
108 | 83 | <!-- My Feed Category --> |
109 | 84 | {#snippet header()} |
110 | | - <LocalizedString text="My Feed" key="home.sections.feed" /> |
| 85 | + <LocalizedString |
| 86 | + text="My Feed" |
| 87 | + key="home.sections.feed" |
| 88 | + /> |
111 | 89 | {/snippet} |
112 | | - {#if !$StoreSettings.loggedIn} |
| 90 | + {#if !($StoreSettings.loggedIn)} |
113 | 91 | <!-- NOTE: This state should never render, but we'll handle it nicely anyways --> |
114 | 92 | <div class="category-textdisplay"> |
115 | 93 | <p> |
|
143 | 121 | {#each $StoreSession.userFeedCachedData as feedItem} |
144 | 122 | <!-- TODO: User display should allow 3 hrefs for the user pfp & bottom text (though we only need the image url to go elsewhere here) --> |
145 | 123 | <UserDisplay |
146 | | - src={PenguinModClient.users.getPfpUrl( |
147 | | - feedItem.username, |
148 | | - )} |
149 | | - href={getFeedUrl( |
150 | | - feedItem.type, |
151 | | - feedItem.username, |
152 | | - feedItem.data, |
153 | | - )} |
| 124 | + src={PenguinModClient.users.getPfpUrl(feedItem.username)} |
| 125 | + href={getFeedUrl(feedItem.type, feedItem.username, feedItem.data)} |
154 | 126 | kind="detail" |
155 | 127 | > |
156 | 128 | {#snippet textTop()} |
157 | | - {getFeedText( |
158 | | - feedItem.type, |
159 | | - feedItem.username, |
160 | | - feedItem.data, |
161 | | - )} |
| 129 | + {getFeedText(feedItem.type, feedItem.username, feedItem.data)} |
162 | 130 | {/snippet} |
163 | 131 | {#snippet textBottom()} |
164 | | - {Locale.timestampToDateWithTime( |
165 | | - Number(new Date(feedItem.date)), |
166 | | - )} |
| 132 | + {Locale.timestampToDateWithTime(Number(new Date(feedItem.date)))} |
167 | 133 | {/snippet} |
168 | 134 | </UserDisplay> |
169 | 135 | {:else} |
|
207 | 173 | overflow: hidden; |
208 | 174 | overflow-y: auto; |
209 | 175 | } |
210 | | - .category-feed :global(div[data-penguinmodsvelteui-userdisplay="true"]) { |
| 176 | + .category-feed :global(div[data-penguinmodsvelteui-userdisplay=true]) { |
211 | 177 | margin-bottom: 4px; |
212 | 178 | } |
213 | | - .category-feed |
214 | | - :global(div[data-penguinmodsvelteui-userdisplay="true"]:last-child) { |
| 179 | + .category-feed :global(div[data-penguinmodsvelteui-userdisplay=true]:last-child) { |
215 | 180 | margin-bottom: 0; |
216 | 181 | } |
217 | 182 | </style> |
0 commit comments