@@ -5,7 +5,8 @@ import { Search } from "lucide-react";
55import { Input } from "@/components/ui/input" ;
66import PinButton from "../PinButton" ;
77import Fuse from "fuse.js" ;
8- import { type StoredSubjects , type ICourseWithCount , type IUpcomingPaper } from "@/interface" ;
8+ import { type ICourseWithCount , type IUpcomingPaper } from "@/interface" ;
9+ import { readPinnedSubjects } from "@/lib/utils/pinned-subjects" ;
910
1011function PinnedSearchBar ( {
1112 initialSubjects,
@@ -52,9 +53,7 @@ function PinnedSearchBar({
5253 const handleSelectSuggestion = ( suggestion : string ) => {
5354 setSearchText ( suggestion ) ;
5455
55- const currentPinnedSubjects = JSON . parse (
56- localStorage . getItem ( "userSubjects" ) ?? "[]" ,
57- ) as StoredSubjects ;
56+ const currentPinnedSubjects = readPinnedSubjects ( ) ;
5857
5958 if ( suggestion && Array . isArray ( currentPinnedSubjects ) ) {
6059 setPinned ( currentPinnedSubjects . includes ( suggestion ) ) ;
@@ -93,9 +92,7 @@ function PinnedSearchBar({
9392 return ;
9493 }
9594
96- const saved = JSON . parse (
97- localStorage . getItem ( "userSubjects" ) ?? "[]" ,
98- ) as string [ ] ;
95+ const saved = readPinnedSubjects ( ) ;
9996
10097 let updated : string [ ] = [ ] ;
10198
@@ -132,9 +129,7 @@ function PinnedSearchBar({
132129
133130 useEffect ( ( ) => {
134131 const handlePinsChange = ( ) => {
135- const saved = JSON . parse (
136- localStorage . getItem ( "userSubjects" ) ?? "[]" ,
137- ) as string [ ] ;
132+ const saved = readPinnedSubjects ( ) ;
138133
139134 if ( saved . length === 0 ) {
140135 setShowControls ( false ) ;
@@ -151,9 +146,7 @@ function PinnedSearchBar({
151146 } , [ ] ) ;
152147
153148 useEffect ( ( ) => {
154- const storedSubjects = JSON . parse (
155- localStorage . getItem ( "userSubjects" ) ?? "[]" ,
156- ) as string [ ] ;
149+ const storedSubjects = readPinnedSubjects ( ) ;
157150
158151 if ( storedSubjects . length > 0 ) {
159152 setShowControls ( true ) ;
0 commit comments