|
1 | 1 | <script lang="ts"> |
2 | 2 | import type APIManager from "src/apiManager"; |
3 | 3 | import type { DictionaryWord, HNItem } from "src/integrations/types"; |
4 | | - import type LocalDictionaryBuilder from "src/localDictionaryBuilder"; |
5 | | -
|
| 4 | + |
6 | 5 | import PhoneticComponent from "./phoneticComponent.svelte"; |
7 | 6 | import MeaningComponent from "./meaningComponent.svelte"; |
8 | 7 | import ErrorComponent from "./errorComponent.svelte"; |
9 | 8 | import OriginComponent from "./originComponent.svelte"; |
10 | 9 | import t from "src/l10n/helpers"; |
11 | 10 |
|
12 | 11 | export let manager: APIManager; |
13 | | - export let localDictionary: LocalDictionaryBuilder; |
14 | 12 |
|
15 | 13 | export let query: string = ""; |
16 | 14 | let promise: Promise<DictionaryWord>; |
|
46 | 44 | </script> |
47 | 45 |
|
48 | 46 | <div class="main"> |
49 | | - <div class="searchbox"> |
50 | | - <button class="dictionary-button" on:click={languageModal} |
51 | | - ><i class="languageIcon" alt="Language" /></button |
52 | | - > |
53 | | - <input |
54 | | - type="text" |
55 | | - spellcheck="true" |
56 | | - placeholder={t("Enter a word")} |
57 | | - bind:value={query} |
58 | | - on:keydown={handleKeyDown} |
59 | | - /> |
60 | | - <button class="dictionary-button" on:click={search} |
61 | | - ><i class="searchIcon" alt="Search" /></button |
62 | | - > |
63 | | - </div> |
64 | | - <br /> |
65 | | - <button class="dictionary-button" on:click={fetchTopHN} |
66 | | - >Fetch TopHN</button |
67 | | - > |
68 | 47 | {#if promiseTopHN} |
69 | 48 | {#await promiseTopHN} |
70 | 49 | <div class="center" /> |
71 | 50 | {:then data} |
72 | 51 | <div class="results"> |
73 | 52 | <div class="container"> |
74 | | - <p>{ data.title }</p> |
75 | | - <p>{ data.url }</p> |
| 53 | + <a href="{ data.url }" target="_blank" class="hn-link">{ data.title }</a> |
| 54 | + <br /> |
| 55 | + <p class="hn-read"> |
| 56 | + <a href="{ data.url }" target="_blank">Read more →</a> |
| 57 | + </p> |
76 | 58 | </div> |
77 | 59 | </div> |
78 | 60 | {:catch error} |
79 | 61 | <ErrorComponent {error} /> |
80 | 62 | {/await} |
81 | 63 | {/if} |
82 | | - |
83 | | - {#if promise && query.trim()} |
84 | | - {#await promise} |
85 | | - <div class="center"> |
86 | | - <div class="spinner" /> |
87 | | - </div> |
88 | | - {:then data} |
89 | | - {#if query === data.word} |
90 | | - <div class="results"> |
91 | | - {#if data.phonetics.first().text} |
92 | | - <div class="container"> |
93 | | - <h3>{t("Pronunciation")}</h3> |
94 | | - {#each data.phonetics as { text, audio }} |
95 | | - <PhoneticComponent {audio} {text} /> |
96 | | - {/each} |
97 | | - </div> |
98 | | - {/if} |
99 | | - <div class="container"> |
100 | | - <h3>{t("Meanings")}</h3> |
101 | | - {#each data.meanings as { definitions, partOfSpeech }} |
102 | | - <MeaningComponent word={data.word} {partOfSpeech} {definitions} /> |
103 | | - {/each} |
104 | | - </div> |
105 | | - {#if data.origin} |
106 | | - <div class="container"> |
107 | | - <h3>{t("Origin")}</h3> |
108 | | - <OriginComponent {data}/> |
109 | | - </div> |
110 | | - {/if} |
111 | | - </div> |
112 | | - <span |
113 | | - class="nn" |
114 | | - on:click={async () => await localDictionary.newNote(data)} |
115 | | - >{t("New Note")}</span |
116 | | - > |
117 | | - {/if} |
118 | | - {:catch error} |
119 | | - <ErrorComponent {error} /> |
120 | | - {/await} |
121 | | - {/if} |
122 | 64 | </div> |
123 | 65 |
|
124 | 66 | <style lang="scss"> |
| 67 | + .hn-link { |
| 68 | + font-size: 1em; |
| 69 | + text-decoration: none; |
| 70 | + } |
| 71 | +
|
| 72 | + .hn-read { |
| 73 | + font-size: 0.75em; |
| 74 | + text-align: right; |
| 75 | + margin-top: 0.5em; |
| 76 | + } |
| 77 | +
|
125 | 78 | .results { |
126 | 79 | display: flex; |
127 | 80 | flex-wrap: wrap; |
128 | 81 | } |
129 | 82 |
|
130 | | - .nn { |
131 | | - color: var(--text-faint); |
132 | | - transition: 0.2s; |
133 | | - width: 100%; |
134 | | - display: inline-block; |
135 | | - text-align: center; |
136 | | - margin-top: 1.5rem; |
137 | | - font-size: 1em; |
138 | | - &:hover { |
139 | | - color: var(--text); |
140 | | - } |
141 | | - } |
142 | | -
|
143 | 83 | .container { |
144 | 84 | max-width: 30vw; |
145 | 85 | width: 100%; |
146 | 86 | margin: auto; |
147 | 87 | background-color: var(--background-primary-alt); |
148 | | - padding-left: 0.5rem; |
149 | | - padding-right: 0.5rem; |
150 | | - padding-top: 0.3rem; |
151 | | - padding-bottom: 0.3rem; |
152 | | - margin-top: 0.5rem; |
| 88 | + padding: 1rem 1rem; |
| 89 | + margin-top: 0.2rem; |
153 | 90 | border-radius: 0.3rem; |
154 | | - > h3 { |
155 | | - margin-top: 0.3rem; |
156 | | - margin-bottom: 0.3rem; |
157 | | - font-weight: normal; |
158 | | - } |
159 | | - } |
160 | | -
|
161 | | - .searchbox { |
162 | | - margin-top: 0.1rem; |
163 | | - display: flex; |
164 | | -
|
165 | | - > input { |
166 | | - width: 100%; |
167 | | - margin-right: 0.8rem; |
168 | | - margin-left: 0.8rem; |
169 | | - } |
170 | | - } |
171 | | -
|
172 | | - .dictionary-button { |
173 | | - margin-right: 0px; |
174 | | - } |
175 | | -
|
176 | | - .searchIcon { |
177 | | - box-sizing: border-box; |
178 | | - position: relative; |
179 | | - display: block; |
180 | | - transform: scale(var(--ggs, 1)); |
181 | | - width: 16px; |
182 | | - height: 16px; |
183 | | - border: 2px solid; |
184 | | - border-radius: 100%; |
185 | | - margin-left: -4px; |
186 | | - margin-top: -4px; |
187 | | - } |
188 | | - .searchIcon::after { |
189 | | - content: ""; |
190 | | - display: block; |
191 | | - box-sizing: border-box; |
192 | | - position: absolute; |
193 | | - border-radius: 3px; |
194 | | - width: 2px; |
195 | | - height: 8px; |
196 | | - background: currentColor; |
197 | | - transform: rotate(-45deg); |
198 | | - top: 10px; |
199 | | - left: 12px; |
200 | | - } |
201 | | -
|
202 | | - .languageIcon, |
203 | | - .languageIcon::after, |
204 | | - .languageIcon::before { |
205 | | - display: block; |
206 | | - box-sizing: border-box; |
207 | | - height: 18px; |
208 | | - border: 2px solid; |
209 | | - } |
210 | | - .languageIcon { |
211 | | - position: relative; |
212 | | - transform: scale(var(--ggs, 1)); |
213 | | - width: 18px; |
214 | | - border-radius: 22px; |
215 | | - } |
216 | | - .languageIcon::after, |
217 | | - .languageIcon::before { |
218 | | - content: ""; |
219 | | - position: absolute; |
220 | | - width: 8px; |
221 | | - border-radius: 100%; |
222 | | - top: -2px; |
223 | | - left: 3px; |
224 | | - } |
225 | | - .languageIcon::after { |
226 | | - width: 24px; |
227 | | - height: 20px; |
228 | | - border: 2px solid transparent; |
229 | | - border-bottom: 2px solid; |
230 | | - top: -11px; |
231 | | - left: -5px; |
232 | 91 | } |
233 | 92 |
|
234 | 93 | .center { |
|
0 commit comments