Skip to content
This repository was archived by the owner on Apr 30, 2024. It is now read-only.

Commit

Permalink
Open guild settings page
Browse files Browse the repository at this point in the history
  • Loading branch information
Avid29 committed May 19, 2022
1 parent baf0a66 commit 82eb9de
Show file tree
Hide file tree
Showing 18 changed files with 312 additions and 13 deletions.
15 changes: 15 additions & 0 deletions src/Quarrel.ViewModels/ViewModels/Panels/GuildsViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
// Quarrel © 2022

using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Mvvm.Input;
using Microsoft.Toolkit.Mvvm.Messaging;
using Quarrel.Bindables.Guilds;
using Quarrel.Bindables.Guilds.Interfaces;
using Quarrel.Messages;
using Quarrel.Messages.Navigation;
using Quarrel.Messages.Navigation.SubPages;
using Quarrel.Services.Analytics;
using Quarrel.Services.Analytics.Enums;
using Quarrel.Services.Discord;
using Quarrel.Services.Dispatcher;
using Quarrel.Services.Localization;
using Quarrel.ViewModels.SubPages.GuildSettings;
using System.Collections.Concurrent;
using System.Collections.ObjectModel;

Expand Down Expand Up @@ -44,6 +47,8 @@ public GuildsViewModel(IAnalyticsService analyticsService, IMessenger messenger,
Source = new ObservableCollection<IBindableGuildListItem>();
_guilds = new ConcurrentDictionary<ulong, BindableGuild>();

OpenGuildSettingsCommand = new RelayCommand(OpenGuildSettings);

_messenger.Register<UserLoggedInMessage>(this, (_, _) => LoadGuilds());
_messenger.Register<NavigateToGuildMessage<ulong>>(this, (_, m) => ForwardNavigate(m.Guild));
}
Expand Down Expand Up @@ -73,6 +78,11 @@ public IBindableSelectableGuildItem? SelectedGuild
/// </summary>
public ObservableCollection<IBindableGuildListItem> Source { get; private set; }

/// <summary>
/// Gets a command that opens the guild settings page for this guild
/// </summary>
public RelayCommand OpenGuildSettingsCommand { get; }

/// <summary>
/// Loads the guilds for the user.
/// </summary>
Expand Down Expand Up @@ -102,6 +112,11 @@ public void LoadGuilds()
});
}

private void OpenGuildSettings()
{
_messenger.Send(new NavigateToSubPageMessage(typeof(GuildSettingsPageViewModel)));
}

