Skip to content

Commit

Permalink
refistration done
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Harnett committed Nov 30, 2023
1 parent f2a3cdc commit fffddc1
Show file tree
Hide file tree
Showing 15 changed files with 415 additions and 133 deletions.
3 changes: 2 additions & 1 deletion RightToAskClient/RightToAskClient.Maui/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<!-- These are all the same light green -->
<Color x:Key="FadedButtonColor">#dfdfdf</Color>
<Color x:Key="SeparatorDarkModeColor">#363636</Color>
<Color x:Key="FrameColor">#dfdfdf</Color>
<Color x:Key="FrameColor">Transparent</Color>

<!-- Second theme color -->
<Color x:Key="DarkPurple">#600C82</Color>
Expand Down Expand Up @@ -382,6 +382,7 @@
<Setter Property="CornerRadius" Value="0" />
<Setter Property="Padding" Value="0" />
<Setter Property="HasShadow" Value="False" />
<Setter Property="BorderColor" Value="Transparent" />
</Style>
<Style x:Key="TransparentSwipeView" TargetType="SwipeView">
<Setter Property="BackgroundColor" Value="Transparent" />
Expand Down
10 changes: 8 additions & 2 deletions RightToAskClient/RightToAskClient.Maui/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CommunityToolkit.Maui;
using static RightToAskClient.Maui.Views.Controls.Accessibility;

