|
9 | 9 | import type { ProcessedStats } from "$lib/stats"; |
10 | 10 | import { STATS_INTROS, STATS_OUTROS } from "$lib/strings"; |
11 | 11 | import { randChoice } from "$lib/util/array"; |
12 | | - import { removeUrlParams } from "$lib/util/string"; |
| 12 | + import { capitalize, removeUrlParams } from "$lib/util/string"; |
13 | 13 |
|
14 | 14 | export let stats: ProcessedStats; |
15 | 15 | export let api: SongAPI; |
| 16 | + export let receivedShareName: string | null = null; |
16 | 17 |
|
17 | 18 | export let onClose: () => any = () => console.warn("onClose not set") |
18 | 19 |
|
19 | 20 | const introText = randChoice(STATS_INTROS); |
20 | 21 | const outroText = randChoice(STATS_OUTROS); |
21 | | - const shareURL = removeUrlParams(window.location.href) + "?s=" + stats.toBase64(); |
| 22 | + const defaultName = "someone"; |
22 | 23 |
|
| 24 | + let shareName: string | undefined; |
| 25 | + let pronoun1 = "you"; |
| 26 | + let pronoun2 = "your"; |
| 27 | + |
23 | 28 | let currentPage = 0; |
24 | 29 | const pageCount = 5; |
25 | 30 |
|
| 31 | + if(receivedShareName) { |
| 32 | + pronoun1 = "they"; |
| 33 | + pronoun2 = "their"; |
| 34 | + } |
| 35 | +
|
26 | 36 | function prev() { |
27 | 37 | if(currentPage > 0) { |
28 | 38 | currentPage -= 1; |
|
67 | 77 | <div id="stats-view-main"> |
68 | 78 | <div id="stats-view-content"> |
69 | 79 | {#snippet pageIntro()} |
70 | | - <h1>{introText}</h1> |
| 80 | + <h1> |
| 81 | + {#if receivedShareName} |
| 82 | + {receivedShareName} wants to show you their music taste! |
| 83 | + {:else} |
| 84 | + {introText} |
| 85 | + {/if} |
| 86 | + </h1> |
71 | 87 | {/snippet} |
72 | 88 |
|
73 | 89 | {#snippet numStats()} |
74 | | - <h1>You listened to</h1> |
| 90 | + <h1>{capitalize(pronoun1)} listened to</h1> |
75 | 91 |
|
76 | 92 | <div class="flex"> |
77 | 93 | <Counter |
|
87 | 103 | {/snippet} |
88 | 104 |
|
89 | 105 | {#snippet pageFavSongsAllTime()} |
90 | | - <h1>These are your favorite songs</h1> |
| 106 | + <h1>These are {pronoun2} favorite songs</h1> |
91 | 107 | <SongList songs={stats.getTopSongs()} api={api} /> |
92 | 108 | {/snippet} |
93 | 109 |
|
94 | 110 | {#snippet pageFavArtistsAllTime()} |
95 | | - <h1>And these are your favorite artists</h1> |
| 111 | + <h1>And these are {pronoun2} favorite artists</h1> |
96 | 112 | <ArtistList artists={stats.getTopArtists()} /> |
97 | 113 | {/snippet} |
98 | 114 |
|
99 | 115 | {#snippet pageEnd()} |
100 | 116 | <h1>{outroText}</h1> |
101 | | - |
| 117 | + |
102 | 118 | <div style="text-align: center; margin: 0 auto; max-width: 500px"> |
103 | | - <p>Share your stats!</p> |
104 | | - <CopyField value={shareURL} /> |
| 119 | + {#if !receivedShareName} |
| 120 | + <h2>Share your stats!</h2> |
| 121 | + <label for="name-inp">Your name: (optional)</label> |
| 122 | + |
| 123 | + <input |
| 124 | + type="text" |
| 125 | + maxlength="28" |
| 126 | + bind:value={shareName} |
| 127 | + placeholder={defaultName} |
| 128 | + id="name-inp" |
| 129 | + /> |
| 130 | + |
| 131 | + <CopyField value={ |
| 132 | + (() => { |
| 133 | + let nameParam = ""; |
| 134 | + const statsParam = `s=${stats.toBase64()}`; |
| 135 | + |
| 136 | + if(shareName && shareName.length != 0 && shareName != defaultName) { |
| 137 | + nameParam = `name=${shareName}&`; |
| 138 | + } |
| 139 | + |
| 140 | + return `${removeUrlParams(window.location.href)}?${nameParam}${statsParam}` |
| 141 | + })() |
| 142 | + } /> |
| 143 | + {/if} |
| 144 | + |
105 | 145 | <LinkButton text="Home page" onClick={onClose} highlight /> |
106 | 146 | </div> |
107 | 147 | {/snippet} |
|
0 commit comments