tangled
alpha
login
or
join now
leaflet.pub
/
leaflet
289
fork
atom
a tool for shared writing and social publishing
289
fork
atom
overview
issues
28
pulls
pipelines
simplify mention logic
awarm.space
3 months ago
480e7bd7
26ada46a
+16
-46
1 changed file
expand all
collapse all
unified
split
components
Mention.tsx
+16
-46
components/Mention.tsx
···
135
135
136
136
const headerStyle = "text-xs text-tertiary font-bold pt-1 px-2";
137
137
138
138
-
const getHeader = (type: Mention["type"]) => {
139
139
-
switch (type) {
140
140
-
case "did":
141
141
-
return "People";
142
142
-
case "publication":
143
143
-
return "Publications";
144
144
-
}
145
145
-
};
146
146
-
147
147
-
const getKey = (mention: Mention) => {
148
148
-
switch (mention.type) {
149
149
-
case "did":
150
150
-
return mention.did;
151
151
-
case "publication":
152
152
-
return mention.uri;
153
153
-
}
154
154
-
};
155
155
-
156
156
-
const getResultText = (mention: Mention) => {
157
157
-
switch (mention.type) {
158
158
-
case "did":
159
159
-
return mention.displayName || `@${mention.handle}`;
160
160
-
case "publication":
161
161
-
return mention.name;
162
162
-
}
163
163
-
};
164
164
-
165
165
-
const getSubtext = (mention: Mention) => {
166
166
-
switch (mention.type) {
167
167
-
case "did":
168
168
-
return mention.displayName ? `@${mention.handle}` : undefined;
169
169
-
case "publication":
170
170
-
return undefined;
171
171
-
}
172
172
-
};
173
173
-
174
138
const sortedSuggestions = [...suggestions].sort((a, b) => {
175
139
const order: Mention["type"][] = ["did", "publication"];
176
140
return order.indexOf(a.type) - order.indexOf(b.type);
···
202
166
<ul className="list-none p-0 text-sm">
203
167
{sortedSuggestions.map((result, index) => {
204
168
const prevResult = sortedSuggestions[index - 1];
205
205
-
const showHeader = !prevResult || prevResult.type !== result.type;
169
169
+
const showHeader =
170
170
+
prevResult && prevResult.type !== result.type;
171
171
+
172
172
+
const [key, resultText, subtext] =
173
173
+
result.type === "did"
174
174
+
? [
175
175
+
result.did,
176
176
+
result.displayName || `@${result.handle}`,
177
177
+
result.displayName ? `@${result.handle}` : undefined,
178
178
+
]
179
179
+
: [result.uri, result.name, undefined];
206
180
207
181
return (
208
182
<>
209
183
{showHeader && (
210
184
<>
211
211
-
{index > 0 && (
212
212
-
<hr className="border-border-light mx-1 my-1" />
213
213
-
)}
214
214
-
<div className={headerStyle}>
215
215
-
{getHeader(result.type)}
216
216
-
</div>
185
185
+
<hr className="border-border-light mx-1 my-1" />
186
186
+
<div className={headerStyle}>Publications</div>
217
187
</>
218
188
)}
219
189
<Result
220
220
-
key={getKey(result)}
190
190
+
key={key}
221
191
onClick={() => {
222
192
if (mentionRange) {
223
193
props.onSelect(result, mentionRange);
···
227
197
}
228
198
}}
229
199
onMouseDown={(e) => e.preventDefault()}
230
230
-
result={getResultText(result)}
231
231
-
subtext={getSubtext(result)}
200
200
+
result={resultText}
201
201
+
subtext={subtext}
232
202
selected={index === suggestionIndex}
233
203
/>
234
204
</>