1- import Page from "./page" ;
1+ import { PageWithUrlParams } from "./page" ;
22import * as Skeleton from "../utils/skeleton" ;
33import { getAuthenticatedUser , isAuthenticated } from "../firebase" ;
44import * as ActivePage from "../states/active-page" ;
@@ -9,15 +9,19 @@ import * as StreakHourOffsetModal from "../modals/streak-hour-offset";
99import * as Loader from "../elements/loader" ;
1010import * as ApeKeyTable from "../elements/account-settings/ape-key-table" ;
1111import * as Notifications from "../elements/notifications" ;
12+ import { z } from "zod" ;
1213
1314const pageElement = $ ( ".page.pageAccountSettings" ) ;
1415
15- type State = {
16- activeTab : "authentication" | "general" | "api" | "dangerZone" ;
17- } ;
16+ const StateSchema = z . object ( {
17+ tab : z . enum ( [ "authentication" , "account" , "apeKeys" , "dangerZone" ] ) ,
18+ } ) ;
19+ type State = z . infer < typeof StateSchema > ;
20+
21+ const UrlParameterSchema = StateSchema . partial ( ) ;
1822
1923const state : State = {
20- activeTab : "general " ,
24+ tab : "account " ,
2125} ;
2226
2327function updateAuthenticationSections ( ) : void {
@@ -122,20 +126,18 @@ function updateIntegrationSections(): void {
122126function updateTabs ( ) : void {
123127 void swapElements (
124128 pageElement . find ( ".tab.active" ) ,
125- pageElement . find ( `.tab[data-tab="${ state . activeTab } "]` ) ,
129+ pageElement . find ( `.tab[data-tab="${ state . tab } "]` ) ,
126130 250 ,
127131 async ( ) => {
128132 //
129133 } ,
130134 async ( ) => {
131135 pageElement . find ( ".tab" ) . removeClass ( "active" ) ;
132- pageElement
133- . find ( `.tab[data-tab="${ state . activeTab } "]` )
134- . addClass ( "active" ) ;
136+ pageElement . find ( `.tab[data-tab="${ state . tab } "]` ) . addClass ( "active" ) ;
135137 }
136138 ) ;
137139 pageElement . find ( "button" ) . removeClass ( "active" ) ;
138- pageElement . find ( `button[data-tab="${ state . activeTab } "]` ) . addClass ( "active" ) ;
140+ pageElement . find ( `button[data-tab="${ state . tab } "]` ) . addClass ( "active" ) ;
139141}
140142
141143function updateAccountSections ( ) : void {
@@ -180,11 +182,13 @@ export function updateUI(): void {
180182 updateAccountSections ( ) ;
181183 void ApeKeyTable . update ( updateUI ) ;
182184 updateTabs ( ) ;
185+ page . setUrlParams ( state ) ;
183186}
184187
185188$ ( ".page.pageAccountSettings" ) . on ( "click" , ".tabs button" , ( event ) => {
186- state . activeTab = $ ( event . target ) . data ( "tab" ) as State [ "activeTab " ] ;
189+ state . tab = $ ( event . target ) . data ( "tab" ) as State [ "tab " ] ;
187190 updateTabs ( ) ;
191+ page . setUrlParams ( state ) ;
188192} ) ;
189193
190194$ (
@@ -207,16 +211,21 @@ $(".page.pageAccountSettings #setStreakHourOffset").on("click", () => {
207211 StreakHourOffsetModal . show ( ) ;
208212} ) ;
209213
210- export const page = new Page ( {
214+ export const page = new PageWithUrlParams ( {
211215 id : "accountSettings" ,
212216 display : "Account Settings" ,
213217 element : pageElement ,
214218 path : "/account-settings" ,
219+ urlParamsSchema : UrlParameterSchema ,
215220 afterHide : async ( ) : Promise < void > => {
216221 Skeleton . remove ( "pageAccountSettings" ) ;
217222 } ,
218- beforeShow : async ( ) : Promise < void > => {
223+ beforeShow : async ( options ) : Promise < void > => {
224+ if ( options . urlParams ?. tab !== undefined ) {
225+ state . tab = options . urlParams . tab ;
226+ }
219227 Skeleton . append ( "pageAccountSettings" , "main" ) ;
228+ pageElement . find ( `.tab[data-tab="${ state . tab } "]` ) . addClass ( "active" ) ;
220229 updateUI ( ) ;
221230 } ,
222231} ) ;
0 commit comments