Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPulman committed Jul 29, 2024
2 parents ed0bdc6 + c8b5af1 commit dd1f226
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/ReactiveMvvm.Maui/Views/FeedbackView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public FeedbackView()
this.OneWayBind(ViewModel, x => x.TitleLengthMax, x => x.TitleEntry.MaxLength)
.DisposeWith(subscriptions);

this.WhenAnyValue(x => x.ViewModel.TitleLength, x => x.ViewModel.TitleLengthMax)
this.WhenAnyValue(x => x.ViewModel!.TitleLength, x => x.ViewModel!.TitleLengthMax)
.Select(values => $"{values.Item1} letters used from {values.Item2}")
.BindTo(this, x => x.TitleLengthEntry.Text)
.DisposeWith(subscriptions);
Expand All @@ -31,7 +31,7 @@ public FeedbackView()
this.OneWayBind(ViewModel, x => x.MessageLengthMax, x => x.MessageEntry.MaxLength)
.DisposeWith(subscriptions);

this.WhenAnyValue(x => x.ViewModel.MessageLength, x => x.ViewModel.MessageLengthMax)
this.WhenAnyValue(x => x.ViewModel!.MessageLength, x => x.ViewModel!.MessageLengthMax)
.Select(values => $"{values.Item1} letters used from {values.Item2}")
.BindTo(this, x => x.MessageLengthEntry.Text)
.DisposeWith(subscriptions);
Expand Down
2 changes: 1 addition & 1 deletion src/ReactiveMvvm.Terminal/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static MemoizedElement<TOwner, TNew> StackPanel<TOwner, TNew>(
TNew control)
where TOwner : View
where TNew : View =>
new MemoizedElement<TOwner, TNew>(owner, control);
new(owner, control);

