@@ -22,6 +22,7 @@ import IconOnlyButton from "../Widgets/Buttons/IconOnlyButton";
2222import SecondaryButton from "../Widgets/Buttons/SecondaryButton" ;
2323import { IoClose } from "react-icons/io5" ;
2424import Loading from "../Widgets/Loading/Loading" ;
25+ import { HiOutlineRefresh } from "react-icons/hi" ;
2526
2627type GitHubProps = {
2728 viewGithubWindow : boolean ;
@@ -49,7 +50,15 @@ export default function GitHub({
4950 const navigate = useNavigate ( ) ;
5051
5152 useEffect ( ( ) => {
52- githubData ?. token && getAllRepos ( ) ;
53+ const cachedGithubRepos = localStorage . getItem ( "cachedGithubRepos" ) ;
54+ if ( githubData ?. token ) {
55+ if ( cachedGithubRepos ) {
56+ setRepos ( JSON . parse ( cachedGithubRepos ) ) ;
57+ setFilteredRepos ( JSON . parse ( cachedGithubRepos ) ) ;
58+ } else {
59+ getAllRepos ( ) ;
60+ }
61+ }
5362 } , [ githubData ?. token ] ) ;
5463
5564 const getAllRepos = async ( ) => {
@@ -67,6 +76,7 @@ export default function GitHub({
6776 setLoading ( false ) ;
6877 setRepos ( data ) ;
6978 setFilteredRepos ( data ) ;
79+ localStorage . setItem ( "cachedGithubRepos" , JSON . stringify ( data ) ) ;
7080 } ;
7181
7282 const readRepoConfig = async (
@@ -128,8 +138,8 @@ export default function GitHub({
128138 icon : userData . data . avatar_url ,
129139 email : userData . data . email ,
130140 } ) ;
131- const encodedData = Buffer . from ( data , "binary" ) . toString ( "base64" ) ;
132141 dispatch ( setGithubData ( data ) ) ;
142+ const encodedData = Buffer . from ( data , "binary" ) . toString ( "base64" ) ;
133143 localStorage . setItem ( "githubData" , encodedData ) ;
134144 } catch ( e : any ) {
135145 if ( e . message . includes ( "Bad credentials" ) ) {
@@ -196,7 +206,10 @@ export default function GitHub({
196206 icon = { < VscDebugDisconnect size = { 25 } className = { `text-red-500` } /> }
197207 onClick = { ( ) => {
198208 localStorage . removeItem ( "githubData" ) ;
209+ localStorage . removeItem ( "cachedGithubRepos" ) ;
199210 dispatch ( setGithubData ( null ) ) ;
211+ setRepos ( [ ] ) ;
212+ setFilteredRepos ( [ ] ) ;
200213 } }
201214 />
202215 </ div >
@@ -286,25 +299,28 @@ export default function GitHub({
286299 < p className = "text-[20px] font-medium text-gray-700 dark:text-gray-300/80" >
287300 { `Found ${ repos . length } repositories:` }
288301 </ p >
289- < div className = "w-full" >
290- < InputBox
291- type = "text"
292- className = ""
293- value = { searchedRepo }
294- onChange = { ( e ) => {
295- setSearchedRepo ( e . target . value ) ;
296- setFilteredRepos (
297- repos . filter (
298- ( repo : any ) =>
299- repo . name
300- . toLowerCase ( )
301- . indexOf ( e . target . value . toLowerCase ( ) ) !== - 1
302- )
303- ) ;
304- } }
305- placeholder = "Search repo name here..."
306- disabled = { false }
307- />
302+ < div className = "w-full flex flex-row justify-between items-center gap-4" >
303+ < div className = "w-full" >
304+ < InputBox
305+ type = "text"
306+ className = "w-full"
307+ value = { searchedRepo }
308+ onChange = { ( e ) => {
309+ setSearchedRepo ( e . target . value ) ;
310+ setFilteredRepos (
311+ repos . filter (
312+ ( repo : any ) =>
313+ repo . name
314+ . toLowerCase ( )
315+ . indexOf ( e . target . value . toLowerCase ( ) ) !== - 1
316+ )
317+ ) ;
318+ } }
319+ placeholder = "Search repo name here..."
320+ disabled = { false }
321+ />
322+ </ div >
323+ < IconOnlyButton className = { `${ loading ?"rotate" :"" } ` } icon = { < HiOutlineRefresh size = { 20 } /> } onClick = { ( ) => { setRepos ( [ ] ) ; setFilteredRepos ( [ ] ) ; getAllRepos ( ) ; } } />
308324 </ div >
309325 < div
310326 className = { `mt-4 ${
0 commit comments