fix conflicts

pull/55/head
Maxime BATISTA 2 years ago
commit 3b9d9f197a

@ -2,3 +2,6 @@
# CS0618: Le type ou le membre est obsolète
dotnet_diagnostic.CS0618.severity = silent
# CS1998: Async method lacks 'await' operators and will run synchronously
dotnet_diagnostic.CS1998.severity = none

@ -24,14 +24,14 @@ namespace ShoopNCook.Controllers
app.ForceLogin();
}
public void GoToMyRecipesPage()
public async void GoToMyRecipesPage()
{
Shell.Current.Navigation.PushAsync(new MyRecipesPage(account, endpoint.RecipesService));
await Shell.Current.Navigation.PushAsync(new MyRecipesPage(account, endpoint.RecipesService));
}
public void GoToProfilePage()
public async void GoToProfilePage()
{
Shell.Current.Navigation.PushAsync(new ProfilePage(account));
await Shell.Current.Navigation.PushAsync(new ProfilePage(account));
}
}
}

@ -5,6 +5,8 @@ using System.Collections.Immutable;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
namespace LocalEndpoint.Data
@ -62,9 +64,11 @@ namespace LocalEndpoint.Data
Save(ACCOUNTS_FILENAME, ACCOUNTS_SERIALIZER, accountsData);
}
public Recipe GetRecipe(Guid id)
public Recipe? GetRecipe(Guid id)
{
return ConvertRecipeDataToRecipe(recipesData[id]);
if (recipesData.TryGetValue(id, out RecipeData? data))
return ConvertRecipeDataToRecipe(data);
return null;
}
public RecipeRate GetRecipeRate(Guid user, Guid recipe)
@ -72,38 +76,38 @@ namespace LocalEndpoint.Data
return usersData[user].Rates[recipe];
}
public void InsertInUserList(Guid userId, Guid recipeId, uint persAmount)
public async void InsertInUserList(Guid userId, Guid recipeId, uint persAmount)
{
usersData[userId].RecipesList[recipeId] = persAmount;
Save(USERS_FILENAME, USERS_SERIALIZER, usersData);
}
public void RemoveFromUserList(Guid userId, Guid recipeId)
public async void RemoveFromUserList(Guid userId, Guid recipeId)
{
usersData[userId].RecipesList.Remove(recipeId);
Save(USERS_FILENAME, USERS_SERIALIZER, usersData);
}
public void InsertRecipe(Recipe recipe)
public async void InsertRecipe(Recipe recipe)
{
recipesData[recipe.Info.Id] = new RecipeData(recipe.Info, recipe.Owner.Id, recipe.Ingredients, recipe.Steps);
Save(RECIPES_FILENAME, RECIPES_SERIALIZER, recipesData);
}
public void InsertUser(User user)
public async void InsertUser(User user)
{
usersData[user.Id] = new UserData(user, new Dictionary<Guid, RecipeRate>(), new Dictionary<Guid, uint>());
Save(USERS_FILENAME, USERS_SERIALIZER, usersData);
}
public void InsertRate(Guid userId, Guid recipeId, RecipeRate rate)
public async void InsertRate(Guid userId, Guid recipeId, RecipeRate rate)
{
usersData[userId].Rates[recipeId] = rate;
Save(USERS_FILENAME, USERS_SERIALIZER, usersData);
}
public void RemoveRecipe(Guid id)
public async void RemoveRecipe(Guid id)
{
recipesData.Remove(id);
Save(RECIPES_FILENAME, RECIPES_SERIALIZER, recipesData);
@ -141,19 +145,16 @@ namespace LocalEndpoint.Data
if (fileInfo.Length == 0)
return new Dictionary<K, V>(); //file is empty thus there is nothing to deserialize
Console.WriteLine(File.ReadAllText(file));
using (var stream = File.OpenRead(file))
return deserializer.ReadObject(stream) as Dictionary<K, V> ?? throw new Exception("object read from " + file + " is not a dictionnary");
string text = File.ReadAllText(file);
return JsonSerializer.Deserialize<Dictionary<K, V>>(text);
}
private void Save<K, T>(string fileName, DataContractSerializer serializer, Dictionary<K, T> dict)
private async void Save<K, T>(string fileName, DataContractSerializer serializer, Dictionary<K, T> dict)
{
using (var stream = File.OpenWrite(dbPath + "/" + fileName))
{
serializer.WriteObject(stream, dict);
stream.Flush();
}
string json = JsonSerializer.Serialize(dict);
File.WriteAllText(dbPath + "/" + fileName, json);
}
}

@ -9,7 +9,7 @@ namespace LocalEndpoint.Data
public interface Database
{
public Recipe GetRecipe(Guid id);
public Recipe? GetRecipe(Guid id);
public RecipeRate GetRecipeRate(Guid user, Guid recipe);

@ -21,7 +21,7 @@ namespace LocalEndpoint
return db.ListAllRecipes().Take(4).ToImmutableList().ConvertAll(v => v.Info);
}
public Recipe GetRecipe(RecipeInfo info)
public Recipe? GetRecipe(RecipeInfo info)
{
return db.GetRecipe(info.Id);
}

