Usman
Usman
Explore posts from servers
CC#
Created by Usman on 5/17/2024 in #help
Mutation IsLoading remains true in (Phetch library)
// Api.cs

public class Api
{
public Api()
{
LoginUserEndpoint = new Endpoint<Login.LoginFormModel, dynamic>(LoginUser, defaultOptions);
}

public Endpoint<Login.LoginFormModel, dynamic> LoginUserEndpoint { get; }

private async Task<dynamic> LoginUser(Login.LoginFormModel loginFormModel, CancellationToken cancellationToken)
{
var apiPath = $"{ApiBaseUrl}/{ApiEndpoint.Login.GetEnumMemberValue()}";
var response = await _httpClient.PostAsJsonAsync(apiPath, loginFormModel, cancellationToken);
if (response is null) throw new JsonException("API response was null");
return response;
}
}

// Login.razor
@code {

public readonly LoginFormModel LoginForm = new("", "");

private Query<LoginFormModel, dynamic>? _loginUserMutation;

protected override void OnInitialized()
{
_loginUserMutation = Api.LoginUserEndpoint.Use();
}

public class LoginFormModel(string username, string password)
{
[Required(ErrorMessage = "Username is required")]
public string Username { get; set; } = username;

[Required(ErrorMessage = "Password is required")]
public string Password { get; set; } = password;
}

private void HandleSubmit()
{
if (_loginUserMutation is null) return;
_loginUserMutation.Trigger(LoginForm);
Console.WriteLine(JsonConvert.SerializeObject(_loginUserMutation.Data, Formatting.Indented));
}

}

<button type="submit" disabled="@_loginUserMutation.IsLoading" class="w-full py-3 px-4 inline-flex justify-center items-center gap-x-2 text-sm font-semibold rounded-lg border border-transparent bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-50 disabled:pointer-events-none">
@(_loginUserMutation.IsLoading ? "Logging in..." : "Log in")
</button>
// Api.cs

public class Api
{
public Api()
{
LoginUserEndpoint = new Endpoint<Login.LoginFormModel, dynamic>(LoginUser, defaultOptions);
}

public Endpoint<Login.LoginFormModel, dynamic> LoginUserEndpoint { get; }

private async Task<dynamic> LoginUser(Login.LoginFormModel loginFormModel, CancellationToken cancellationToken)
{
var apiPath = $"{ApiBaseUrl}/{ApiEndpoint.Login.GetEnumMemberValue()}";
var response = await _httpClient.PostAsJsonAsync(apiPath, loginFormModel, cancellationToken);
if (response is null) throw new JsonException("API response was null");
return response;
}
}

// Login.razor
@code {

public readonly LoginFormModel LoginForm = new("", "");

private Query<LoginFormModel, dynamic>? _loginUserMutation;

protected override void OnInitialized()
{
_loginUserMutation = Api.LoginUserEndpoint.Use();
}

public class LoginFormModel(string username, string password)
{
[Required(ErrorMessage = "Username is required")]
public string Username { get; set; } = username;

[Required(ErrorMessage = "Password is required")]
public string Password { get; set; } = password;
}

private void HandleSubmit()
{
if (_loginUserMutation is null) return;
_loginUserMutation.Trigger(LoginForm);
Console.WriteLine(JsonConvert.SerializeObject(_loginUserMutation.Data, Formatting.Indented));
}

}

<button type="submit" disabled="@_loginUserMutation.IsLoading" class="w-full py-3 px-4 inline-flex justify-center items-center gap-x-2 text-sm font-semibold rounded-lg border border-transparent bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-50 disabled:pointer-events-none">
@(_loginUserMutation.IsLoading ? "Logging in..." : "Log in")
</button>
2 replies
DTDrizzle Team
Created by Usman on 12/23/2023 in #help
Multiple records with same columns and values - using joins
I am using innerJoins and this is the result I get. Sorry for the bad formatting. But except the fieldd (which is different in all results) I get everything else the same
[
{
id: "abcd",
// same fields
fieldd: {
"id": 4315,
"module_d_id": 8969,
"field_t_id": 28,
"field_value": "9"
}
},
{
id: "abcd",
// same fields
fieldd: {
"id": 4316,
"module_d_id": 8969,
"field_t_id": 29,
"field_value": "75"
}
},
{
id: "abcd",
// same fields
fieldd: {
"id": 4317,
"module_d_id": 8969,
"field_t_id": 30,
"field_value": "Roof Repair Needed"
}
}
]
[
{
id: "abcd",
// same fields
fieldd: {
"id": 4315,
"module_d_id": 8969,
"field_t_id": 28,
"field_value": "9"
}
},
{
id: "abcd",
// same fields
fieldd: {
"id": 4316,
"module_d_id": 8969,
"field_t_id": 29,
"field_value": "75"
}
},
{
id: "abcd",
// same fields
fieldd: {
"id": 4317,
"module_d_id": 8969,
"field_t_id": 30,
"field_value": "Roof Repair Needed"
}
}
]
3 replies
CC#
Created by Usman on 10/31/2022 in #help
How to pass custom arguments to MAUI button click
7 replies