Skip to content

Commit d138b96

Browse files
authored
Refactor/jsdoc userecentsearches (JhaSourav07#650)
## Description Added standard JSDoc comments to `useRecentSearches`, `addSearch`, and `clearSearches` in `hooks/useRecentSearches.ts`. Fixes JhaSourav07#324 ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview N/A ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [x] I have tested these changes locally (`localhost:3000/api/streak?user=YOUR_USERNAME`). - [x] I have run `npm run format` and `npm run lint` locally and resolved all errors (CI will fail otherwise). - [x] My commits follow the Conventional Commits format (e.g., `feat(themes): ...`, `fix(calculate): ...`). - [x] I have updated `README.md` if I added a new theme or URL parameter. - [x] I have started the repo. - [x] I have made sure that i have only one commit to merge in this PR. - [x] The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts). - [x] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
1 parent 20526ee commit d138b96

4 files changed

Lines changed: 40 additions & 14 deletions

File tree

hooks/useRecentSearches.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ function writeStorage(searches: string[] | null): void {
3131
}
3232
}
3333

34+
/**
35+
* A hook to manage and persist a list of recent searches.
36+
*
37+
* It uses localStorage for persistence and ensures SSR compatibility by starting
38+
* with an empty state on the first render and updating upon hydration.
39+
*
40+
* @returns An object containing the recent searches, a function to add a search, and a function to clear all searches.
41+
*/
3442
export function useRecentSearches() {
3543
// Always start with [] and mounted:false on both server and client so the
3644
// initial render matches (SSR-safe). A single setState in the mount effect
@@ -46,6 +54,13 @@ export function useRecentSearches() {
4654
setState({ searches: loadFromStorage(), mounted: true });
4755
}, []);
4856

57+
/**
58+
* Adds a new search query to the recent searches list.
59+
* If the query already exists, it is moved to the top.
60+
* The list is truncated to the maximum number of searches allowed.
61+
*
62+
* @param query - The search query to add.
63+
*/
4964
const addSearch = (query: string) => {
5065
if (!query.trim()) return;
5166
setState((prev) => {
@@ -55,6 +70,9 @@ export function useRecentSearches() {
5570
});
5671
};
5772

73+
/**
74+
* Clears all recent searches from state and localStorage.
75+
*/
5876
const clearSearches = () => {
5977
setState((prev) => ({ ...prev, searches: [] }));
6078
writeStorage(null);

lib/svg/constants.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export const SVG_WIDTH = 600;
2+
export const SVG_HEIGHT = 420;
3+
4+
export const GHOST_HEIGHT_PX = 4;
5+
export const LOG_SCALE_MULTIPLIER = 12;
6+
export const LINEAR_SCALE_MULTIPLIER = 5;
7+
export const MAX_LOG_HEIGHT = 80;
8+
export const MAX_LINEAR_HEIGHT = 50;
9+
10+
export const FONT_MAP: Record<string, string> = {
11+
jetbrains: '"JetBrains Mono", monospace',
12+
fira: '"Fira Code", monospace',
13+
roboto: '"Roboto", sans-serif',
14+
};

lib/svg/generator.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,7 @@ import { TOWER_ANIMATION_CSS } from './animations';
55
import { computeTowers, type TowerData } from './layout';
66
import { sanitizeFont, sanitizeHexColor, sanitizeRadius, sanitizeGoogleFontUrl } from './sanitizer';
77

8-
const SVG_WIDTH = 600;
9-
const SVG_HEIGHT = 420;
10-
11-
const FONT_MAP: Record<string, string> = {
12-
jetbrains: '"JetBrains Mono", monospace',
13-
fira: '"Fira Code", monospace',
14-
roboto: '"Roboto", sans-serif',
15-
};
8+
import { SVG_WIDTH, SVG_HEIGHT, FONT_MAP } from './constants';
169

1710
// helpers
1811
function getSizeScale(size?: 'small' | 'medium' | 'large'): number {

lib/svg/layout.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import type { ContributionCalendar } from '../../types';
22

3-
// constants
4-
const GHOST_HEIGHT_PX = 4;
5-
const LOG_SCALE_MULTIPLIER = 12;
6-
const LINEAR_SCALE_MULTIPLIER = 5;
7-
const MAX_LOG_HEIGHT = 80;
8-
const MAX_LINEAR_HEIGHT = 50;
3+
import {
4+
GHOST_HEIGHT_PX,
5+
LOG_SCALE_MULTIPLIER,
6+
LINEAR_SCALE_MULTIPLIER,
7+
MAX_LOG_HEIGHT,
8+
MAX_LINEAR_HEIGHT,
9+
} from './constants';
910

1011
/** Shared layout data for a single isometric tower. */
1112
export interface FaceOpacity {

0 commit comments

Comments
 (0)