|
14 | 14 | import { format as dateFormat, formatDistanceToNowStrict } from "date-fns"; |
15 | 15 | import { format as numberFormat } from "numerable"; |
16 | 16 |
|
17 | | - const profile = $derived(getProfileContext()); |
18 | | - const profileUUID = $derived(profile.uuid); |
19 | | - const profileId = $derived(profile.profile_id); |
| 17 | + const profile = $derived(getProfileContext().current); |
| 18 | + const profileUUID = $derived(profile?.uuid); |
| 19 | + const profileId = $derived(profile?.profile_id); |
20 | 20 |
|
21 | 21 | const defaultPatternDecimal: string = "0,0.##"; |
22 | 22 | const defaultPattern: string = "0,0"; |
|
27 | 27 | </script> |
28 | 28 |
|
29 | 29 | <div class="additional-stats flex flex-col gap-2 @md:flex-row @md:flex-wrap"> |
30 | | - {#if profile.joined != null} |
31 | | - <AdditionStat text="Joined" data={formatDistanceToNowStrict(profile.joined, { addSuffix: true, in: tz(Intl.DateTimeFormat().resolvedOptions().timeZone) })} asterisk={true}> |
32 | | - Joined on {dateFormat(profile.joined, "dd MMMM yyyy 'at' HH:mm", { in: tz(Intl.DateTimeFormat().resolvedOptions().timeZone) })} |
33 | | - </AdditionStat> |
34 | | - {/if} |
35 | | - {#if profile.purse != null} |
36 | | - <AdditionStat text="Purse" data={`${formatNumber(profile.purse)} Coins`} /> |
37 | | - {/if} |
38 | | - {#if profile.bank != null && profile.personalBank != null} |
39 | | - <AdditionStat text="Bank Account" data={`${formatNumber(profile.bank + profile.personalBank)} Coins`} asterisk={profile.bank && profile.personalBank ? true : false}> |
40 | | - <div> |
41 | | - <h3 class="font-bold text-text/85"> |
42 | | - Bank: |
43 | | - <span class="text-text"> |
44 | | - {formatNumber(profile.bank)} |
45 | | - </span> |
46 | | - </h3> |
47 | | - {#if profile.personalBank} |
48 | | - <h3 class="font-bold text-text/85"> |
49 | | - Personal Bank: |
50 | | - <span class="text-text"> |
51 | | - {formatNumber(profile.personalBank)} |
52 | | - </span> |
53 | | - </h3> |
54 | | - {/if} |
55 | | - </div> |
56 | | - </AdditionStat> |
57 | | - {/if} |
58 | | - {#if profile.skills?.averageSkillLevel} |
59 | | - <AdditionStat text="Average Skill Level" data={profile.skills.averageSkillLevel.toFixed(2)} asterisk={true}> |
60 | | - <div class="max-w-xs space-y-2"> |
| 30 | + {#if profile != null} |
| 31 | + {#if profile.joined != null} |
| 32 | + <AdditionStat text="Joined" data={formatDistanceToNowStrict(profile.joined, { addSuffix: true, in: tz(Intl.DateTimeFormat().resolvedOptions().timeZone) })} asterisk={true}> |
| 33 | + Joined on {dateFormat(profile.joined, "dd MMMM yyyy 'at' HH:mm", { in: tz(Intl.DateTimeFormat().resolvedOptions().timeZone) })} |
| 34 | + </AdditionStat> |
| 35 | + {/if} |
| 36 | + {#if profile.purse != null} |
| 37 | + <AdditionStat text="Purse" data={`${formatNumber(profile.purse)} Coins`} /> |
| 38 | + {/if} |
| 39 | + {#if profile.bank != null && profile.personalBank != null} |
| 40 | + <AdditionStat text="Bank Account" data={`${formatNumber(profile.bank + profile.personalBank)} Coins`} asterisk={profile.bank && profile.personalBank ? true : false}> |
61 | 41 | <div> |
62 | 42 | <h3 class="font-bold text-text/85"> |
63 | | - Total Skill XP: |
| 43 | + Bank: |
64 | 44 | <span class="text-text"> |
65 | | - {numberFormat(profile.skills.totalSkillXp, defaultPattern)} |
| 45 | + {formatNumber(profile.bank)} |
66 | 46 | </span> |
67 | 47 | </h3> |
68 | | - <p class="font-medium text-text/80">Total XP gained in all skills except Social and Runecrafting.</p> |
| 48 | + {#if profile.personalBank} |
| 49 | + <h3 class="font-bold text-text/85"> |
| 50 | + Personal Bank: |
| 51 | + <span class="text-text"> |
| 52 | + {formatNumber(profile.personalBank)} |
| 53 | + </span> |
| 54 | + </h3> |
| 55 | + {/if} |
69 | 56 | </div> |
70 | | - {#if profile.skills.averageSkillLevelWithProgress != null} |
| 57 | + </AdditionStat> |
| 58 | + {/if} |
| 59 | + {#if profile.skills?.averageSkillLevel} |
| 60 | + <AdditionStat text="Average Skill Level" data={profile.skills.averageSkillLevel.toFixed(2)} asterisk={true}> |
| 61 | + <div class="max-w-xs space-y-2"> |
71 | 62 | <div> |
72 | 63 | <h3 class="font-bold text-text/85"> |
73 | | - Average Level: |
| 64 | + Total Skill XP: |
74 | 65 | <span class="text-text"> |
75 | | - {profile.skills.averageSkillLevelWithProgress.toFixed(2)} |
| 66 | + {numberFormat(profile.skills.totalSkillXp, defaultPattern)} |
76 | 67 | </span> |
77 | 68 | </h3> |
78 | | - <p class="font-medium text-text/80">Average skill level over all skills except Social and Runecrafting, includes progress to next level.</p> |
| 69 | + <p class="font-medium text-text/80">Total XP gained in all skills except Social and Runecrafting.</p> |
| 70 | + </div> |
| 71 | + {#if profile.skills.averageSkillLevelWithProgress != null} |
| 72 | + <div> |
| 73 | + <h3 class="font-bold text-text/85"> |
| 74 | + Average Level: |
| 75 | + <span class="text-text"> |
| 76 | + {profile.skills.averageSkillLevelWithProgress.toFixed(2)} |
| 77 | + </span> |
| 78 | + </h3> |
| 79 | + <p class="font-medium text-text/80">Average skill level over all skills except Social and Runecrafting, includes progress to next level.</p> |
| 80 | + </div> |
| 81 | + {/if} |
| 82 | + <div> |
| 83 | + <h3 class="font-bold text-text/85"> |
| 84 | + Average Level without progress: |
| 85 | + <span class="text-text"> |
| 86 | + {numberFormat(profile.skills.averageSkillLevel, defaultPatternDecimal)} |
| 87 | + </span> |
| 88 | + </h3> |
| 89 | + <p class="font-medium text-text/80">Average skill level without including partial level progress.</p> |
79 | 90 | </div> |
80 | | - {/if} |
81 | | - <div> |
82 | | - <h3 class="font-bold text-text/85"> |
83 | | - Average Level without progress: |
84 | | - <span class="text-text"> |
85 | | - {numberFormat(profile.skills.averageSkillLevel, defaultPatternDecimal)} |
86 | | - </span> |
87 | | - </h3> |
88 | | - <p class="font-medium text-text/80">Average skill level without including partial level progress.</p> |
89 | 91 | </div> |
90 | | - </div> |
91 | | - </AdditionStat> |
92 | | - {/if} |
93 | | - {#if profile.fairySouls} |
94 | | - <AdditionStat text="Fairy Souls" data={`${profile.fairySouls.found} / ${profile.fairySouls.total}`} maxed={(profile.fairySouls.found ?? 0) >= (profile.fairySouls.total ?? 0)} asterisk={true}> |
95 | | - {calculatePercentage(profile.fairySouls.found ?? 0, profile.fairySouls.total ?? 0)}% of fairy souls found. |
96 | | - </AdditionStat> |
| 92 | + </AdditionStat> |
| 93 | + {/if} |
| 94 | + {#if profile.fairySouls} |
| 95 | + <AdditionStat text="Fairy Souls" data={`${profile.fairySouls.found} / ${profile.fairySouls.total}`} maxed={(profile.fairySouls.found ?? 0) >= (profile.fairySouls.total ?? 0)} asterisk={true}> |
| 96 | + {calculatePercentage(profile.fairySouls.found ?? 0, profile.fairySouls.total ?? 0)}% of fairy souls found. |
| 97 | + </AdditionStat> |
| 98 | + {/if} |
97 | 99 | {/if} |
98 | | - |
99 | 100 | <svelte:boundary> |
100 | 101 | {#snippet pending()} |
101 | 102 | <div class="my-0 flex items-center gap-1 font-bold text-text/60"> |
|
132 | 133 | <Button.Root onclick={retry} class="text-icon hover:text-icon/80">Retry</Button.Root> |
133 | 134 | </div> |
134 | 135 | {/snippet} |
135 | | - {@const networthData = await getNetworth({ uuid: profileUUID!, profileId: profileId! })} |
| 136 | + {#if profileUUID != null && profileId != null} |
| 137 | + {@const networthData = await getNetworth({ uuid: profileUUID, profileId: profileId })} |
136 | 138 |
|
137 | | - {#if networthData.normal} |
138 | | - {@render NetworthSnippet(networthData.normal, "Networth")} |
139 | | - {/if} |
140 | | - {#if networthData.nonCosmetic} |
141 | | - {@render NetworthSnippet(networthData.nonCosmetic, "Non-Cosmetic Networth")} |
| 139 | + {#if networthData.normal} |
| 140 | + {@render NetworthSnippet(networthData.normal, "Networth")} |
| 141 | + {/if} |
| 142 | + {#if networthData.nonCosmetic} |
| 143 | + {@render NetworthSnippet(networthData.nonCosmetic, "Non-Cosmetic Networth")} |
| 144 | + {/if} |
142 | 145 | {/if} |
143 | 146 | </svelte:boundary> |
144 | 147 | </div> |
|
0 commit comments