Skip to content

Commit

Permalink
feat(display): move ShouldRender and ShouldRenderNext to block instea…
Browse files Browse the repository at this point in the history
…d of descriptor
  • Loading branch information
SonicGD committed Sep 8, 2021
1 parent 2433587 commit 96055b7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
7 changes: 0 additions & 7 deletions src/Sitko.Blockly.AntDesign/Blocks/AntCutBlockDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Sitko.Blockly.AntDesignComponents.Forms.Blocks;
using Sitko.Blockly.Blazor;
using Sitko.Blockly.Blocks;
using Sitko.Blockly.Display;
using Sitko.Core.App.Localization;

namespace Sitko.Blockly.AntDesignComponents.Blocks
Expand All @@ -15,11 +14,5 @@ public AntCutBlockDescriptor(ILocalizationProvider<CutBlock> localizationProvide
}

public override RenderFragment Icon => builder => builder.AddIcon("cut");

public bool ShouldRender(BlockListContext context, ContentBlock block) =>
context.Mode == BlocksListMode.Preview;

public bool ShouldRenderNext(BlockListContext context, ContentBlock block) =>
context.Mode == BlocksListMode.Full;
}
}
4 changes: 2 additions & 2 deletions src/Sitko.Blockly.AntDesign/Display/AntBlocksList.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
@foreach (var block in Blocks)
{
var blockDescriptor = Blockly.GetBlockDescriptor(block.GetType());
if (blockDescriptor.ShouldRender(Context!, block))
if (block.ShouldRender(Options))
{
var className = $"blockly blockly-{block.GetType().Name.ToLowerInvariant()} {blockDescriptor.DisplayComponentCssClass}";
<div class="@className" @key="block.Id">
@(RenderBlock(blockDescriptor, block))
</div>
}
if (!blockDescriptor.ShouldRenderNext(Context!, block))
if (!block.ShouldRenderNext(Options))
{
break;
}
Expand Down
3 changes: 0 additions & 3 deletions src/Sitko.Blockly/BlockDescriptor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using Sitko.Blockly.Display;
using Sitko.Core.App.Localization;

namespace Sitko.Blockly
Expand All @@ -9,8 +8,6 @@ public interface IBlockDescriptor
string Title { get; }
Type Type { get; }
string Key { get; }
bool ShouldRender(BlockListContext context, ContentBlock block) => true;
bool ShouldRenderNext(BlockListContext context, ContentBlock block) => true;
}

// ReSharper disable once UnusedTypeParameter
Expand Down
8 changes: 8 additions & 0 deletions src/Sitko.Blockly/Blocks/CutBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@

namespace Sitko.Blockly.Blocks
{
using Display;

[ContentBlockMetadata(2, 1)]
public record CutBlock : ContentBlock

{
public override string ToString() => "";

public string ButtonText { get; set; } = "Read more...";

public override bool ShouldRender(BlocklyListOptions listOptions) =>
listOptions.Mode == BlocksListMode.Preview;

public override bool ShouldRenderNext(BlocklyListOptions options) =>
options.Mode == BlocksListMode.Full;
}

public record CutBlockDescriptor : BlockDescriptor<CutBlock>
Expand Down
5 changes: 5 additions & 0 deletions src/Sitko.Blockly/ContentBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@

namespace Sitko.Blockly
{
using Display;

public abstract record ContentBlock : IOrdered
{
public Guid Id { get; set; } = Guid.NewGuid();
public int Position { get; set; }
public bool Enabled { get; set; } = true;

public override string ToString() => GetType().Name;

public virtual bool ShouldRender(BlocklyListOptions listOptions) => true;
public virtual bool ShouldRenderNext(BlocklyListOptions listOptions) => true;
}
}

0 comments on commit 96055b7

Please sign in to comment.