Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace JSON.parse with parseJsonWithSchema #5881

Open
fehmer opened this issue Sep 13, 2024 · 8 comments
Open

Replace JSON.parse with parseJsonWithSchema #5881

fehmer opened this issue Sep 13, 2024 · 8 comments
Assignees
Labels
help wanted Extra attention is needed improvement Change or improvement

Comments

@fehmer
Copy link
Member

fehmer commented Sep 13, 2024

Replace JSON.parse with Misc.parseJsonWithSchema for type safety.

Example:

const customThemeUrlDataSchema = z.object({
c: CustomThemeColorsSchema,
i: z.string().optional(),
s: CustomBackgroundSizeSchema.optional(),
f: CustomBackgroundFilterSchema.optional(),
});
export function loadCustomThemeFromUrl(getOverride?: string): void {
const getValue = Misc.findGetParameter("customTheme", getOverride);
if (getValue === null) return;
let decoded: z.infer<typeof customThemeUrlDataSchema>;
try {
decoded = Misc.parseJsonWithSchema(
atob(getValue),
customThemeUrlDataSchema
);
} catch (e) {
console.log("Custom theme URL decoding failed", e);
Notifications.add(
"Failed to load theme from URL: " + (e as Error).message,
0
);
return;
}

@fehmer fehmer added bug Something isn't working improvement Change or improvement help wanted Extra attention is needed frontend User interface or web stuff and removed bug Something isn't working labels Sep 13, 2024
@Miodec
Copy link
Member

Miodec commented Sep 14, 2024

I think before we do this we should extract common util functions (like this one) to a package.

@rajneesh-18
Copy link

It should be go on the discussion.

@dev-mohit06
Copy link

Hi @fehmer, Could you assign me that issue.

@fehmer
Copy link
Member Author

fehmer commented Jan 22, 2025

@dev-mohit06 I'd say just work on it and create a PR

@dev-mohit06
Copy link

Hey @fehmer, I’d prefer to avoid duplication of effort, so could you assign this issue to me if possible?

@dev-mohit06
Copy link

@fehmer - Could you please indicate which files in the frontend need JSON.parse replacements? This will help ensure I cover all necessary changes.

@fehmer fehmer removed the frontend User interface or web stuff label Jan 22, 2025
@dev-mohit06
Copy link

@fehmer thanks for helping me out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed improvement Change or improvement
Projects
None yet
Development

No branches or pull requests

4 participants