Skip to content

Commit 980eb84

Browse files
Merge branch 'dostonnabotov:main' into feat/restrict-snippet-height
2 parents 4a850cf + 91d290e commit 980eb84

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(
@@ -650,6 +654,13 @@ abbr {
650654
color: var(--clr-text-secondary);
651655
}
652656

657+
.category-no-snippets-found {
658+
text-align: center;
659+
font-size: var(--fs-500);
660+
color: var(--clr-text-primary);
661+
padding: 1rem;
662+
height: 100%;
663+
}
653664
/*------------------------------------*\
654665
#MODAL
655666
\*------------------------------------*/

0 commit comments

Comments
 (0)