Skip to content

Commit e0240b3

Browse files
authored
Merge branch 'dostonnabotov:main' into main
2 parents 4ba59b3 + afae80d commit e0240b3

File tree

8 files changed

+83
-27
lines changed

8 files changed

+83
-27
lines changed

.github/workflows/consolidate-snippets.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,20 @@ jobs:
1616
- name: Checkout repository
1717
uses: actions/checkout@v3
1818

19+
- name: Install jq (for JSON manipulation)
20+
run: sudo apt-get install -y jq
21+
1922
- name: Consolidate JSON files
2023
run: |
2124
mkdir -p public/consolidated
2225
echo "[" > public/consolidated/all_snippets.json
23-
find public/data -name "*.json" -exec sh -c 'jq -c ".[]" {} | sed "s/^/{\"language\": \"$(basename {} .json)\", /" | sed "s/}/},/" >> public/consolidated/all_snippets.json' \;
26+
find public/data -name "*.json" ! -name "_index.json" -exec sh -c '
27+
for file; do
28+
jq -c ".[]" "$file" | \
29+
sed "s/^/{\"language\": \"$(basename "$file" .json)\", /" | \
30+
sed "s/}$/}/" >> public/consolidated/all_snippets.json
31+
done
32+
' _ {} +
2433
sed -i '$ s/,$//' public/consolidated/all_snippets.json
2534
echo "]" >> public/consolidated/all_snippets.json
2635

public/consolidated/all_snippets.json

Lines changed: 22 additions & 25 deletions
Large diffs are not rendered by default.

public/data/_index.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,9 @@
1414
{
1515
"lang": "SCSS",
1616
"icon": "/icons/sass.svg"
17+
},
18+
{
19+
"lang": "CPP",
20+
"icon": "/icons/cpp.svg"
1721
}
1822
]

public/data/cpp.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[
2+
{
3+
"categoryName": "String Manipulation",
4+
"snippets": [
5+
{
6+
"title": "Reverse String",
7+
"description": "Reverses the characters in a string.",
8+
"code": [
9+
"string reverseString(const string& input) {",
10+
" string reversed = input;",
11+
" reverse(reversed.begin(), reversed.end()); // Using STL's reverse function",
12+
" return reversed;",
13+
"}"
14+
],
15+
"tags": ["cpp", "array", "reverse", "utility"],
16+
"author": "Vaibhav-kesarwani"
17+
}
18+
]
19+
}
20+
]

public/data/scss.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
},
9393
{
9494
"title": "Aspect Ratio",
95-
"description": "Ensures that elements maintain a specific aspect ratio.",
95+
"description": "Ensures elements maintain a specific aspect ratio.",
9696
"code": [
9797
"@mixin aspect-ratio($width, $height) {",
9898
" position: relative;",

public/icons/cpp.svg

Lines changed: 8 additions & 0 deletions
Loading

src/components/SnippetModal.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { CloseIcon } from "./Icons";
55
import CodePreview from "./CodePreview";
66
import { SnippetType } from "../types";
77
import slugify from "../utils/slugify";
8+
import useEscapeKey from "../hooks/useEscapeKey";
89

910
type Props = {
1011
snippet: SnippetType;
@@ -19,6 +20,7 @@ const SnippetModal: React.FC<Props> = ({
1920
}) => {
2021
const modalRoot = document.getElementById("modal-root");
2122
if (!modalRoot) return null;
23+
useEscapeKey(handleCloseModal);
2224

2325
return ReactDOM.createPortal(
2426
<div className="modal-overlay">

src/hooks/useEscapeKey.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { useEffect } from "react"
2+
3+
const useEscapeKey = (onEscapeEvent: () => void) => {
4+
useEffect(() => {
5+
const handleEscape = (event: { key: string }) => {
6+
if (event.key === "Escape") onEscapeEvent();
7+
}
8+
window.addEventListener("keydown", handleEscape);
9+
10+
return () => {
11+
window.removeEventListener("keydown", handleEscape);
12+
}
13+
}, [onEscapeEvent]);
14+
};
15+
16+
export default useEscapeKey;

0 commit comments

Comments
 (0)