public static MemoizedElement<TOwner, TNew> Append<TOwner, TOld, TNew>(
this MemoizedElement<TOwner, TOld> owner,
Expand Down
2 changes: 1 addition & 1 deletion src/ReactiveMvvm.Terminal/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static void Main(string[] args)
Application.Init();
Application.Run(
new FeedbackView(
new FeedbackViewModel(
new(
new TerminalSender(),
new Clock())));
}
Expand Down
3 changes: 2 additions & 1 deletion src/ReactiveMvvm.Terminal/ReactiveMvvm.Terminal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="[2024.2.0,)" PrivateAssets="all" />
<PackageReference Include="ReactiveMarbles.ObservableEvents.SourceGenerator" Version="1.3.1" />
<PackageReference Include="Terminal.Gui" Version="2.0.0-prealpha.1829" />
<PackageReference Include="NStack.Core" Version="1.1.1" />
<PackageReference Include="NStack.Core" Version="1.1.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ReactiveMvvm\ReactiveMvvm.csproj" />
Expand Down
43 changes: 22 additions & 21 deletions src/ReactiveMvvm.Terminal/Views/FeedbackView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,28 @@ public sealed class FeedbackView : Window, IViewFor<FeedbackViewModel>, IDisposa
{
private readonly CompositeDisposable _subscriptions = [];

public FeedbackView(FeedbackViewModel viewModel) :
base(new Rect(0, 0, 30, 20))
public FeedbackView(FeedbackViewModel viewModel)
{
ViewModel = viewModel;
ViewModel.Activator.Activate();
this.StackPanel(TimeElapsedLabel())
.Append(new Label("Issue Title"))
.Append(new Label() { Text = "Issue Title" })
.Append(TitleDescription())
.Append(TitleInput())
.Append(new Label("Issue Description"))
.Append(new Label() { Text = "Issue Description" })
.Append(MessageDescription())
.Append(MessageInput())
.Append(new Label("Feedback Type"))
.Append(new Label() { Text = "Feedback Type" })
.Append(IssueCheckBox())
.Append(IdeaCheckBox())
.Append(new Label("Feedback Category"))
.Append(new Label() { Text = "Feedback Category" })
.Append(SectionRadioGroup())
.Append(new Button("Send Feedback"), 4);
.Append(new Button() { Text = "Send Feedback" }, 4);
}

private RadioGroup SectionRadioGroup()
{
var radioGroup = new RadioGroup(["User Interface", "Audio", "Video", "Voice"]);
var radioGroup = new RadioGroup() { RadioLabels = ["User Interface", "Audio", "Video", "Voice"] };
this.WhenAnyValue(x => x.ViewModel.Section)
.BindTo(radioGroup, x => x.SelectedItem)
.DisposeWith(_subscriptions);
Expand All @@ -51,13 +50,14 @@ private RadioGroup SectionRadioGroup()

private CheckBox IssueCheckBox()
{
var item = new CheckBox("Issue", ViewModel.Issue);
var item = new CheckBox() { Text = "Issue", State = ViewModel.Issue ? CheckState.Checked : CheckState.UnChecked };
this.WhenAnyValue(x => x.ViewModel.Issue)
.BindTo(item, x => x.Checked)
.Select(issue => issue ? CheckState.Checked : CheckState.UnChecked)
.BindTo(item, x => x.State)
.DisposeWith(_subscriptions);
item.Events()
.Toggled
.Select(args => item.Checked)
.Toggle
.Select(args => args.NewValue == CheckState.Checked)
.BindTo(this, x => x.ViewModel.Issue)
.DisposeWith(_subscriptions);
this.WhenAnyValue(x => x.ViewModel.Idea)
Expand All @@ -69,13 +69,14 @@ private CheckBox IssueCheckBox()

private CheckBox IdeaCheckBox()
{
var item = new CheckBox("Suggestion", ViewModel.Idea);
var item = new CheckBox() { Text = "Suggestion", State = ViewModel.Idea ? CheckState.Checked : CheckState.UnChecked };
this.WhenAnyValue(x => x.ViewModel.Idea)
.BindTo(item, x => x.Checked)
.Select(issue => issue ? CheckState.Checked : CheckState.UnChecked)
.BindTo(item, x => x.State)
.DisposeWith(_subscriptions);
item.Events()
.Toggled
.Select(old => item.Checked)
.Toggle
.Select(args => args.NewValue == CheckState.Checked)
.BindTo(this, x => x.ViewModel.Idea)
.DisposeWith(_subscriptions);
this.WhenAnyValue(x => x.ViewModel.Issue)
Expand All @@ -87,7 +88,7 @@ private CheckBox IdeaCheckBox()

private Label TimeElapsedLabel()
{
var label = new Label("0 seconds passed");
var label = new Label() { Text = "0 seconds passed" };
this.WhenAnyValue(x => x.ViewModel.Elapsed)
.Select(elapsed => (ustring) $"{elapsed} seconds passed")
.BindTo(label, x => x.Text)
Expand All @@ -97,7 +98,7 @@ private Label TimeElapsedLabel()

private TextField MessageInput()
{
var text = new TextField(ViewModel.Message);
var text = new TextField() { Text = ViewModel.Message, Width = 40 };
this.WhenAnyValue(x => x.ViewModel.Message)
.BindTo(text, x => x.Text)
.DisposeWith(_subscriptions);
Expand All @@ -112,7 +113,7 @@ private TextField MessageInput()

private Label MessageDescription()
{
var label = new Label($"0 letters used from {ViewModel.MessageLengthMax}");
var label = new Label() { Text = $"0 letters used from {ViewModel.MessageLengthMax}" };
this.WhenAnyValue(x => x.ViewModel.MessageLength, x => x.ViewModel.MessageLengthMax)
.Select(values => (ustring) $"{values.Item1} letters used from {values.Item2}")
.BindTo(label, x => x.Text)
Expand All @@ -122,7 +123,7 @@ private Label MessageDescription()

private TextField TitleInput()
{
var text = new TextField(ViewModel.Title);
var text = new TextField() { Text = ViewModel.Title, Width = 40 };
this.WhenAnyValue(x => x.ViewModel.Title)
.BindTo(text, x => x.Text)
.DisposeWith(_subscriptions);
Expand All @@ -137,7 +138,7 @@ private TextField TitleInput()

private Label TitleDescription()
{
var label = new Label($"0 letters used from {ViewModel.TitleLengthMax}");
var label = new Label() { Text = $"0 letters used from {ViewModel.TitleLengthMax}" };
this.WhenAnyValue(x => x.ViewModel.TitleLength, x => x.ViewModel.TitleLengthMax)
.Select(values => (ustring) $"{values.Item1} letters used from {values.Item2}")
.BindTo(label, x => x.Text)
Expand Down

0 comments on commit dd1f226

Please sign in to comment.