Skip to content

Remove blinking arrow and add message for empty categories #245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions src/components/SnippetList.tsx
Original file line number Diff line number Diff line change
@@ -12,18 +12,17 @@ import {
} from "@utils/languageUtils";
import { slugify } from "@utils/slugify";

import { LeftAngleArrowIcon } from "./Icons";
import SnippetModal from "./SnippetModal";

const SnippetList = () => {
const [searchParams, setSearchParams] = useSearchParams();
const shouldReduceMotion = useReducedMotion();

const { fetchedSnippets, loading } = useSnippets();
const { language, subLanguage, snippet, setSnippet } = useAppContext();
const { fetchedSnippets } = useSnippets();

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

const shouldReduceMotion = useReducedMotion();

const handleOpenModal = (selected: SnippetType) => () => {
setIsModalOpen(true);
setSnippet(selected);
@@ -56,18 +55,29 @@ const SnippetList = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [fetchedSnippets, searchParams]);

if (!fetchedSnippets) {
return (
<div>
<LeftAngleArrowIcon />
</div>
);
}
if (loading) return null;

return (
<>
<motion.ul role="list" className="snippets">
<motion.ul
role="list"
className={`snippets ${fetchedSnippets && fetchedSnippets.length === 0 ? "data-empty" : ""}`}
>
<AnimatePresence mode="popLayout">
{fetchedSnippets && fetchedSnippets.length === 0 && (
<div className="category-no-snippets-found">
<p>No snippets found for this category. Why not add one? 🚀</p>
<a
href="https://github.com/dostonnabotov/quicksnip/blob/main/CONTRIBUTING.md"
target="_blank"
rel="noopener noreferrer"
className="styled-link"
>
Add your own snippet
</a>
</div>
)}

{fetchedSnippets.map((snippet, idx) => {
const uniqueId = `${language.name}-${snippet.title}-${idx}`;
return (
13 changes: 12 additions & 1 deletion src/styles/main.css
Original file line number Diff line number Diff line change
@@ -221,6 +221,10 @@ abbr {
--_flow-space: 2rem;
}

.flow:has(.data-empty) {
height: 100%;
}

/* Text */
.main-title {
font-size: var(--fs-800);
@@ -592,7 +596,7 @@ abbr {
* 1. Responsive grid that adjusts columns automatically
* Each item has a minimum width of 17.5rem and maximum of 100%
*/
.snippets {
.snippets:not(.data-empty) {
display: grid;
gap: 1.5rem;
grid-template-columns: repeat(
@@ -631,6 +635,13 @@ abbr {
color: var(--clr-text-secondary);
}

.category-no-snippets-found {
text-align: center;
font-size: var(--fs-500);
color: var(--clr-text-primary);
padding: 1rem;
height: 100%;
}
/*------------------------------------*\
#MODAL
\*------------------------------------*/