Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 91d290e

Browse files
Merge pull request #245 from ACR1209/tweak/fix-loading-state-blinking-arrow
Remove blinking arrow and add message for empty categories
2 parents d9bdf59 + 772497f commit 91d290e

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

‎src/components/SnippetList.tsx

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,17 @@ import {
1212
} from "@utils/languageUtils";
1313
import { slugify } from "@utils/slugify";
1414

15-
import { LeftAngleArrowIcon } from "./Icons";
1615
import SnippetModal from "./SnippetModal";
1716

1817
const SnippetList = () => {
1918
const [searchParams, setSearchParams] = useSearchParams();
20-
const shouldReduceMotion = useReducedMotion();
21-
19+
const { fetchedSnippets, loading } = useSnippets();
2220
const { language, subLanguage, snippet, setSnippet } = useAppContext();
23-
const { fetchedSnippets } = useSnippets();
2421

2522
const [isModalOpen, setIsModalOpen] = useState<boolean>(false);
2623

24+
const shouldReduceMotion = useReducedMotion();
25+
2726
const handleOpenModal = (selected: SnippetType) => () => {
2827
setIsModalOpen(true);
2928
setSnippet(selected);
@@ -56,18 +55,29 @@ const SnippetList = () => {
5655
// eslint-disable-next-line react-hooks/exhaustive-deps
5756
}, [fetchedSnippets, searchParams]);
5857

59-
if (!fetchedSnippets) {
60-
return (
61-
<div>
62-
<LeftAngleArrowIcon />
63-
</div>
64-
);
65-
}
58+
if (loading) return null;
6659

6760
return (
6861
<>
69-
<motion.ul role="list" className="snippets">
62+
<motion.ul
63+
role="list"
64+
className={`snippets ${fetchedSnippets && fetchedSnippets.length === 0 ? "data-empty" : ""}`}
65+
>
7066
<AnimatePresence mode="popLayout">
67+
{fetchedSnippets && fetchedSnippets.length === 0 && (
68+
<div className="category-no-snippets-found">
69+
<p>No snippets found for this category. Why not add one? 🚀</p>
70+
<a
71+
href="https://github.com/dostonnabotov/quicksnip/blob/main/CONTRIBUTING.md"
72+
target="_blank"
73+
rel="noopener noreferrer"
74+
className="styled-link"
75+
>
76+
Add your own snippet
77+
</a>
78+
</div>
79+
)}
80+
7181
{fetchedSnippets.map((snippet, idx) => {
7282
const uniqueId = `${language.name}-${snippet.title}-${idx}`;
7383
return (

‎src/styles/main.css

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ abbr {
221221
--_flow-space: 2rem;
222222
}
223223

224+
.flow:has(.data-empty) {
225+
height: 100%;
226+
}
227+
224228
/* Text */
225229
.main-title {
226230
font-size: var(--fs-800);
@@ -592,7 +596,7 @@ abbr {
592596
* 1. Responsive grid that adjusts columns automatically
593597
* Each item has a minimum width of 17.5rem and maximum of 100%
594598
*/
595-
.snippets {
599+
.snippets:not(.data-empty) {
596600
display: grid;
597601
gap: 1.5rem;
598602
grid-template-columns: repeat(
@@ -631,6 +635,13 @@ abbr {
631635
color: var(--clr-text-secondary);
632636
}
633637

638+
.category-no-snippets-found {
639+
text-align: center;
640+
font-size: var(--fs-500);
641+
color: var(--clr-text-primary);
642+
padding: 1rem;
643+
height: 100%;
644+
}
634645
/*------------------------------------*\
635646
#MODAL
636647
\*------------------------------------*/

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /