Skip to content

Commit bcabf69

Browse files
committed
add loading state to decoder store
1 parent 1470b37 commit bcabf69

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/features/decoder/services/decoder.store.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export type DecoderStoreState = {
4848
asymmetricPublicKeyFormat: AsymmetricKeyFormatValues;
4949
decodedHeader: string;
5050
decodedPayload: string;
51+
isLoading: boolean;
5152
signatureStatus: JwtSignatureStatusValues;
5253
controlledSymmetricSecretKey: {
5354
id: number;
@@ -70,11 +71,11 @@ type DecoderStoreActions = {
7071
handleJwtChange: (newToken: string) => void;
7172
handleSymmetricSecretKeyChange: (newSymmetricSecretKey: string) => void;
7273
handleSymmetricSecretKeyEncodingChange: (
73-
newSymmetricSecretKey: EncodingValues,
74+
newSymmetricSecretKey: EncodingValues
7475
) => void;
7576
handleAsymmetricPublicKeyChange: (newAsymmetricPublicKey: string) => void;
7677
handleAsymmetricPublicKeyFormatChange: (
77-
newFormat: AsymmetricKeyFormatValues,
78+
newFormat: AsymmetricKeyFormatValues
7879
) => void;
7980
resetControlledSymmetricSecretKey: () => void;
8081
resetControlledAsymmetricPublicKey: () => void;
@@ -92,6 +93,7 @@ export const initialState: DecoderStoreState = {
9293
asymmetricPublicKeyFormat: AsymmetricKeyFormatValues.PEM,
9394
decodedHeader: DEFAULT_DECODED_HEADER,
9495
decodedPayload: DEFAULT_DECODED_PAYLOAD,
96+
isLoading: false,
9597
signatureStatus: JwtSignatureStatusValues.VALID,
9698
signatureWarnings: null,
9799
decodingErrors: null,
@@ -120,6 +122,12 @@ export const useDecoderStore = create<DecoderStore>()(
120122
asymmetricPublicKeyFormat,
121123
} = get();
122124

125+
set({
126+
isLoading: true,
127+
decodedHeader: "",
128+
decodedPayload: "",
129+
});
130+
123131
const update = await TokenDecoderService.handleJwtChange({
124132
alg,
125133
symmetricSecretKey,
@@ -129,7 +137,10 @@ export const useDecoderStore = create<DecoderStore>()(
129137
newToken,
130138
});
131139

132-
set(update);
140+
set({
141+
...update,
142+
isLoading: false,
143+
});
133144
},
134145
handleSymmetricSecretKeyChange: async (newSymmetricSecretKey) => {
135146
const { jwt, symmetricSecretKeyEncoding } = get();
@@ -208,5 +219,5 @@ export const useDecoderStore = create<DecoderStore>()(
208219

209220
set(update);
210221
},
211-
})),
222+
}))
212223
);

0 commit comments

Comments
 (0)