Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Commit 68adf8a

Browse files
committed
fix: allow dismiss contributing to autocomplete
1 parent 992f2ce commit 68adf8a

1 file changed

Lines changed: 64 additions & 41 deletions

File tree

components/explain.tsx

Lines changed: 64 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useMemo } from "react";
1+
import React, { useEffect, useMemo, useState } from "react";
22
import { HiExclamationCircle, HiXCircle } from "react-icons/hi";
33
import clsx from "clsx";
44
import { sentenceCase } from "sentence-case";
@@ -45,6 +45,17 @@ const Explain: React.FC<Props> = ({
4545
}
4646
}, [spec, simpleTokens]);
4747

48+
const [ctaContribToAutocompleteVisible, setCtaContribToAutocompleteVisible] =
49+
useState(
50+
() => localStorage.getItem("cta/contributeToAutocomplete") !== "off"
51+
);
52+
useEffect(() => {
53+
localStorage.setItem(
54+
"cta/contributeToAutocomplete",
55+
ctaContribToAutocompleteVisible ? "on" : "off"
56+
);
57+
}, [ctaContribToAutocompleteVisible]);
58+
4859
if (!cmd || !spec || !parsed)
4960
return (
5061
<div className="rounded-md bg-yellow-50 p-4">
@@ -101,49 +112,61 @@ const Explain: React.FC<Props> = ({
101112
);
102113

103114
return (
104-
<div className="flex flex-col items-stretch space-y-4 select-none">
115+
<>
105116
{/* Results */}
106-
{parsed.map((token) => (
107-
<div
108-
key={token.indices[0]}
109-
className={clsx(
110-
"bg-white text-gray-900 dark:bg-black dark:text-white shadow-md rounded p-4 border-2 border-transparent transition",
111-
selection[0] !== null &&
112-
selection[0] >= token.indices[0] &&
113-
selection[0] <= token.indices[1] &&
114-
"border-teal-400 opacity-100"
115-
)}
116-
onMouseEnter={() =>
117-
onSelectionChange([token.indices[0], token.indices[1]])
118-
}
119-
onClick={() =>
120-
onSelectionChange([token.indices[0], token.indices[1]])
121-
}
122-
>
123-
<div className="font-mono font-bold">
124-
<span>
125-
{token.value}
126-
{token.displayName ? ` - ${token.displayName}` : ""}
127-
</span>
117+
<div className="flex flex-col items-stretch space-y-4 select-none">
118+
{parsed.map((token) => (
119+
<div
120+
key={token.indices[0]}
121+
className={clsx(
122+
"bg-white text-gray-900 dark:bg-black dark:text-white shadow-md rounded p-4 border-2 border-transparent transition",
123+
selection[0] !== null &&
124+
selection[0] >= token.indices[0] &&
125+
selection[0] <= token.indices[1] &&
126+
"border-teal-400 opacity-100"
127+
)}
128+
onMouseEnter={() =>
129+
onSelectionChange([token.indices[0], token.indices[1]])
130+
}
131+
onClick={() =>
132+
onSelectionChange([token.indices[0], token.indices[1]])
133+
}
134+
>
135+
<div className="font-mono font-bold">
136+
<span>
137+
{token.value}
138+
{token.displayName ? ` - ${token.displayName}` : ""}
139+
</span>
140+
</div>
141+
<div>{token.description || sentenceCase(token.type)}</div>
128142
</div>
129-
<div>{token.description || sentenceCase(token.type)}</div>
130-
</div>
131-
))}
132-
{/* CTA to contribute */}
133-
<div className="bg-white text-gray-500 dark:bg-black dark:text-gray-400 shadow-md rounded p-4 border-2 border-transparent transition">
134-
Want to make the descriptions better? They{"'"}re open-source!
135-
Contribute at{" "}
136-
<a
137-
href="https://github.com/withfig/autocomplete"
138-
target="_blank"
139-
rel="noopener noreferrer"
140-
className="hover:text-gray-900 dark:hover:text-gray-100"
141-
>
142-
withfig/autocomplete on Github
143-
</a>
144-
.
143+
))}
145144
</div>
146-
</div>
145+
{/* CTA to contribute */}
146+
{ctaContribToAutocompleteVisible && (
147+
<div className="mt-6 text-xs bg-white text-gray-500 dark:bg-black dark:text-gray-400 rounded-full transition flex flex-col items-center">
148+
<div className="text-center leading-relaxed">
149+
Could the descriptions be better? <br className="sm:hidden" />
150+
Contribute at{" "}
151+
<a
152+
href="https://github.com/withfig/autocomplete"
153+
target="_blank"
154+
rel="noopener noreferrer"
155+
className="hover:text-gray-900 dark:hover:text-gray-100"
156+
>
157+
withfig/autocomplete on Github
158+
</a>
159+
.
160+
</div>
161+
<button
162+
className="mt-1 sm:mt-0.5 font-medium text-gray-400 hover:text-gray-600"
163+
onClick={() => setCtaContribToAutocompleteVisible(false)}
164+
>
165+
Dismiss
166+
</button>
167+
</div>
168+
)}
169+
</>
147170
);
148171
};
149172

0 commit comments

Comments
 (0)