Skip to content

Commit

Permalink
update notifications, finish restore func
Browse files Browse the repository at this point in the history
  • Loading branch information
waffle-lord committed Jun 20, 2024
1 parent 28c6144 commit d91b147
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 21 deletions.
14 changes: 11 additions & 3 deletions noitatool/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,18 @@ func (a *App) BackupSave(name string) Result {
return NewResult(true, fmt.Sprintf("backup complete: %s", name))
}

func (a *App) RestoreSave(name string) bool {
// todo: actually restore stuff
func (a *App) RestoreSave(name string) Result {
destination := a.notia_main_save_path
source := a.backup_folder_path + "\\" + name

return true
err := cp.Copy(source, destination)

if err != nil {
println(err.Error())
return NewResult(false, fmt.Sprintf("Restore Failed: %s", err.Error()))
}

return NewResult(true, fmt.Sprintf("Restore Complete: %s", name))
}

func (a *App) DeleteSave(name string) bool {
Expand Down
8 changes: 5 additions & 3 deletions noitatool/frontend/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
let backups;
async function backup() {
const id = addNotification({type: "info", message: `Saving '${newName}' ...`});
const id = addNotification({type: "pending", message: `Saving '${newName}' ...`});
const res = await BackupSave(newName);
Expand All @@ -31,8 +31,10 @@
<NotificationsList />

<div class="inputs">
<input type="text" bind:value={newName}/>
<button class="button-main backup-button" on:click={backup}>Backup</button>
<form on:submit|preventDefault={() => {}}>
<input type="text" bind:value={newName}/>
<button class="button-main backup-button" on:click={backup}>Backup</button>
</form>
</div>

<div class="list">
Expand Down
9 changes: 4 additions & 5 deletions noitatool/frontend/src/Components/BackupInfo.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,15 @@
async function restoreSave() {
const id = addNotification({type: "info", message: `Restoring '${backup.Name}' ...`});
const restored = RestoreSave(backup.Name);
const res = await RestoreSave(backup.Name);
const type = restored ? "success" : "error";
const message = restored ? `Backup Restored '${backup.Name}'` : `Restore failed '${backup.Name}'`;
const type = res.Success ? "success" : "error";
updateNotification(id, {type: type, message: message}, true);
updateNotification(id, {type: type, message: res.Message}, true);
}
async function deleteSave() {
const id = addNotification({type: "info", message: `Deleting '${backup.Name}' ...`});
const id = addNotification({type: "pending", message: `Deleting '${backup.Name}' ...`});
const removed = await DeleteSave(backup.Name);
Expand Down
72 changes: 68 additions & 4 deletions noitatool/frontend/src/Components/Notification.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,57 @@
export let type = "error";
</script>

<article class={type} role="alert" transition:scale={{start: .8, duration: 200}}>
<article
class={type}
role="alert"
transition:scale={{ start: 0.8, duration: 200 }}
>
{#if type === "success"}
<svg width="24" height="24" fill="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 2c5.523 0 10 4.477 10 10s-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2Zm3.22 6.97-4.47 4.47-1.97-1.97a.75.75 0 0 0-1.06 1.06l2.5 2.5a.75.75 0 0 0 1.06 0l5-5a.75.75 0 1 0-1.06-1.06Z"/></svg>
<svg
width="24"
height="24"
fill="currentColor"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
><path
d="M12 2c5.523 0 10 4.477 10 10s-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2Zm3.22 6.97-4.47 4.47-1.97-1.97a.75.75 0 0 0-1.06 1.06l2.5 2.5a.75.75 0 0 0 1.06 0l5-5a.75.75 0 1 0-1.06-1.06Z"
/></svg
>
{:else if type === "error"}
<svg width="24" height="24" fill="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M10.909 2.782a2.25 2.25 0 0 1 2.975.74l.083.138 7.759 14.009a2.25 2.25 0 0 1-1.814 3.334l-.154.006H4.242A2.25 2.25 0 0 1 2.2 17.812l.072-.143L10.03 3.66a2.25 2.25 0 0 1 .879-.878ZM12 16.002a.999.999 0 1 0 0 1.997.999.999 0 0 0 0-1.997Zm-.002-8.004a1 1 0 0 0-.993.884L11 8.998 11 14l.007.117a1 1 0 0 0 1.987 0l.006-.117L13 8.998l-.007-.117a1 1 0 0 0-.994-.883Z"/></svg>
<svg
width="24"
height="24"
fill="currentColor"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
><path
d="M10.909 2.782a2.25 2.25 0 0 1 2.975.74l.083.138 7.759 14.009a2.25 2.25 0 0 1-1.814 3.334l-.154.006H4.242A2.25 2.25 0 0 1 2.2 17.812l.072-.143L10.03 3.66a2.25 2.25 0 0 1 .879-.878ZM12 16.002a.999.999 0 1 0 0 1.997.999.999 0 0 0 0-1.997Zm-.002-8.004a1 1 0 0 0-.993.884L11 8.998 11 14l.007.117a1 1 0 0 0 1.987 0l.006-.117L13 8.998l-.007-.117a1 1 0 0 0-.994-.883Z"
/></svg
>
{:else if type === "pending"}
<svg
class="spinning"
width="24"
height="24"
fill="currentColor"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
><path
d="M12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10-4.477 10-10 10Zm3.27-11.25H14a.75.75 0 0 0 0 1.5h2.75a.75.75 0 0 0 .75-.75V8.25a.75.75 0 0 0-1.5 0V9a4.991 4.991 0 0 0-4-2c-1.537 0-2.904.66-3.827 1.77a.75.75 0 0 0 1.154.96C9.963 8.963 10.907 8.5 12 8.5c1.492 0 2.767.934 3.27 2.25Zm-7.27 5V15a5.013 5.013 0 0 0 7.821.237.75.75 0 1 0-1.142-.972 3.513 3.513 0 0 1-5.842-.765H10a.75.75 0 0 0 0-1.5H7.25a.75.75 0 0 0-.75.75v3a.75.75 0 0 0 1.5 0Z"
/></svg
>
{:else}
<svg width="24" height="24" fill="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 1.999c5.524 0 10.002 4.478 10.002 10.002 0 5.523-4.478 10.001-10.002 10.001-5.524 0-10.002-4.478-10.002-10.001C1.998 6.477 6.476 1.999 12 1.999Zm-.004 8.25a1 1 0 0 0-.992.885l-.007.116.003 5.502.007.117a1 1 0 0 0 1.987-.002L13 16.75l-.003-5.501-.007-.117a1 1 0 0 0-.994-.882ZM12 6.5a1.251 1.251 0 1 0 0 2.503A1.251 1.251 0 0 0 12 6.5Z"/></svg>
<!-- info icon -->
<svg
width="24"
height="24"
fill="currentColor"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
><path
d="M12 1.999c5.524 0 10.002 4.478 10.002 10.002 0 5.523-4.478 10.001-10.002 10.001-5.524 0-10.002-4.478-10.002-10.001C1.998 6.477 6.476 1.999 12 1.999Zm-.004 8.25a1 1 0 0 0-.992.885l-.007.116.003 5.502.007.117a1 1 0 0 0 1.987-.002L13 16.75l-.003-5.501-.007-.117a1 1 0 0 0-.994-.882ZM12 6.5a1.251 1.251 0 1 0 0 2.503A1.251 1.251 0 0 0 12 6.5Z"
/></svg
>
{/if}

<div class="text">
Expand All @@ -30,6 +74,7 @@
align-items: center;
margin: 0 auto 0.5rem auto;
border-radius: 7px;
box-shadow: 4px 2px 5px black;
width: 20rem;
}
.error {
Expand All @@ -38,11 +83,30 @@
.success {
background: MediumSeaGreen;
}
.pending {
background: mediumpurple;
}
.info {
background: SkyBlue;
}
.text {
margin-left: 1rem;
user-select: none;
}
.spinning {
-webkit-animation: spin 2s linear infinite;
}
@-webkit-keyframes spin {
100% {
-webkit-transform: rotate(360deg);
}
}
@keyframes spin {
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
</style>
2 changes: 1 addition & 1 deletion noitatool/frontend/wailsjs/go/main/App.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export function DeleteSave(arg1:string):Promise<boolean>;

export function GetBackups():Promise<Array<main.BackupInfo>>;

export function RestoreSave(arg1:string):Promise<boolean>;
export function RestoreSave(arg1:string):Promise<main.Result>;
2 changes: 1 addition & 1 deletion noitatool/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21

toolchain go1.22.2

require github.com/wailsapp/wails/v2 v2.8.2
require github.com/wailsapp/wails/v2 v2.7.1

require golang.org/x/sync v0.3.0 // indirect

Expand Down
8 changes: 4 additions & 4 deletions noitatool/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ github.com/samber/lo v1.38.1 h1:j2XEAqXKb09Am4ebOg31SpvzUTTs6EN3VfgeLUhPdXM=
github.com/samber/lo v1.38.1/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/tkrajina/go-reflector v0.5.6 h1:hKQ0gyocG7vgMD2M3dRlYN6WBBOmdoOzJ6njQSepKdE=
github.com/tkrajina/go-reflector v0.5.6/go.mod h1:ECbqLgccecY5kPmPmXg1MrHW585yMcDkVl6IvJe64T4=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
Expand All @@ -65,8 +65,8 @@ github.com/wailsapp/go-webview2 v1.0.10 h1:PP5Hug6pnQEAhfRzLCoOh2jJaPdrqeRgJKZhy
github.com/wailsapp/go-webview2 v1.0.10/go.mod h1:Uk2BePfCRzttBBjFrBmqKGJd41P6QIHeV9kTgIeOZNo=
github.com/wailsapp/mimetype v1.4.1 h1:pQN9ycO7uo4vsUUuPeHEYoUkLVkaRntMnHJxVwYhwHs=
github.com/wailsapp/mimetype v1.4.1/go.mod h1:9aV5k31bBOv5z6u+QP8TltzvNGJPmNJD4XlAL3U+j3o=
github.com/wailsapp/wails/v2 v2.8.2 h1:rYOn9p+7bJiZuFSi2wDyq8rBLHrIX/FoUxov+RpdUOI=
github.com/wailsapp/wails/v2 v2.8.2/go.mod h1:5pTURIST4yZ/wRcmqDUtnM0Mk+caNax/oS610hFiy74=
github.com/wailsapp/wails/v2 v2.7.1 h1:HAzp2c5ODOzsLC6ZMDVtNOB72ozM7/SJecJPB2Ur+UU=
github.com/wailsapp/wails/v2 v2.7.1/go.mod h1:oIJVwwso5fdOgprBYWXBBqtx6PaSvxg8/KTQHNGkadc=
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc=
Expand Down

0 comments on commit d91b147

Please sign in to comment.