1- import { Slot , component$ , useContext , useSignal , $ , type PropsOf } from '@builder.io/qwik' ;
1+ import {
2+ Slot ,
3+ component$ ,
4+ useContext ,
5+ useSignal ,
6+ $ ,
7+ type PropsOf ,
8+ isBrowser ,
9+ } from '@builder.io/qwik' ;
210import { Tabs } from '@qwik-ui/headless' ;
311import { GlobalStore } from '~/context' ;
412
513const pkgManagers = [ 'pnpm' , 'npm' , 'yarn' , 'bun' ] as const ;
6- type PkgManagers = ( typeof pkgManagers ) [ number ] ;
14+ export type PkgManagers = ( typeof pkgManagers ) [ number ] ;
15+
16+ const pkgManagerStorageKey = 'pkg-manager-preference' ;
17+
18+ const setPreference = ( value : PkgManagers ) => {
19+ if ( isBrowser ) {
20+ localStorage . setItem ( pkgManagerStorageKey , value ) ;
21+ }
22+ } ;
23+
24+ export const getPkgManagerPreference = ( ) => {
25+ try {
26+ return ( localStorage . getItem ( pkgManagerStorageKey ) || 'pnpm' ) as PkgManagers ;
27+ } catch ( err ) {
28+ return 'pnpm' ;
29+ }
30+ } ;
731
832export default component$ ( ( ) => {
933 const globalStore = useContext ( GlobalStore ) ;
10- const selectedPkgManagersSig = useSignal < PkgManagers > ( 'pnpm' ) ;
11-
1234 const activeClass = `${ globalStore . theme === 'light' ? 'bg-gray-300 text-black' : 'bg-slate-800 text-white' } ` ;
1335
1436 return (
1537 < Tabs . Root
16- selectedTabId = { selectedPkgManagersSig . value }
38+ selectedTabId = { globalStore . pkgManager }
1739 onSelectedTabIdChange$ = { ( pkgManager ) => {
18- selectedPkgManagersSig . value = pkgManager as PkgManagers ;
40+ const value = pkgManager as PkgManagers ;
41+ globalStore . pkgManager = value ;
42+ setPreference ( value ) ;
1943 } }
2044 >
2145 < Tabs . List >
2246 < Tabs . Tab
2347 tabId = "pnpm"
24- class = { `px-4 pt-2 rounded-md ${ selectedPkgManagersSig . value === 'pnpm' ? `font-bold ${ activeClass } ` : '' } ` }
48+ class = { `px-4 pt-2 rounded-md ${ globalStore . pkgManager === 'pnpm' ? `font-bold ${ activeClass } ` : '' } ` }
2549 >
2650 < span class = "inline-flex items-center gap-x-2" >
2751 < PnpmIcon />
@@ -30,7 +54,7 @@ export default component$(() => {
3054 </ Tabs . Tab >
3155 < Tabs . Tab
3256 tabId = "npm"
33- class = { `px-4 pt-2 rounded-md ${ selectedPkgManagersSig . value === 'npm' ? `font-bold ${ activeClass } ` : '' } ` }
57+ class = { `px-4 pt-2 rounded-md ${ globalStore . pkgManager === 'npm' ? `font-bold ${ activeClass } ` : '' } ` }
3458 >
3559 < span class = "inline-flex items-center gap-x-2" >
3660 < NpmIcon />
@@ -39,7 +63,7 @@ export default component$(() => {
3963 </ Tabs . Tab >
4064 < Tabs . Tab
4165 tabId = "yarn"
42- class = { `px-4 pt-2 rounded-md ${ selectedPkgManagersSig . value === 'yarn' ? `font-bold ${ activeClass } ` : '' } ` }
66+ class = { `px-4 pt-2 rounded-md ${ globalStore . pkgManager === 'yarn' ? `font-bold ${ activeClass } ` : '' } ` }
4367 >
4468 < span class = "inline-flex items-center gap-x-2" >
4569 < YarnIcon />
@@ -48,7 +72,7 @@ export default component$(() => {
4872 </ Tabs . Tab >
4973 < Tabs . Tab
5074 tabId = "bun"
51- class = { `px-4 pt-2 rounded-md ${ selectedPkgManagersSig . value === 'bun' ? `font-bold ${ activeClass } ` : '' } ` }
75+ class = { `px-4 pt-2 rounded-md ${ globalStore . pkgManager === 'bun' ? `font-bold ${ activeClass } ` : '' } ` }
5276 >
5377 < span class = "inline-flex items-center gap-x-2" >
5478 < BunIcon />
0 commit comments