private void ForwardNavigate(ulong guildId)
{
BindableGuild? guild = GetBindableGuild(guildId);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Quarrel © 2022

using Microsoft.Toolkit.Mvvm.ComponentModel;
using Quarrel.Services.Localization;

namespace Quarrel.ViewModels.SubPages.GuildSettings
{
/// <summary>
/// A header for a category of guild settings menu items.
/// </summary>
public class GuildSettingsHeader : ObservableObject, IGuildSettingsMenuItem
{
internal GuildSettingsHeader(ILocalizationService localizationService, string resource)
{
Title = localizationService[resource];
}

/// <inheritdoc/>
public string Title { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Quarrel © 2022

using Microsoft.Toolkit.Mvvm.ComponentModel;
using Quarrel.Services.Localization;
using Quarrel.ViewModels.SubPages.GuildSettings.Pages.Abstract;
using System.Collections.ObjectModel;

namespace Quarrel.ViewModels.SubPages.GuildSettings
{
/// <summary>
/// A view model for the guild settings page.
/// </summary>
public class GuildSettingsPageViewModel : ObservableObject
{
private const string PersonalSettingsResource = "GuildSettings/PersonalSettings";
private const string ServerSettingsResource = "GuildSettings/ServerSettings";
private const string UserManagementResource = "GuildSettings/UserManagement";

private GuildSettingsSubPageViewModel? _selectedSubPage;

/// <summary>
/// Initializes a new instance of the <see cref="GuildSettingsPageViewModel"/>.
/// </summary>
public GuildSettingsPageViewModel(ILocalizationService localizationService)
{
Pages = new ObservableCollection<IGuildSettingsMenuItem>();

// Personal Settings
Pages.Add(new GuildSettingsHeader(localizationService, PersonalSettingsResource));

// Server Settings
Pages.Add(new GuildSettingsHeader(localizationService, ServerSettingsResource));

// User management
Pages.Add(new GuildSettingsHeader(localizationService, UserManagementResource));
}

/// <summary>
/// Gets the view model of the selected sub page.
/// </summary>
public GuildSettingsSubPageViewModel? SelectedSubPage
{
get => _selectedSubPage;
set => SetProperty(ref _selectedSubPage, value);
}

/// <summary>
/// Gets the view models of all sub page options.
/// </summary>
public ObservableCollection<IGuildSettingsMenuItem> Pages { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Quarrel © 2022

namespace Quarrel.ViewModels.SubPages.GuildSettings
{
/// <summary>
/// An interface for items in the guild settings navigation menu.
/// </summary>
public interface IGuildSettingsMenuItem
{
/// <summary>
/// Gets the title of the menu item.
/// </summary>
string Title { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Quarrel © 2022

using Microsoft.Toolkit.Mvvm.ComponentModel;
using Quarrel.Services.Localization;
using Quarrel.Services.Storage;

namespace Quarrel.ViewModels.SubPages.GuildSettings.Pages.Abstract
{
/// <summary>
/// A base class for guild settings sub-page view models.
/// </summary>
public abstract class GuildSettingsSubPageViewModel : ObservableObject, IGuildSettingsMenuItem
{
/// <summary>
/// The localization service.
/// </summary>
protected readonly ILocalizationService _localizationService;

/// <summary>
/// The storage service.
/// </summary>
protected readonly IStorageService _storageService;

internal GuildSettingsSubPageViewModel(ILocalizationService localizationService, IStorageService storageService)
{
_localizationService = localizationService;
_storageService = storageService;
}

/// <summary>
/// Gets the string used as a glyph for the sub page.
/// </summary>
public abstract string Glyph { get; }

/// <summary>
/// Gets the title of the sub page.
/// </summary>
public abstract string Title { get; }

/// <summary>
/// Gets whether or not the page is currently active.
/// </summary>
public virtual bool IsActive => false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Quarrel.ViewModels.SubPages.UserSettings
{
/// <summary>
/// An interface for items in the
/// An interface for items in the user settings navigation menu.
/// </summary>
public interface IUserSettingsMenuItem
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,27 @@ public class UserSettingsPageViewModel : ObservableObject
private const string AccountSettingsResource = "UserSettings/AccountSettings";
private const string AppSettingsResource = "UserSettings/AppSettings";

private readonly ILocalizationService _localizationService;
private UserSettingsSubPageViewModel? _selectedSubPage;

/// <summary>
/// Initializes a new instance of the <see cref="UserSettingsPageViewModel"/>.
/// </summary>
public UserSettingsPageViewModel(ILocalizationService localizationService, IStorageService storageService, IDiscordService discordService)
{
_localizationService = localizationService;

Pages = new ObservableCollection<IUserSettingsMenuItem>();

// Account settings
Pages.Add(new UserSettingsHeader(localizationService, AccountSettingsResource));
Pages.Add(new MyAccountPageViewModel(_localizationService, storageService, discordService));
Pages.Add(new PrivacyPageViewModel(_localizationService, storageService, discordService));
Pages.Add(new ConnectionsPageViewModel(_localizationService, storageService));
Pages.Add(new MyAccountPageViewModel(localizationService, storageService, discordService));
Pages.Add(new PrivacyPageViewModel(localizationService, storageService, discordService));
Pages.Add(new ConnectionsPageViewModel(localizationService, storageService));

// App Settings
Pages.Add(new UserSettingsHeader(localizationService, AppSettingsResource));
Pages.Add(new DisplayPageViewModel(_localizationService, storageService));
Pages.Add(new BehaviorPageViewModel(_localizationService, storageService));
Pages.Add(new NotificationsPageViewModel(_localizationService, storageService));
Pages.Add(new VoicePageViewModel(_localizationService, storageService));
Pages.Add(new DisplayPageViewModel(localizationService, storageService));
Pages.Add(new BehaviorPageViewModel(localizationService, storageService));
Pages.Add(new NotificationsPageViewModel(localizationService, storageService));
Pages.Add(new VoicePageViewModel(localizationService, storageService));
}

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions src/Quarrel/App.Services.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Quarrel.ViewModels.Panels;
using Quarrel.ViewModels.SubPages;
using Quarrel.ViewModels.SubPages.DiscordStatus;
using Quarrel.ViewModels.SubPages.GuildSettings;
using Quarrel.ViewModels.SubPages.Host;
using Quarrel.ViewModels.SubPages.Meta;
using Quarrel.ViewModels.SubPages.Settings;
Expand Down Expand Up @@ -68,6 +69,7 @@ private IServiceProvider ConfigureServices()
services.AddTransient<AboutPageViewModel>();
services.AddTransient<CreditPageViewModel>();
services.AddTransient<DiscordStatusViewModel>();
services.AddTransient<GuildSettingsPageViewModel>();
services.AddTransient<UserSettingsPageViewModel>();

#if DEV
Expand Down
3 changes: 2 additions & 1 deletion src/Quarrel/Controls/Panels/Channels/GuildHeader.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
BorderThickness="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
HorizontalContentAlignment="Stretch">
HorizontalContentAlignment="Stretch"
Command="{x:Bind ViewModel.OpenGuildSettingsCommand}">
<TextBlock Text="{x:Bind ViewModel.SelectedGuild.Name, Mode=OneWay}"
HorizontalAlignment="Left" FontSize="20"/>
</Button>
Expand Down
12 changes: 12 additions & 0 deletions src/Quarrel/MultilingualResources/Quarrel.he-IL.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,18 @@
<source>Version: {0}.{1}.{2}</source>
<target state="needs-review-translation">גרסת: {0}.{1}.{2}</target>
</trans-unit>
<trans-unit id="GuildSettings/PersonalSettings" translate="yes" xml:space="preserve">
<source>Personal Settings</source>
<target state="new">Personal Settings</target>
</trans-unit>
<trans-unit id="GuildSettings/ServerSettings" translate="yes" xml:space="preserve">
<source>Server Settings</source>
<target state="new">Server Settings</target>
</trans-unit>
<trans-unit id="GuildSettings/UserManagement" translate="yes" xml:space="preserve">
<source>User Management</source>
<target state="new">User Management</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
9 changes: 9 additions & 0 deletions src/Quarrel/Quarrel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@
<Compile Include="Selectors\Guilds\GuildTemplateSelector.cs" />
<Compile Include="Selectors\Messages\AttachmentTemplateSelector.cs" />
<Compile Include="Selectors\Messages\MessageTemplateSelector.cs" />
<Compile Include="Selectors\SubPages\GuildSettings\GuildSettingsMenuItemSelector.cs" />
<Compile Include="Selectors\SubPages\GuildSettings\GuildSettingsPageSelector.cs" />
<Compile Include="Selectors\SubPages\SubPageTemplateSelector.cs" />
<Compile Include="Selectors\SubPages\UserSettings\UserSettingsMenuItemSelector.cs" />
<Compile Include="Selectors\SubPages\UserSettings\UserSettingsPageSelector.cs" />
Expand All @@ -209,6 +211,9 @@
<Compile Include="SubPages\DiscordStatus\DiscordStatusPage.xaml.cs">
<DependentUpon>DiscordStatusPage.xaml</DependentUpon>
</Compile>
<Compile Include="SubPages\GuildSettings\GuildSettingsPage.xaml.cs">
<DependentUpon>GuildSettingsPage.xaml</DependentUpon>
</Compile>
<Compile Include="SubPages\Meta\AboutPage.xaml.cs">
<DependentUpon>AboutPage.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -590,6 +595,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="SubPages\GuildSettings\GuildSettingsPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="SubPages\Meta\AboutPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Quarrel © 2022

using Quarrel.ViewModels.SubPages.GuildSettings;
using Quarrel.ViewModels.SubPages.GuildSettings.Pages.Abstract;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace Quarrel.Selectors.SubPages.GuildSettings
{
public class GuildSettingsMenuItemSelector : DataTemplateSelector
{
public DataTemplate? HeaderItem { get; set; }

public DataTemplate? MenuItem { get; set; }

protected override DataTemplate SelectTemplateCore(object item)
{
return item switch
{
GuildSettingsHeader => HeaderItem,
GuildSettingsSubPageViewModel or _ => MenuItem,
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Quarrel © 2022

using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace Quarrel.Selectors.SubPages.UserSettings
{
public class GuildSettingsPageSelector : DataTemplateSelector
{
protected override DataTemplate? SelectTemplateCore(object item, DependencyObject container)
{
return item switch
{
_ => null,
};
}
}
}
5 changes: 4 additions & 1 deletion src/Quarrel/Selectors/SubPages/SubPageTemplateSelector.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Quarrel © 2022

using Quarrel.ViewModels.SubPages.DiscordStatus;
using Quarrel.ViewModels.SubPages.GuildSettings;
using Quarrel.ViewModels.SubPages.Meta;
using Quarrel.ViewModels.SubPages.Settings;
using Windows.UI.Xaml;
Expand All @@ -16,8 +17,9 @@ public class SubPageTemplateSelector : DataTemplateSelector

public DataTemplate? DiscordStatusTemplate { get; set; }

public DataTemplate? UserSettingsTemplate { get; set; }
public DataTemplate? GuildSettingsTemplate { get; set; }

public DataTemplate? UserSettingsTemplate { get; set; }

/// <inheritdoc/>
protected override DataTemplate? SelectTemplateCore(object item, DependencyObject container)
Expand All @@ -27,6 +29,7 @@ public class SubPageTemplateSelector : DataTemplateSelector
AboutPageViewModel => AboutTemplate,
CreditPageViewModel => CreditTemplate,
DiscordStatusViewModel => DiscordStatusTemplate,
GuildSettingsPageViewModel => GuildSettingsTemplate,
UserSettingsPageViewModel => UserSettingsTemplate,
_ => null,
};
Expand Down
9 changes: 9 additions & 0 deletions src/Quarrel/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,15 @@
<data name="Guilds/Home" xml:space="preserve">
<value>Home</value>
</data>
<data name="GuildSettings/PersonalSettings" xml:space="preserve">
<value>Personal Settings</value>
</data>
<data name="GuildSettings/ServerSettings" xml:space="preserve">
<value>Server Settings</value>
</data>
<data name="GuildSettings/UserManagement" xml:space="preserve">
<value>User Management</value>
</data>
<data name="InfoMessage/Call" xml:space="preserve">
<value>{author} started a call</value>
</data>
Expand Down
Loading

0 comments on commit 82eb9de

Please sign in to comment.