Skip to content

Commit

Permalink
com.rest.blockadelabs 1.0.3 (#10)
Browse files Browse the repository at this point in the history
- cleaned up history fetching a bit and pagination of history item list
  • Loading branch information
StephenHodgson committed Jul 24, 2023
1 parent 9341027 commit aa2142f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEditor.VersionControl;
using UnityEngine;
using Utilities.Async;
using Utilities.WebRequestRest;
Expand Down Expand Up @@ -83,18 +82,26 @@ private static GUIStyle BoldCenteredHeaderStyle

private static string editorDownloadDirectory = string.Empty;

private static bool hasFetchedSkyboxStyles;
private static bool isGeneratingSkybox;

private static IReadOnlyList<SkyboxStyle> skyboxStyles = new List<SkyboxStyle>();

private static GUIContent[] skyboxOptions = Array.Empty<GUIContent>();

private static SkyboxStyle currentSkyboxStyleSelection;

private static bool isFetchingSkyboxStyles;
private static bool hasFetchedSkyboxStyles;

private static bool hasFetchedHistory;
private static bool isFetchingSkyboxHistory;

private static SkyboxHistory history;

private static int page;

private static int limit = 100;

#endregion static content

[SerializeField]
Expand Down Expand Up @@ -286,8 +293,6 @@ private void SkyboxGeneration()
EditorGUILayout.EndHorizontal();
}

private static bool isFetchingSkyboxStyles;

private static async void FetchSkyboxStyles()
{
if (isFetchingSkyboxStyles) { return; }
Expand All @@ -308,8 +313,6 @@ private static async void FetchSkyboxStyles()
}
}

private static bool isGeneratingSkybox;

private async void GenerateSkybox()
{
if (isGeneratingSkybox) { return; }
Expand Down Expand Up @@ -360,7 +363,7 @@ private async void GenerateSkybox()
}
}

private static ConcurrentDictionary<int, SkyboxInfo> loadingSkyboxes = new ConcurrentDictionary<int, SkyboxInfo>();
private static readonly ConcurrentDictionary<int, SkyboxInfo> loadingSkyboxes = new ConcurrentDictionary<int, SkyboxInfo>();

private static async void SaveSkyboxAsset(SkyboxInfo skyboxInfo)
{
Expand Down Expand Up @@ -465,21 +468,36 @@ private void RenderHistory()
{ //Header
EditorGUILayout.LabelField("History", EditorStyles.boldLabel, wideColumnWidthOption);

//if (history != null && GUILayout.Button("Prev Page"))
//{
// page--;
//}
GUI.enabled = !isFetchingSkyboxHistory;
if (history != null && page > 0 && GUILayout.Button("Prev Page"))
{
page--;
EditorApplication.delayCall += FetchSkyboxHistory;
}

//if (history is { HasMore: true } && GUILayout.Button("Next Page"))
//{
// page++;
//}
if (history is { HasMore: true } && GUILayout.Button("Next Page"))
{
page++;
EditorApplication.delayCall += FetchSkyboxHistory;
}

EditorGUI.BeginChangeCheck();
limit = EditorGUILayout.IntField("page items", limit);

GUILayout.FlexibleSpace();
if (EditorGUI.EndChangeCheck())
{
if (limit > 100)
{
limit = 100;
}

GUI.enabled = !isFetchingSkyboxHistory;
if (limit < 1)
{
limit = 1;
}
}

GUILayout.FlexibleSpace();

if (GUILayout.Button(refreshContent, defaultColumnWidthOption))
{
Expand Down Expand Up @@ -558,20 +576,15 @@ private void RenderHistory()
EditorGUILayout.Space();
}

private static bool isFetchingSkyboxHistory;

// private static int page;

private static int limit = 9999;

private static async void FetchSkyboxHistory()
{
if (isFetchingSkyboxHistory) { return; }
isFetchingSkyboxHistory = true;

try
{
history = await api.SkyboxEndpoint.GetSkyboxHistoryAsync(new SkyboxHistoryParameters { Limit = limit });
history = await api.SkyboxEndpoint.GetSkyboxHistoryAsync(new SkyboxHistoryParameters { Limit = limit, Offset = page });
//Debug.Log($"history item count: {history.TotalCount} | hasMore? {history.HasMore}");
}
catch (Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,18 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten

// dropdown
var index = -1;
dynamic currentVoiceOption = null;
dynamic currentOption = null;

if (id.intValue > 0)
{
currentVoiceOption = styles?.FirstOrDefault(style => style.Id.ToString() == id.intValue.ToString());
currentOption = styles?.FirstOrDefault(style => style.Id.ToString() == id.intValue.ToString());
}

if (currentVoiceOption != null)
if (currentOption != null)
{
for (var i = 0; i < options.Length; i++)
{
if (options[i].tooltip.Contains(currentVoiceOption.Id.ToString()))
if (options[i].tooltip.Contains(currentOption.Id.ToString()))
{
index = i;
break;
Expand All @@ -83,9 +83,9 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten

if (EditorGUI.EndChangeCheck())
{
currentVoiceOption = styles?.FirstOrDefault(style => options[index].text.Contains(style.Name));
id.intValue = currentVoiceOption!.Id;
name.stringValue = currentVoiceOption!.Name;
currentOption = styles?.FirstOrDefault(style => options[index].text.Contains(style.Name));
id.intValue = currentOption!.Id;
name.stringValue = currentOption!.Name;
}
}

Expand Down
2 changes: 1 addition & 1 deletion BlockadeLabs/Packages/com.rest.blockadelabs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "BlockadeLabs",
"description": "A Non-Official Blockade Labs Rest Client for Unity (UPM)",
"keywords": [],
"version": "1.0.2",
"version": "1.0.3",
"unity": "2021.3",
"documentationUrl": "https://github.com/RageAgainstThePixel/com.rest.blockadelabs#documentation",
"changelogUrl": "https://github.com/RageAgainstThePixel/com.rest.blockadelabs/releases",
Expand Down

0 comments on commit aa2142f

Please sign in to comment.