Skip to content

Commit

Permalink
Manual GDrive save
Browse files Browse the repository at this point in the history
  • Loading branch information
WilStead committed Apr 10, 2024
1 parent 35fdb17 commit e16ae02
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
17 changes: 15 additions & 2 deletions src/Pages/ManageData.razor
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,23 @@ else
}
</div>
<div class="footer">
@if (DataService.GDriveSync) {
@if (DataService.GDriveSync)
{
<button class="btn danger ms-auto" @onclick="OnUnlinkGDrive">Sign out</button>
if (!SignInFailure
&& DataService.GDriveSync
&& DataService.LastGDriveSync == DateTime.MinValue
&& (DataService.Data.Ethnicities?.Count > 0
|| DataService.Data.Genres?.Count > 0
|| DataService.Data.Plots?.Count > 0
|| DataService.Data.Stories.Count > 0
|| DataService.Data.Traits?.Count > 0))
{
<button class="btn primary ms-1" @onclick="OnSaveGDriveAsync">Save</button>
}
}
else {
else
{
<button class="btn primary ms-auto" @onclick="OnLinkGDrive">Save</button>
}
</div>
Expand Down
2 changes: 2 additions & 0 deletions src/Pages/ManageData.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ private async Task OnLinkGDrive()
}
}

private async Task OnSaveGDriveAsync() => await DataService.SaveGDriveAsync();

private async Task OnSyncLocalAsync() => await DataService.SaveLocalAsync();

private async Task OnUnlinkGDrive()
Expand Down
27 changes: 16 additions & 11 deletions src/Services/DataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,22 @@ public async Task SaveAsync()
}
}

public async Task SaveGDriveAsync()
{
if (!GDriveSync)
{
return;
}

var serializedData = JsonSerializer.Serialize(
Data,
ScopSerializerOptions.Instance);

await jsInterop.SaveDriveData(serializedData);

LastGDriveSync = Data.LastSync;
}

public async Task SaveLocalAsync()
{
if (!(Data.Ethnicities?.Count > 0
Expand Down Expand Up @@ -799,17 +815,6 @@ private async Task LoadInitialDataAsync()
Traits = await GetDefaultTraitsAsync();
}

private async Task SaveGDriveAsync()
{
var serializedData = JsonSerializer.Serialize(
Data,
ScopSerializerOptions.Instance);

await jsInterop.SaveDriveData(serializedData);

LastGDriveSync = Data.LastSync;
}

private void UpdateData()
{
if (Data.Ethnicities?.Count > 0)
Expand Down

0 comments on commit e16ae02

Please sign in to comment.