|
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)) return; |
| 25 | + if (!CacheHelper.isExpired("userFeedCachedTime", CACHE_USER_FEED)) |
| 26 | + return; |
26 | 27 |
|
27 | 28 | const myFeed = await PenguinModClient.users.getMyFeed(); |
28 | 29 | CacheHelper.update({ |
29 | 30 | userFeedCachedData: myFeed, |
30 | 31 | }); |
31 | 32 | }; |
32 | 33 | onMount(async () => { |
33 | | - if (!($StoreSettings.loggedIn)) return; |
| 34 | + if (!$StoreSettings.loggedIn) return; |
34 | 35 | if (loading) return; // TODO: remove these loading false then true then false things |
35 | 36 | loading = true; |
36 | | - |
| 37 | +
|
37 | 38 | try { |
38 | 39 | await loadingAttempt(); |
39 | 40 | } catch (err) { |
|
49 | 50 | switch (type) { |
50 | 51 | // TODO: At some point we should stop including removed projects in the feed. |
51 | 52 | case "follow": |
52 | | - return TranslationMapper.mapCurrent("feed.following", "$1 followed you") |
53 | | - .replaceAll("$1", author); |
| 53 | + return TranslationMapper.mapCurrent( |
| 54 | + "feed.following", |
| 55 | + "$1 followed you", |
| 56 | + ).replaceAll("$1", author); |
54 | 57 | case "upload": |
55 | | - return TranslationMapper.mapCurrent("feed.uploaded", "$1 uploaded $2") |
| 58 | + return TranslationMapper.mapCurrent( |
| 59 | + "feed.uploaded", |
| 60 | + "$1 uploaded $2", |
| 61 | + ) |
56 | 62 | .replaceAll("$1", author) |
57 | | - .replaceAll("$2", content.name || TranslationMapper.mapCurrent("project.status.removed", "(removed)")); |
| 63 | + .replaceAll( |
| 64 | + "$2", |
| 65 | + content.name || |
| 66 | + TranslationMapper.mapCurrent( |
| 67 | + "project.status.removed", |
| 68 | + "(removed)", |
| 69 | + ), |
| 70 | + ); |
58 | 71 | case "remix": |
59 | | - return TranslationMapper.mapCurrent("feed.remixed", "$1 remixed $2") |
| 72 | + return TranslationMapper.mapCurrent( |
| 73 | + "feed.remixed", |
| 74 | + "$1 remixed $2", |
| 75 | + ) |
60 | 76 | .replaceAll("$1", author) |
61 | | - .replaceAll("$2", content.name || TranslationMapper.mapCurrent("project.status.removed", "(removed)")); |
| 77 | + .replaceAll( |
| 78 | + "$2", |
| 79 | + content.name || |
| 80 | + TranslationMapper.mapCurrent( |
| 81 | + "project.status.removed", |
| 82 | + "(removed)", |
| 83 | + ), |
| 84 | + ); |
62 | 85 | case "posted": |
63 | | - return TranslationMapper.mapCurrent("feed.posted", "$1 made a post") |
64 | | - .replaceAll("$1", author); |
| 86 | + return TranslationMapper.mapCurrent( |
| 87 | + "feed.posted", |
| 88 | + "$1 made a post", |
| 89 | + ).replaceAll("$1", author); |
65 | 90 | } |
66 | 91 | }; |
67 | 92 | const getFeedUrl = (type, author, content) => { |
|
82 | 107 | <Category {...props}> |
83 | 108 | <!-- My Feed Category --> |
84 | 109 | {#snippet header()} |
85 | | - <LocalizedString |
86 | | - text="My Feed" |
87 | | - key="home.sections.feed" |
88 | | - /> |
| 110 | + <LocalizedString text="My Feed" key="home.sections.feed" /> |
89 | 111 | {/snippet} |
90 | | - {#if !($StoreSettings.loggedIn)} |
| 112 | + {#if !$StoreSettings.loggedIn} |
91 | 113 | <!-- NOTE: This state should never render, but we'll handle it nicely anyways --> |
92 | 114 | <div class="category-textdisplay"> |
93 | 115 | <p> |
|
119 | 141 | {:else} |
120 | 142 | <div class="category-feed"> |
121 | 143 | {#each $StoreSession.userFeedCachedData as feedItem} |
122 | | - <!-- TODO: use the right avatar URL (probably add getPfpUrl to api module) --> |
123 | 144 | <!-- TODO: User display should allow 3 hrefs for the user pfp & bottom text (though we only need the image url to go elsewhere here) --> |
124 | 145 | <UserDisplay |
125 | | - src="https://projects.penguinmod.com/api/v1/users/getpfp?username=jeremygamer13" |
126 | | - href={getFeedUrl(feedItem.type, feedItem.username, feedItem.data)} |
| 146 | + src={PenguinModClient.users.getPfpUrl( |
| 147 | + feedItem.username, |
| 148 | + )} |
| 149 | + href={getFeedUrl( |
| 150 | + feedItem.type, |
| 151 | + feedItem.username, |
| 152 | + feedItem.data, |
| 153 | + )} |
127 | 154 | kind="detail" |
128 | 155 | > |
129 | 156 | {#snippet textTop()} |
130 | | - {getFeedText(feedItem.type, feedItem.username, feedItem.data)} |
| 157 | + {getFeedText( |
| 158 | + feedItem.type, |
| 159 | + feedItem.username, |
| 160 | + feedItem.data, |
| 161 | + )} |
131 | 162 | {/snippet} |
132 | 163 | {#snippet textBottom()} |
133 | | - {Locale.timestampToDateWithTime(Number(new Date(feedItem.date)))} |
| 164 | + {Locale.timestampToDateWithTime( |
| 165 | + Number(new Date(feedItem.date)), |
| 166 | + )} |
134 | 167 | {/snippet} |
135 | 168 | </UserDisplay> |
136 | 169 | {:else} |
|
174 | 207 | overflow: hidden; |
175 | 208 | overflow-y: auto; |
176 | 209 | } |
177 | | - .category-feed :global(div[data-penguinmodsvelteui-userdisplay=true]) { |
| 210 | + .category-feed :global(div[data-penguinmodsvelteui-userdisplay="true"]) { |
178 | 211 | margin-bottom: 4px; |
179 | 212 | } |
180 | | - .category-feed :global(div[data-penguinmodsvelteui-userdisplay=true]:last-child) { |
| 213 | + .category-feed |
| 214 | + :global(div[data-penguinmodsvelteui-userdisplay="true"]:last-child) { |
181 | 215 | margin-bottom: 0; |
182 | 216 | } |
183 | 217 | </style> |
0 commit comments