namespace RightToAskClient.Maui
{
Expand All @@ -10,13 +11,18 @@ public static MauiApp CreateMauiApp()
builder
.UseMauiApp<App>()
.UseMauiCommunityToolkit()
.ConfigureEffects(effects =>
{
//effects.Add<>();
})
.ConfigureFonts(fonts =>
{
fonts.AddFont("DancingScript-VariableFont_wght.ttf", "DanceFont");
// fonts.AddFont("Roboto-Black.ttf", "AppFont");
// fonts.AddFont("Roboto-Black.ttf", "AppFont");
});

return builder.Build();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -323,4 +323,6 @@
</MauiXaml>
</ItemGroup>

<ProjectExtensions><VisualStudio><UserProperties XamarinHotReloadDebuggerTimeoutExceptionRightToAskClientMauiHideInfoBar="True" /></VisualStudio></ProjectExtensions>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public bool IsRaiseLayoutVisible
// Convenient views of things stored in the Question.
public List<Answer> QuestionAnswers => Question.Answers;
public List<Uri> HansardLinks => Question.HansardLink;

public string QuestionAnswerers =>
Helpers.Extensions.JoinFilter(", ",
string.Join(", ", Question.Filters.SelectedAnsweringMPsNotMine.Select(mp => mp.ShortestName)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,28 @@
using Microsoft.Maui;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Maui.Views;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Input;

namespace RightToAskClient.Maui.ViewModels
{
public class ReadingPageViewModel: BaseViewModel
public class ReadingPageViewModel : BaseViewModel
{
public FilterChoices FilterChoices = new FilterChoices();

// This is static because we want every instance of ReadingPageViewModel to have the same one:
// if you up-vote a question in one version of the ReadingView, we need the other ReadingPages to
// see the same change.
private static QuestionResponseRecords _thisUsersResponsesToQuestions = new QuestionResponseRecords();

// properties
public Boolean HasFilter
{
get => FilterChoices.SelectedAnsweringMPsNotMine.Count == 0 &&
get => FilterChoices.SelectedAnsweringMPsNotMine.Count == 0 &&
FilterChoices.SelectedAnsweringMPsMine.Count == 0 &&
FilterChoices.SelectedCommittees.Count == 0 &&
FilterChoices.SelectedAskingMPsMine.Count == 0 &&
FilterChoices.SelectedCommittees.Count == 0 &&
FilterChoices.SelectedAskingMPsMine.Count == 0 &&
FilterChoices.SelectedAskingMPsNotMine.Count == 0 &&
FilterChoices.SelectedAuthorities.Count == 0 ? true : false;
}
Expand Down Expand Up @@ -74,12 +77,17 @@ public ObservableCollection<QuestionDisplayCardViewModel> QuestionsToDisplay
set => SetProperty(ref _questionsToDisplay, value);
}

private bool _isRefreshing = true;
private bool _isRefreshing = false;
public bool IsRefreshing
{
get => _isRefreshing;
set => SetProperty(ref _isRefreshing, value);
}
#region INotifyPropertyChanged



#endregion

public string Keyword
{
Expand All @@ -88,9 +96,9 @@ public string Keyword
{
FilterChoices.SearchKeyword = value;
}

}

private string _writerOnlyUid = string.Empty;
private bool _readByQuestionWriter;
protected bool _successRespond = true;
Expand All @@ -104,54 +112,52 @@ public string EmptyViewLabelText

// Parameters for server question searches
protected readonly Weights SearchWeights;
public ReadingPageViewModel(): this(false, true)
public ReadingPageViewModel() : this(false, true)
{
Task.Run(async() => await RefreshItemsAsync());
}

// constructor
public ReadingPageViewModel(bool readByQuestionWriter, bool needRefresh)
{
_readByQuestionWriter = readByQuestionWriter;

// Retrieve previous responses from Preferences, e.g. to display proper coloration on prior up-votes.
_thisUsersResponsesToQuestions.Init();

// Keyword = FilterChoices.SearchKeyword;

// Default to search weights for main reading page; derived classes can alter this for other priorities.
SearchWeights = Constants.mainReadingPageWeights;

// If we're already searching for something, show the user what.
ShowSearchFrame = !readByQuestionWriter;
ShowSearchFrame = !readByQuestionWriter;

// Reading with a draft question - prompt for upvoting similar questions
Heading1 = AppResources.FocusSupportInstructionReadingOnly;
Title = AppResources.ReadQuestionsTitle;

PopupLabelText = AppResources.ReadingPageHeader1;
PopupHeaderText = Heading1;

if (XamarinPreferences.shared.Get(Constants.ShowFirstTimeReadingPopup, true))
{
// InfoPopupCommand.ExecuteAsync(null);
TCCommand.ExecuteAsync(null);

}
// Note: There is a race condition here, in that it is possible
// for this command to be executed multiple times simultaneously,
// producing multiple calls to Clear and the simultaneous insertion
// of questions from various versions of questionsToDisplay List.
// I don't *think* this will cause a lock because QuestionsToDisplay
// ought to be able to be cleared and added to in any order.
RefreshCommand = new AsyncRelayCommand (async () =>
RefreshCommand = new AsyncRelayCommand(async () =>
{
var questionsToDisplayList = await LoadQuestions();
doQuestionDisplayRefresh(questionsToDisplayList);
IsRefreshing = false;
await RefreshItemsAsync();
});
DraftCommand = new AsyncRelayCommand (async () =>
DraftCommand = new AsyncRelayCommand(async () =>
{

// Check that they are registered - if not, prompt them to get an account.
if (!IndividualParticipant.getInstance().ProfileData.RegistrationInfo.IsRegistered)
{
Expand All @@ -173,7 +179,7 @@ await NavigationUtils.DoRegistrationCheck(
// Only show it once.
XamarinPreferences.shared.Set(Constants.ShowHowToPublishPopup, false);
}

// Now let them start drafting.
await Shell.Current.GoToAsync($"{nameof(WriteQuestionPage)}");
}
Expand All @@ -182,7 +188,7 @@ await NavigationUtils.DoRegistrationCheck(
{
ShowSearchFrame = !ShowSearchFrame; // just toggle it
});
ShowFiltersCommand = new AsyncRelayCommand (async () =>
ShowFiltersCommand = new AsyncRelayCommand(async () =>
{
var advancedSearchFiltersPage = new AdvancedSearchFiltersPage(FilterChoices);
await Application.Current.MainPage.Navigation.PushAsync(advancedSearchFiltersPage);
Expand All @@ -195,39 +201,45 @@ await NavigationUtils.DoRegistrationCheck(
QuestionsToDisplay.Remove(questionToRemove);
}
// removeQuestionAddRecord(questionToRemove);
});
});

// Get the question list for display
if (needRefresh)
{
RefreshCommand.ExecuteAsync(null);
//RefreshCommand.Execute(null);
}
else
{
IsRefreshing = false;
}

// Makes the question list refresh when the Advanced Search page has updated search terms.
MessagingCenter.Subscribe<FilterViewModel>(this, Constants.RefreshQuestionList,
MessagingCenter.Subscribe<FilterViewModel>(this, Constants.RefreshQuestionList,
(sender) =>
{
RefreshCommand.ExecuteAsync(null);
// RefreshCommand.Execute(null);
});
}

async Task RefreshItemsAsync()
{
IsRefreshing = true;
var questionsToDisplayList = await LoadQuestions();
DoQuestionDisplayRefresh(questionsToDisplayList);
IsRefreshing = false;
}
// commands
public AsyncRelayCommand RefreshCommand { get; protected set; }
public IAsyncRelayCommand DraftCommand { get; }
public ICommand RefreshCommand { get; protected set; }
public IAsyncRelayCommand DraftCommand { get; }
public Command SearchToolbarCommand { get; }
public Command<QuestionDisplayCardViewModel> RemoveQuestionCommand { get; }
public IAsyncRelayCommand ShowFiltersCommand { get; }
public IAsyncRelayCommand ShowFiltersCommand { get; }

// Loads the questions, depending on the value of ReadByQuestionWriter.
protected async Task<List<QuestionDisplayCardViewModel>> LoadQuestions()
{
var serverQuestions = new List<QuestionReceiveFromServer>();
var questionsToDisplay = new List<QuestionDisplayCardViewModel>();

JOSResult<List<string>> httpResponse;
if (_readByQuestionWriter)
{
Expand All @@ -239,18 +251,18 @@ protected async Task<List<QuestionDisplayCardViewModel>> LoadQuestions()
EmptyViewLabelText = AppResources.EmptyMatchingQuestionCollectionViewString;
httpResponse = await GetQuestionListBySearch();
}

var httpValidation = RTAClient.ValidateHttpResponse(httpResponse, "Server Signature Verification");
_successRespond = httpValidation.isValid;
if (!httpValidation.isValid)
{
ReportLabelText = "Failed to get Question List from server." + httpValidation.errorMessage;
return questionsToDisplay;
}

// httpValidation isValid
var questionIds = httpResponse.Data;

// loop through the questions
foreach (var questionId in questionIds)
{
Expand Down Expand Up @@ -293,19 +305,17 @@ protected async Task<List<QuestionDisplayCardViewModel>> LoadQuestions()
questionsToDisplay.Add(new QuestionDisplayCardViewModel(serverQuestion, _thisUsersResponsesToQuestions));
}
}

DoQuestionDisplayRefresh(questionsToDisplay);
return questionsToDisplay;
}

protected void doQuestionDisplayRefresh(List<QuestionDisplayCardViewModel> questions)
protected void DoQuestionDisplayRefresh(List<QuestionDisplayCardViewModel> questions)
{
QuestionsToDisplay.Clear();
foreach (var q in questions)
{
QuestionsToDisplay.Add(q);

{
QuestionsToDisplay.Add(q);
}

if (QuestionsToDisplay.Count == 0)
{
if (!_successRespond)
Expand All @@ -319,26 +329,26 @@ protected void doQuestionDisplayRefresh(List<QuestionDisplayCardViewModel> quest
}
}
}

// Gets the list of question IDs, using 'similarity' material
private async Task<JOSResult<List<string>>> GetQuestionListBySearch()
{
var filters = FilterChoices;

// use the filters to search for similar questions.
var serverSearchQuery = new WeightedSearchRequest()
{
question_text = filters.SearchKeyword,
page = new QuestionListPage()
{
from = 0,
to = Constants.DefaultPageSize
to = Constants.DefaultPageSize
},
weights = SearchWeights,
entity_who_should_answer_the_question = filters.TranscribeQuestionAnswerersForUpload(),
mp_who_should_ask_the_question = filters.TranscribeQuestionAskersForUpload()
};

// Search based on filters and/or search/draft words.
var scoredList = await RTAClient.GetSortedSimilarQuestionIDs(serverSearchQuery);

Expand All @@ -357,7 +367,7 @@ private async Task<JOSResult<List<string>>> GetQuestionListBySearch()
// For the moment, ignore both the token and the individual-question scores.
return new SuccessResult<List<string>>(scoredList.Data.questions.Select(sq => sq.id).ToList());
}

private async Task<JOSResult<List<string>>> GetQuestionListByWriter()
{
var myUID = IndividualParticipant.getInstance().ProfileData.RegistrationInfo.uid;
Expand All @@ -379,4 +389,6 @@ private async Task<JOSResult<List<string>>> GetQuestionListByWriter()
return new SuccessResult<List<string>>(questionIDs.Data);
}
}


}
Loading

0 comments on commit fffddc1

Please sign in to comment.