Skip to content

Commit 81ff42c

Browse files
fix: use runtime API endpoint for user profile (#303)
Select the active endpoint from MajEnv.ApiEndpoints and let UserInfoDisplayer own its visibility state.
1 parent f500ad7 commit 81ff42c

2 files changed

Lines changed: 14 additions & 17 deletions

File tree

Assets/Scripts/Scenes/List/ListManager.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,10 @@ void Start()
162162
void DisplayUserInfo()
163163
{
164164
//TODO: display multiple endpoints
165-
var apiendpoint = MajEnv.Settings.Online.ApiEndpoints.FirstOrDefault();
166-
if (apiendpoint is not null)
167-
{
168-
_userProfileDisplayer.DisplayUserInfo(apiendpoint);
169-
}
170-
else
171-
{
172-
_userProfileDisplayer.gameObject.SetActive(false);
173-
}
165+
var apiEndpoint = MajEnv.ApiEndpoints.FirstOrDefault(x => x.RuntimeConfig.IsLoggedIn)
166+
?? MajEnv.ApiEndpoints.FirstOrDefault();
167+
168+
_userProfileDisplayer.DisplayUserInfo(apiEndpoint);
174169
}
175170

176171
async UniTaskVoid InitializeCoverListAsync()

Assets/Scripts/Scenes/List/UserInfoDisplayer.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,22 @@ void Update()
4040
Refresh();
4141
}
4242

43-
public void DisplayUserInfo(ApiEndpoint apiEndpoint)
43+
public void DisplayUserInfo(ApiEndpoint? apiEndpoint)
4444
{
4545
_currentApiEndpoint = apiEndpoint;
46+
gameObject.SetActive(apiEndpoint is not null);
47+
48+
if (apiEndpoint is not null)
49+
{
50+
Refresh();
51+
}
4652
}
4753

4854
public void DisplayFromSong(ISongDetail song)
4955
{
50-
if (song is not OnlineSongDetail)
51-
{
52-
gameObject.SetActive(false);
53-
return;
54-
}
55-
var serverInfo = ((OnlineSongDetail)song).ServerInfo;
56-
DisplayUserInfo(serverInfo);
56+
DisplayUserInfo(song is OnlineSongDetail onlineSong
57+
? onlineSong.ServerInfo
58+
: null);
5759
}
5860

5961
void Refresh()

0 commit comments

Comments
 (0)