mirror of
https://github.com/kmc7468/arkvault.git
synced 2026-02-04 16:16:55 +00:00
사소한 리팩토링 3
This commit is contained in:
40
src/lib/utils/gotoStateful.ts
Normal file
40
src/lib/utils/gotoStateful.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { goto } from "$app/navigation";
|
||||
|
||||
type Path = "/key/export";
|
||||
|
||||
interface KeyExportState {
|
||||
redirectPath: string;
|
||||
|
||||
encryptKeyBase64: string;
|
||||
decryptKeyBase64: string;
|
||||
signKeyBase64: string;
|
||||
verifyKeyBase64: string;
|
||||
|
||||
masterKeyWrapped: string;
|
||||
hmacSecretWrapped: string;
|
||||
}
|
||||
|
||||
const useAutoNull = <T>(value: T | null) => {
|
||||
return {
|
||||
get: () => {
|
||||
const result = value;
|
||||
value = null;
|
||||
return result;
|
||||
},
|
||||
set: (newValue: T) => {
|
||||
value = newValue;
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export const keyExportState = useAutoNull<KeyExportState>(null);
|
||||
|
||||
export function gotoStateful(path: "/key/export", state: KeyExportState): Promise<void>;
|
||||
|
||||
export function gotoStateful(path: Path, state: unknown) {
|
||||
switch (path) {
|
||||
case "/key/export":
|
||||
keyExportState.set(state as KeyExportState);
|
||||
return goto(path);
|
||||
}
|
||||
}
|
||||
1
src/lib/utils/index.ts
Normal file
1
src/lib/utils/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./gotoStateful";
|
||||
Reference in New Issue
Block a user