Skip to content

Commit

Permalink
feat(display): remove entity from block list context cause it's never…
Browse files Browse the repository at this point in the history
… used
  • Loading branch information
SonicGD committed Sep 8, 2021
1 parent 0ff5397 commit c258cca
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 35 deletions.
10 changes: 7 additions & 3 deletions src/Sitko.Blockly.Blazor/Display/BlockComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@

namespace Sitko.Blockly.Blazor.Display
{
public abstract class BlockComponent<TEntity, TBlock, TListOptions> : BaseComponent
where TListOptions : BlazorBlocklyListOptions, new()
public abstract class BlockComponent<TBlock> : BaseComponent
where TBlock : ContentBlock
{
#if NET6_0_OR_GREATER
[EditorRequired]
#endif
[Parameter]
public TBlock Block { get; set; } = null!;
}

public abstract class BlockComponent<TBlock, TListOptions> : BlockComponent<TBlock>
where TListOptions : BlazorBlocklyListOptions, new()
where TBlock : ContentBlock
{
#if NET6_0_OR_GREATER
[EditorRequired]
#endif
[Parameter]
public BlockListContext<TEntity> Context { get; set; } = null!;
public BlockListContext Context { get; set; } = null!;

protected TListOptions ListOptions { get; set; } = new();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Sitko.Blockly.Blazor.Display.Blocks
{
public abstract class
CutBlockComponent<TEntity, TListOptions> : BlockComponent<TEntity, Sitko.Blockly.Blocks.CutBlock, TListOptions>
CutBlockComponent<TListOptions> : BlockComponent<Sitko.Blockly.Blocks.CutBlock, TListOptions>
where TListOptions : BlazorBlocklyListOptions, new()
{
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Sitko.Blockly.Blazor.Display.Blocks
{
public abstract class
FilesBlockComponent<TEntity, TListOptions> : BlockComponent<TEntity, Sitko.Blockly.Blocks.FilesBlock,
FilesBlockComponent<TListOptions> : BlockComponent<Sitko.Blockly.Blocks.FilesBlock,
TListOptions> where TListOptions : BlazorBlocklyListOptions, new()
{
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Sitko.Blockly.Blazor.Display.Blocks
{
public abstract class
GalleryBlockComponent<TEntity, TListOptions> : BlockComponent<TEntity, Sitko.Blockly.Blocks.GalleryBlock,
GalleryBlockComponent<TListOptions> : BlockComponent<Sitko.Blockly.Blocks.GalleryBlock,
TListOptions> where TListOptions : BlazorBlocklyListOptions, new()
{
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Sitko.Blockly.Blazor.Display.Blocks
{
public abstract class
IframeBlockComponent<TEntity, TListOptions> : BlockComponent<TEntity, Sitko.Blockly.Blocks.IframeBlock,
IframeBlockComponent<TListOptions> : BlockComponent<Sitko.Blockly.Blocks.IframeBlock,
TListOptions> where TListOptions : BlazorBlocklyListOptions, new()
{
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace Sitko.Blockly.Blazor.Display.Blocks
{
public abstract class QuoteBlockComponent<TEntity, TListOptions> : BlockComponent<TEntity,
Sitko.Blockly.Blocks.QuoteBlock,
public abstract class QuoteBlockComponent<TListOptions> : BlockComponent<Sitko.Blockly.Blocks.QuoteBlock,
TListOptions> where TListOptions : BlazorBlocklyListOptions, new()
{
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Sitko.Blockly.Blazor.Display.Blocks
{
public abstract class
TextBlockComponent<TEntity, TListOptions> : BlockComponent<TEntity, Sitko.Blockly.Blocks.TextBlock,
TextBlockComponent<TListOptions> : BlockComponent<Sitko.Blockly.Blocks.TextBlock,
TListOptions> where TListOptions : BlazorBlocklyListOptions, new()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Sitko.Blockly.Blazor.Display.Blocks
using Sitko.Blazor.ScriptInjector;

public abstract class
TwitchBlockComponent<TEntity, TListOptions> : BlockComponent<TEntity, Sitko.Blockly.Blocks.TwitchBlock,
TwitchBlockComponent<TListOptions> : BlockComponent<Sitko.Blockly.Blocks.TwitchBlock,
TListOptions> where TListOptions : BlazorBlocklyListOptions, new()
{
protected ElementReference ContainerRef { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Sitko.Blockly.Blazor.Display.Blocks
using Sitko.Blazor.ScriptInjector;

public abstract class
TwitterBlockComponent<TEntity, TListOptions> : BlockComponent<TEntity, Sitko.Blockly.Blocks.TwitterBlock,
TwitterBlockComponent<TListOptions> : BlockComponent<Sitko.Blockly.Blocks.TwitterBlock,
TListOptions> where TListOptions : BlazorBlocklyListOptions, new()
{
protected ElementReference ContainerRef { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Sitko.Blockly.Blazor.Display.Blocks
{
public abstract class
YoutubeBlockComponent<TEntity, TListOptions> : BlockComponent<TEntity, Sitko.Blockly.Blocks.YoutubeBlock,
YoutubeBlockComponent<TListOptions> : BlockComponent<Sitko.Blockly.Blocks.YoutubeBlock,
TListOptions> where TListOptions : BlazorBlocklyListOptions, new()
{
}
Expand Down
28 changes: 10 additions & 18 deletions src/Sitko.Blockly.Blazor/Display/BlocksList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,10 @@ namespace Sitko.Blockly.Blazor.Display
{
using JetBrains.Annotations;

public abstract class BlocksList<TEntity, TOptions> : BaseComponent where TOptions : BlazorBlocklyListOptions, new()
public abstract class BlocksList<TOptions> : BaseComponent where TOptions : BlazorBlocklyListOptions, new()
{
#if NET6_0_OR_GREATER
[EditorRequired]
#endif
[Parameter]
public TEntity Entity { get; set; } = default!;
#if NET6_0_OR_GREATER
[EditorRequired]
#endif
[Parameter]
public string EntityUrl { get; set; } = null!;
#if NET6_0_OR_GREATER
[EditorRequired]
#endif
[Parameter]
public IEnumerable<ContentBlock> EntityBlocks { get; set; } = null!;
Expand Down Expand Up @@ -54,21 +44,23 @@ protected override void Initialize()
{
base.Initialize();
BlockDescriptors = Blockly.Descriptors.ToArray();
Context = new BlockListContext<TEntity>(Entity, EntityUrl, ListOptions.Mode);
if (Context is null)
{
throw new InvalidOperationException(LocalizationProvider["You must provide block list context"]);
}
}

protected BlockListContext<TEntity> Context { get; private set; } = null!;
#if NET6_0_OR_GREATER
[EditorRequired]
#endif
[Parameter]
public BlockListContext? Context { get; set; }

[PublicAPI]
public RenderFragment RenderBlock(IBlazorBlockDescriptor blockDescriptor, ContentBlock block) =>
builder =>
{
var component = blockDescriptor.DisplayComponent;
if (blockDescriptor.DisplayComponent.IsGenericTypeDefinition)
{
component = blockDescriptor.DisplayComponent.MakeGenericType(typeof(TEntity));
}

builder.OpenComponent(0, component);
builder.AddAttribute(1, "Block", block);
builder.AddAttribute(2, "Context", Context);
Expand Down
5 changes: 1 addition & 4 deletions src/Sitko.Blockly/Display/BlockListContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,5 @@ public enum BlocksListMode
Full
}

public record BlockListContext(BlocksListMode Mode);

public record BlockListContext<TEntity>
(TEntity Entity, string EntityUrl, BlocksListMode Mode) : BlockListContext(Mode);
public record BlockListContext(string EntityUrl, BlocksListMode Mode);
}

0 comments on commit c258cca

Please sign in to comment.