Skip to content
This repository has been archived by the owner on Oct 19, 2022. It is now read-only.

Commit

Permalink
Edit page improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Aug 10, 2022
1 parent a6fe59e commit 2135fe0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
4 changes: 2 additions & 2 deletions interface/windows/edit/edit.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<h3>You can revert the current changes you made.</h3>
</div>
<div class="ml-10 flex gap-3">
<button class="button">
<button class="button" on:click={revertChanges}>
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path d="M20 11a8.1 8.1 0 0 0 -15.5 -2m-.5 -4v4h4" />
Expand Down Expand Up @@ -81,5 +81,5 @@
</div>

<script lang="ts">
import { deleteCodes, loadSavedCodes, saveChanges } from "./index"
import { deleteCodes, loadSavedCodes, revertChanges, saveChanges } from "./index"
</script>
32 changes: 29 additions & 3 deletions interface/windows/edit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ export const loadSavedCodes = async () => {
}

export const saveChanges = async () => {
const confirm = await dialog.ask("Are you sure you want to save the changes? \n\nThis will overwrite your saved codes!", { type: "warning" })

if (confirm === false) {
return
}

const settings = getSettings()

let saveText = ""
Expand All @@ -119,13 +125,25 @@ export const saveChanges = async () => {
const filePath = await path.join(await path.configDir(), "Levminer", "Authme 4", "codes", "codes.authme")

await fs.writeTextFile(filePath, JSON.stringify(fileContents, null, "\t"))

navigate("codes")
}

export const revertChanges = async () => {
const confirm = await dialog.ask("Are you sure you want to revert all changes? \n\nYou will lose all current changes!", { type: "warning" })

if (confirm === false) {
return
}

location.reload()
}

/**
* Delete all imported codes
*/
export const deleteCodes = async () => {
const confirm0 = await dialog.ask("Are you sure you want to delete all codes? \n\nYou can not revert this.", { type: "warning" })
const confirm0 = await dialog.ask("Are you sure you want to delete all codes? \n\nYou can not revert this!", { type: "warning" })

if (confirm0 === false) {
return
Expand All @@ -137,7 +155,7 @@ export const deleteCodes = async () => {
const filePath = await path.join(await path.configDir(), "Levminer", "Authme 4", "codes", "codes.authme")
await fs.removeFile(filePath)

navigate("/")
navigate("codes")
}
}

Expand All @@ -152,20 +170,28 @@ export const editCode = (id: number) => {
if (issuer.readOnly === true) {
issuer.readOnly = false
name.readOnly = false

issuer.style.color = "#28A443"
name.style.color = "#28A443"
} else {
issuer.readOnly = true
name.readOnly = true

issuer.style.color = "white"
name.style.color = "white"

const newIssuer = document.querySelector(`#issuer${id}`).value
const newName = document.querySelector(`#name${id}`).value

issuers[id] = newIssuer
names[id] = newName

dialog.message("Code edited. \n\nYou can save or revert this change at the top of the page.")
}
}

export const deleteCode = async (id: number) => {
const res = await dialog.ask("Are you sure?")
const res = await dialog.ask("Are you sure you want to delete this code? \n\nYou can save or revert this change at the top of the page.", { type: "warning" })

if (res === true) {
names.splice(id, 1)
Expand Down

0 comments on commit 2135fe0

Please sign in to comment.