Skip to content

Commit

Permalink
Making it possible to use a custom made location
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdullahAlhariri committed Jun 15, 2024
1 parent f615dfc commit d44df37
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 12 deletions.
27 changes: 24 additions & 3 deletions ViewModels/JadeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public partial class JadeViewModel : ObservableObject
[ObservableProperty] private List<string> _locations;
[ObservableProperty] private string _selectedLocation;
[ObservableProperty] private string _noteName;
[ObservableProperty] private bool _customLocationEntry = false;

public async void OnLoaded()
{
Expand Down Expand Up @@ -90,29 +91,43 @@ private async void StartSignalRConnection()

}

public void NoteContentUpdate(TextChangedEventArgs e) => _debounceService.Debounce(500, async () =>
public void NoteContentUpdate(TextChangedEventArgs e) => _debounceService.Debounce(1000, async () =>
{
if (Note == null || e.OldTextValue == e.NewTextValue) return;
var connection = await _signalRService.GetConnection();
await connection.InvokeCoreAsync("UpdateContent", args: new object?[] { Note.id, Content });
});

public void NoteNameUpdate() => _debounceService.Debounce(500, async () =>
public void NoteNameUpdate() => _debounceService.Debounce(1000, async () =>
{
if (Note == null) return;
var connection = await _signalRService.GetConnection();
Note.name = NoteName;
await connection.InvokeCoreAsync("Update", args: new object?[] { Note.id, Note.name, Note.location });
});

public void NoteLocationUpdate() => _debounceService.Debounce(500, async () =>
public void NoteCustomLocationUpdate() => _debounceService.Debounce(1000, async () =>
{
if (Note == null) return;
var connection = await _signalRService.GetConnection();
Note.location = SelectedLocation == "./" ? null : SelectedLocation;
await connection.InvokeCoreAsync("Update", args: new object?[] { Note.id, Note.name, Note.location });
});

public void NoteLocationUpdate(object? sender, EventArgs e) => _debounceService.Debounce(1000, async () =>
{
var picker = (Picker)sender;
int selectedIndex = picker.SelectedIndex;
if (selectedIndex == -1) return;
SelectedLocation = (string)picker.ItemsSource[selectedIndex];
if (Note == null) return;
var connection = await _signalRService.GetConnection();
Note.location = SelectedLocation == "./" ? null : SelectedLocation;
await connection.InvokeCoreAsync("Update", args: new object?[] { Note.id, Note.name, Note.location });
});

[RelayCommand]
private async Task SaveNote()
{
Expand All @@ -137,4 +152,10 @@ private async Task NotesArchivePage()
await _signalRService.StopConnection();
await Shell.Current.GoToAsync(Routes.NotesArchivePage);
}

[RelayCommand]
private void ToggleCustomLocationEntry()
{
CustomLocationEntry = !CustomLocationEntry;
}
}
47 changes: 39 additions & 8 deletions Views/JadePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,58 @@

<StackLayout Margin="15">
<Grid
ColumnDefinitions="*, Auto, Auto"
ColumnDefinitions="Auto, *, Auto, Auto"
ColumnSpacing="10"
VerticalOptions="Start">
<Grid.Triggers>
<DataTrigger
Binding="{Binding Note}"
TargetType="Grid"
Value="{x:Null}">
<Setter Property="ColumnDefinitions" Value="*, Auto, Auto, Auto" />
<Setter Property="ColumnDefinitions" Value="Auto, *, Auto, Auto, Auto" />
</DataTrigger>
</Grid.Triggers>

<Picker
<Button
Command="{Binding ToggleCustomLocationEntryCommand}"
Grid.Column="0"
HeightRequest="30"
ImageSource="{icons:Material TextFields,
IconSize=17}"
VerticalOptions="Fill" />

<Picker
Grid.Column="1"
ItemsSource="{Binding Locations}"
SelectedIndexChanged="NoteLocationUpdate"
SelectedItem="{Binding SelectedLocation}" />
SelectedIndexChanged="NoteLocationUpdate">
<Picker.Triggers>
<DataTrigger
Binding="{Binding CustomLocationEntry}"
TargetType="Picker"
Value="true">
<Setter Property="IsVisible" Value="False" />
</DataTrigger>
</Picker.Triggers>
</Picker>

<Entry
Grid.Column="1"
IsVisible="False"
Text="{Binding SelectedLocation}"
TextChanged="NoteCustomLocationUpdate">
<Entry.Triggers>
<DataTrigger
Binding="{Binding CustomLocationEntry}"
TargetType="Entry"
Value="true">
<Setter Property="IsVisible" Value="True" />
</DataTrigger>
</Entry.Triggers>
</Entry>

<Button
Command="{Binding NotesArchivePageCommand}"
Grid.Column="1"
Grid.Column="2"
ImageSource="{icons:Material Archive,
IconSize=17}"
Text="Archived"
Expand All @@ -78,7 +109,7 @@

<Button
Command="{Binding NotesPageCommand}"
Grid.Column="2"
Grid.Column="3"
ImageSource="{icons:Material FolderCopy,
IconSize=17}"
Text="Notes"
Expand All @@ -93,7 +124,7 @@

<Button
Command="{Binding SaveNoteCommand}"
Grid.Column="3"
Grid.Column="4"
ImageSource="{icons:Material Check,
IconSize=17}"
Text="Save new note"
Expand Down
3 changes: 2 additions & 1 deletion Views/JadePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ private void NoteContentUpdate(object sender, TextChangedEventArgs e) =>
ViewModel.NoteContentUpdate(e); // Note content update

private void NoteNameUpdate(object? sender, EventArgs e) => ViewModel.NoteNameUpdate();
private void NoteLocationUpdate(object? sender, EventArgs e) => ViewModel.NoteLocationUpdate();
private void NoteLocationUpdate(object? sender, EventArgs e) => ViewModel.NoteLocationUpdate(sender, e);
private void NoteCustomLocationUpdate(object? sender, EventArgs e) => ViewModel.NoteCustomLocationUpdate();

private void OnLoaded(object? sender, EventArgs e) => ViewModel.OnLoaded();
}

0 comments on commit d44df37

Please sign in to comment.