Save unpublished news articles (#31491)
* Add draft saving to news consoles * fix after bui changes * comments + rename vars * no
This commit is contained in:
@@ -47,8 +47,10 @@
|
||||
</Control>
|
||||
<Control HorizontalExpand="True"/>
|
||||
<BoxContainer Orientation="Horizontal">
|
||||
<Button Name="ButtonSaveDraft" SetHeight="32" SetWidth="85"
|
||||
StyleClasses="OpenRight" Text="{Loc news-write-ui-save-text}"/>
|
||||
<Button Name="ButtonPreview" SetHeight="32" SetWidth="85"
|
||||
StyleClasses="OpenRight" Text="{Loc news-write-ui-preview-text}"/>
|
||||
StyleClasses="OpenBoth" Text="{Loc news-write-ui-preview-text}"/>
|
||||
<Button Name="ButtonPublish" SetHeight="32" SetWidth="85" Text="{Loc news-write-ui-publish-text}" Access="Public"/>
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Content.Client.MassMedia.Ui;
|
||||
public sealed partial class ArticleEditorPanel : Control
|
||||
{
|
||||
public event Action? PublishButtonPressed;
|
||||
public event Action<string, string>? ArticleDraftUpdated;
|
||||
|
||||
private bool _preview;
|
||||
|
||||
@@ -45,6 +46,7 @@ public sealed partial class ArticleEditorPanel : Control
|
||||
ButtonPreview.OnPressed += OnPreview;
|
||||
ButtonCancel.OnPressed += OnCancel;
|
||||
ButtonPublish.OnPressed += OnPublish;
|
||||
ButtonSaveDraft.OnPressed += OnDraftSaved;
|
||||
|
||||
TitleField.OnTextChanged += args => OnTextChanged(args.Text.Length, args.Control, SharedNewsSystem.MaxTitleLength);
|
||||
ContentField.OnTextChanged += args => OnTextChanged(Rope.CalcTotalLength(args.TextRope), args.Control, SharedNewsSystem.MaxContentLength);
|
||||
@@ -68,6 +70,9 @@ public sealed partial class ArticleEditorPanel : Control
|
||||
ButtonPublish.Disabled = false;
|
||||
ButtonPreview.Disabled = false;
|
||||
}
|
||||
|
||||
// save draft regardless; they can edit down the length later
|
||||
ArticleDraftUpdated?.Invoke(TitleField.Text, Rope.Collapse(ContentField.TextRope));
|
||||
}
|
||||
|
||||
private void OnPreview(BaseButton.ButtonEventArgs eventArgs)
|
||||
@@ -92,6 +97,12 @@ public sealed partial class ArticleEditorPanel : Control
|
||||
Visible = false;
|
||||
}
|
||||
|
||||
private void OnDraftSaved(BaseButton.ButtonEventArgs eventArgs)
|
||||
{
|
||||
ArticleDraftUpdated?.Invoke(TitleField.Text, Rope.Collapse(ContentField.TextRope));
|
||||
Visible = false;
|
||||
}
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
_preview = false;
|
||||
@@ -100,6 +111,7 @@ public sealed partial class ArticleEditorPanel : Control
|
||||
PreviewLabel.SetMarkup("");
|
||||
TitleField.Text = "";
|
||||
ContentField.TextRope = Rope.Leaf.Empty;
|
||||
ArticleDraftUpdated?.Invoke(string.Empty, string.Empty);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
|
||||
@@ -25,6 +25,9 @@ public sealed class NewsWriterBoundUserInterface : BoundUserInterface
|
||||
_menu.ArticleEditorPanel.PublishButtonPressed += OnPublishButtonPressed;
|
||||
_menu.DeleteButtonPressed += OnDeleteButtonPressed;
|
||||
|
||||
_menu.CreateButtonPressed += OnCreateButtonPressed;
|
||||
_menu.ArticleEditorPanel.ArticleDraftUpdated += OnArticleDraftUpdated;
|
||||
|
||||
SendMessage(new NewsWriterArticlesRequestMessage());
|
||||
}
|
||||
|
||||
@@ -34,7 +37,7 @@ public sealed class NewsWriterBoundUserInterface : BoundUserInterface
|
||||
if (state is not NewsWriterBoundUserInterfaceState cast)
|
||||
return;
|
||||
|
||||
_menu?.UpdateUI(cast.Articles, cast.PublishEnabled, cast.NextPublish);
|
||||
_menu?.UpdateUI(cast.Articles, cast.PublishEnabled, cast.NextPublish, cast.DraftTitle, cast.DraftContent);
|
||||
}
|
||||
|
||||
private void OnPublishButtonPressed()
|
||||
@@ -67,4 +70,14 @@ public sealed class NewsWriterBoundUserInterface : BoundUserInterface
|
||||
|
||||
SendMessage(new NewsWriterDeleteMessage(articleNum));
|
||||
}
|
||||
|
||||
private void OnCreateButtonPressed()
|
||||
{
|
||||
SendMessage(new NewsWriterRequestDraftMessage());
|
||||
}
|
||||
|
||||
private void OnArticleDraftUpdated(string title, string content)
|
||||
{
|
||||
SendMessage(new NewsWriterSaveDraftMessage(title, content));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ using Robust.Client.UserInterface.XAML;
|
||||
using Content.Shared.MassMedia.Systems;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.MassMedia.Ui;
|
||||
|
||||
@@ -16,6 +17,8 @@ public sealed partial class NewsWriterMenu : FancyWindow
|
||||
|
||||
public event Action<int>? DeleteButtonPressed;
|
||||
|
||||
public event Action? CreateButtonPressed;
|
||||
|
||||
public NewsWriterMenu()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
@@ -31,7 +34,7 @@ public sealed partial class NewsWriterMenu : FancyWindow
|
||||
ButtonCreate.OnPressed += OnCreate;
|
||||
}
|
||||
|
||||
public void UpdateUI(NewsArticle[] articles, bool publishEnabled, TimeSpan nextPublish)
|
||||
public void UpdateUI(NewsArticle[] articles, bool publishEnabled, TimeSpan nextPublish, string draftTitle, string draftContent)
|
||||
{
|
||||
ArticlesContainer.Children.Clear();
|
||||
ArticleCount.Text = Loc.GetString("news-write-ui-article-count-text", ("count", articles.Length));
|
||||
@@ -54,6 +57,9 @@ public sealed partial class NewsWriterMenu : FancyWindow
|
||||
|
||||
ButtonCreate.Disabled = !publishEnabled;
|
||||
_nextPublish = nextPublish;
|
||||
|
||||
ArticleEditorPanel.TitleField.Text = draftTitle;
|
||||
ArticleEditorPanel.ContentField.TextRope = new Rope.Leaf(draftContent);
|
||||
}
|
||||
|
||||
protected override void FrameUpdate(FrameEventArgs args)
|
||||
@@ -93,5 +99,6 @@ public sealed partial class NewsWriterMenu : FancyWindow
|
||||
private void OnCreate(BaseButton.ButtonEventArgs buttonEventArgs)
|
||||
{
|
||||
ArticleEditorPanel.Visible = true;
|
||||
CreateButtonPressed?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user