@ -8,7 +8,7 @@ namespace Endpoint
{
public ImmutableList<RecipeInfo> PopularRecipes();
public Recipe GetRecipe(RecipeInfo info);
public Recipe? GetRecipe(RecipeInfo info);
public IAccountOwnedRecipes GetRecipesOf(Account account);
public IAccountRecipesPreferences GetPreferencesOf(Account account);

@ -37,11 +37,9 @@
<!-- Email entry -->
<Grid
Grid.Row="1"
RowDefinitions="*, Auto, Auto"
>
RowDefinitions="*, Auto, Auto">
<Label
Grid.Row="0"
FontSize="15"
TextColor="{StaticResource TextColorSecondary}"

@ -16,21 +16,21 @@ public partial class CreateRecipePage : ContentPage
this.onRecipeCreated = onRecipeCreated;
}
private void OnAddIngredientTapped(object sender, TappedEventArgs e)
private async void OnAddIngredientTapped(object sender, TappedEventArgs e)
{
IngredientList.Children.Add(new IngredientEntry());
}
private void OnAddStepTapped(object sender, TappedEventArgs e)
private async void OnAddStepTapped(object sender, TappedEventArgs e)
{
StepList.Children.Add(new StepEntry((uint) StepList.Children.Count() + 1));
}
private void OnBackButtonClicked(object sender, EventArgs e)
private async void OnBackButtonClicked(object sender, EventArgs e)
{
Navigation.PopAsync();
}
private void OnUploadRecipeClicked(object sender, EventArgs e)
private async void OnUploadRecipeClicked(object sender, EventArgs e)
{
uint callPerPers;

@ -27,15 +27,15 @@ public partial class FavoritesPage : ContentPage
RecipeViewLayout.Children.Clear();
preferences.GetFavorites().ForEach(info =>
{
RecipeViewLayout.Children.Add(new RecipeView(info, () =>
RecipeViewLayout.Children.Add(new RecipeView(info, async () =>
{
Recipe recipe = service.GetRecipe(info);
Shell.Current.Navigation.PushAsync(new RecipePage(recipe, preferences, 1));
Recipe? recipe = service.GetRecipe(info);
await Shell.Current.Navigation.PushAsync(new RecipePage(recipe, preferences, 1));
}));
});
}
private void ContentPage_NavigatedTo(object sender, NavigatedToEventArgs e)
private async void ContentPage_NavigatedTo(object sender, NavigatedToEventArgs e)
{
UpdateFavorites();
}

@ -1,4 +1,3 @@
namespace ShoopNCook.Pages;
using Models;
using ShoopNCook.Views;
@ -20,8 +19,13 @@ public partial class HomePage : ContentPage
{
layout.Children.Add(new RecipeView(info, () =>
{
Recipe recipe = service.GetRecipe(info);
Shell.Current.Navigation.PushAsync(new RecipePage(recipe, preferences, 1));
Recipe? recipe = service.GetRecipe(info);
if (recipe != null)
Shell.Current.Navigation.PushAsync(new RecipePage(recipe, preferences, 1));
else
{
UserNotifier.Error("Could not find recipe");
}
}));
}
@ -35,8 +39,8 @@ public partial class HomePage : ContentPage
private void OnSyncButtonClicked(object sender, EventArgs e)
private async void OnSyncButtonClicked(object sender, EventArgs e)
{
Shell.Current.Navigation.PushAsync(new SearchPage());
await Shell.Current.Navigation.PushAsync(new SearchPage());
}
}

@ -35,7 +35,7 @@ public partial class MyListPage : ContentPage
});
}
private void ContentPage_NavigatedTo(object sender, NavigatedToEventArgs e)
private async void ContentPage_NavigatedTo(object sender, NavigatedToEventArgs e)
{
UpdateMyList();
}

@ -58,11 +58,11 @@ public partial class MyRecipesPage : ContentPage
UserNotifier.Success("Recipe successfully removed");
}
private void OnBackButtonClicked(object sender, EventArgs e)
private async void OnBackButtonClicked(object sender, EventArgs e)
{
Navigation.PopAsync();
await Navigation.PopAsync();
}
private void OnAddRecipeButtonClicked(object sender, EventArgs e)
private async void OnAddRecipeButtonClicked(object sender, EventArgs e)
{
IAccountOwnedRecipes recipes = service.GetRecipesOf(account);

@ -75,7 +75,7 @@ public partial class RecipePage : ContentPage
}
}
private void OnFavorite(object o, EventArgs e)
private async void OnFavorite(object o, EventArgs e)
{
SetFavorite(!isFavorite);
if (isFavorite)
@ -84,13 +84,13 @@ public partial class RecipePage : ContentPage
preferences.RemoveFromFavorites(info);
}
private void OnSubmitReviewClicked(object o, EventArgs e)
private async void OnSubmitReviewClicked(object o, EventArgs e)
{
preferences.SetReviewScore(info, note);
UserNotifier.Success("Your review has been successfuly submited");
}
private void OnAddToMyListClicked(object o, EventArgs e)
private async void OnAddToMyListClicked(object o, EventArgs e)
{
if (!preferences.AddToWeeklyList(info, Counter.Count))
UserNotifier.Notice("You already added this recipe to you weekly list!");
@ -106,9 +106,9 @@ public partial class RecipePage : ContentPage
else
Favorite.Source = ImageSource.FromFile("hearth_off.svg");
}
private void OnBackButtonClicked(object sender, EventArgs e)
private async void OnBackButtonClicked(object sender, EventArgs e)
{
Navigation.PopAsync();
await Navigation.PopAsync();
}
}

@ -14,7 +14,7 @@ public partial class RegisterPage : ContentPage
{
await Shell.Current.GoToAsync("//Login");
}
private void RegisterTapped(object sender, EventArgs e)
private async void RegisterTapped(object sender, EventArgs e)
{
string email = EmailEntry.Text;
string password = PasswordEntry.Text;

Binary file not shown.
Loading…
Cancel
Save