Skip to content

Commit

Permalink
fix: Add "Theme Already Exists" warnings for presets and templates
Browse files Browse the repository at this point in the history
  • Loading branch information
beebls committed Jun 27, 2023
1 parent 67b11d2 commit 7863427
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 11 deletions.
7 changes: 7 additions & 0 deletions backend/tauriMethods/checkIfThemeExists.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { exists, BaseDirectory } from "@tauri-apps/api/fs";

export async function checkIfThemeExists(themeName: string): Promise<boolean> {
return await exists(`homebrew/themes/${themeName}`, {
dir: BaseDirectory.Home,
});
}
1 change: 1 addition & 0 deletions backend/tauriMethods/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export * from "./checkIfStandaloneBackendExists";
export * from "./copyBackend";
export * from "./getOS";
export * from "./downloadTemplate";
export * from "./checkIfThemeExists";
11 changes: 9 additions & 2 deletions components/CreatePresetModal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useContext, useMemo, useState } from "react";
import { themeContext } from "@contexts/themeContext";
import { generatePreset } from "../backend";
import { checkIfThemeExists, generatePreset, toast } from "../backend";
import { BiPlus } from "react-icons/bi";
import { LabelledInput, Modal } from "./Primitives";
import { twMerge } from "tailwind-merge";
Expand All @@ -12,9 +12,16 @@ export function CreatePresetModal() {
[localThemeList]
);
const [presetName, setPresetName] = useState<string>("");
function createPreset() {
async function createPreset() {
if (presetName) {
const alreadyExists = await checkIfThemeExists(presetName);
if (alreadyExists) {
toast("Theme Already Exists!");
setPresetName("");
return;
}
generatePreset(presetName).then(() => {
toast("Preset Created Successfully");
refreshThemes(true);
setPresetName("");
});
Expand Down
20 changes: 13 additions & 7 deletions components/Settings/CreateTemplateTheme.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { useMemo, useState, useContext } from "react";
import { LabelledInput, Modal } from "..";
import { downloadTemplate, toast } from "backend";
import { checkIfThemeExists, downloadTemplate, toast } from "backend";
import { ImSpinner5 } from "react-icons/im";
import { themeContext } from "@contexts/themeContext";
import { exists, BaseDirectory } from "@tauri-apps/api/fs";

export function CreateTemplateTheme({ ongoingAction }: { ongoingAction: boolean }) {
const { refreshThemes } = useContext(themeContext);
Expand All @@ -29,14 +30,19 @@ export function CreateTemplateTheme({ ongoingAction }: { ongoingAction: boolean
}
actionDisabled={name.length === 0 || nameContainsInvalidCharacters || invalidName}
actionText="Create"
onAction={() =>
onAction={async () => {
const alreadyExists = await checkIfThemeExists(name);
if (alreadyExists) {
toast("Theme Already Exists!");
setName("");
return;
}
downloadTemplate(name).then((success) => {
if (!success) {
toast("Error Creating Template");
}
toast(success ? "Template Created Successfully" : "Error Creating Template");
refreshThemes(true);
})
}
setName("");
});
}}
title="Create Template Theme"
description={`This will create a blank theme in your themes folder that you can use as the starting point for your own theme.`}
triggerDisabled={ongoingAction}
Expand Down
4 changes: 2 additions & 2 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"$CONFIG\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\*",
"$APPDATA/standaloneVersion.txt",
"$APPDATA",
"$HOME/homebrew/themes"
"$HOME/homebrew/themes/*"
],
"writeFile": true
},
Expand Down Expand Up @@ -183,7 +183,7 @@
"resizable": true,
"title": "CSSLoader Desktop",
"decorations": false,
"transparent": true,
"transparent": true,
"width": 800,
"minWidth": 460,
"minHeight": 300
Expand Down

0 comments on commit 7863427

Please sign in to comment.