|
1 | 1 | @page "/posts/create"
|
2 | 2 | @inject IPostsService PostsService
|
3 |
| -@inject IEventsService EventsService |
4 | 3 | @inject IIdentityService IdentityService
|
5 | 4 | @inject IMediaFilesService MediaFilesService
|
6 | 5 | @inject NavigationManager NavigationManager
|
7 | 6 | @inject IJSRuntime JSRuntime
|
8 | 7 | @using Astravent.Web.Wasm.Areas.Posts.CommandsDto
|
9 | 8 | @using Astravent.Web.Wasm.DTO.Enums.Posts
|
10 | 9 | @using MudBlazor
|
11 |
| -@using System.IO |
12 |
| -@using Microsoft.AspNetCore.Components.Forms |
13 |
| - |
14 |
| -<MudContainer MaxWidth="MaxWidth.Small" Class="pa-4"> |
15 |
| - <MudCard> |
16 |
| - <MudCardHeader> |
17 |
| - <MudText Typo="Typo.h5">Create a New Post</MudText> |
18 |
| - </MudCardHeader> |
19 |
| - <MudCardContent> |
20 |
| - <MudForm @ref="form" @onsubmit="HandleSubmit"> |
21 |
| - <MudTextField @bind-Value="textContent" Label="Description" Multiline="true" Lines="5" FullWidth Immediate="true" Required="true" /> |
22 |
| - <MudMarkdown Value="@textContent" /> |
23 |
| - |
24 |
| - <MudButton Color="Color.Primary" Variant="Variant.Outlined" OnClick="UploadMediaFilesClick" StartIcon="@Icons.Material.Filled.Upload"> |
25 |
| - Upload Media Files |
26 |
| - </MudButton> |
27 |
| - <InputFile id="fileInputMediaFiles" OnChange="@(async e => await UploadMediaFiles(e))" Multiple="true" style="display: none;" accept=".jpeg,.png,.jpg,.mp4,.pdf" /> |
28 |
| - |
29 |
| - @if (mediaFilesPreviews.Any()) |
| 10 | + |
| 11 | +<MudContainer MaxWidth="MaxWidth.Large" Class="pa-4"> |
| 12 | + <MudGrid> |
| 13 | + <!-- Left Side: Post Preview (Public Information) --> |
| 14 | + <MudItem xs="12" md="6"> |
| 15 | + <MudPaper Class="pa-4"> |
| 16 | + <MudText Typo="Typo.h5">Post Preview</MudText> |
| 17 | + @if (postType == PostType.BlogPost) |
30 | 18 | {
|
31 |
| - <MudText Typo="Typo.h6" Class="mt-4">Uploaded Files Preview</MudText> |
32 |
| - <MudGrid> |
33 |
| - @foreach (var filePreview in mediaFilesPreviews) |
34 |
| - { |
35 |
| - <MudItem xs="12" sm="6"> |
36 |
| - <MudCard> |
37 |
| - @if (filePreview.IsImage) |
38 |
| - { |
39 |
| - <MudCardMedia Image="@filePreview.Url" Title="Media Preview" AspectRatio="16:9" /> |
40 |
| - } |
41 |
| - else if (filePreview.IsVideo) |
42 |
| - { |
43 |
| - <MudCardMedia AspectRatio="16:9"> |
44 |
| - <video width="100%" controls> |
45 |
| - <source src="@filePreview.Url" type="@filePreview.ContentType"> |
46 |
| - Your browser does not support the video tag. |
47 |
| - </video> |
48 |
| - </MudCardMedia> |
49 |
| - } |
50 |
| - else if (filePreview.IsPdf) |
51 |
| - { |
52 |
| - <MudCardContent> |
53 |
| - <MudButton Variant="Variant.Outlined" Color="Color.Secondary" StartIcon="@Icons.Material.Filled.PictureAsPdf" OnClick="@(async () => await JSRuntime.InvokeVoidAsync("window.open", filePreview.Url, "_blank"))"> |
54 |
| - View PDF |
55 |
| - </MudButton> |
56 |
| - </MudCardContent> |
57 |
| - } |
58 |
| - </MudCard> |
59 |
| - </MudItem> |
60 |
| - } |
61 |
| - </MudGrid> |
| 19 | + <MudText Typo="Typo.h6" Class="mt-2">Title: @title</MudText> |
| 20 | + <MudMarkdown MarkupContent="@textContent" /> |
62 | 21 | }
|
63 |
| - |
64 |
| - <MudSelect T="string" @bind-Value="state" Label="State" Required="true" Class="mt-4"> |
65 |
| - <MudSelectItem T="string" Value="@("InDraft")">Draft</MudSelectItem> |
66 |
| - <MudSelectItem T="string" Value="@("Published")">Published</MudSelectItem> |
67 |
| - </MudSelect> |
68 |
| - |
69 |
| - <MudSelect T="string" @bind-Value="visibility" Label="Visibility" Required="true" Class="mt-4"> |
70 |
| - <MudSelectItem T="string" Value="@("Visible")">Visible</MudSelectItem> |
71 |
| - <MudSelectItem T="string" Value="@("Invisible")">Invisible</MudSelectItem> |
72 |
| - </MudSelect> |
73 |
| - |
74 |
| - <MudDatePicker @bind-Date="publishDate" Label="Publish Date" Class="mt-4" /> |
75 |
| - |
76 |
| - <MudStack Direction="Row" Spacing="2" Class="mt-4"> |
77 |
| - <MudButton Color="Color.Primary" Variant="Variant.Filled" Type="Submit" StartIcon="@Icons.Material.Filled.Check">Create Post</MudButton> |
78 |
| - <MudButton Color="Color.Secondary" Variant="Variant.Outlined" OnClick="HandleCancel" StartIcon="@Icons.Material.Filled.Cancel">Cancel</MudButton> |
79 |
| - </MudStack> |
80 |
| - </MudForm> |
81 |
| - </MudCardContent> |
82 |
| - </MudCard> |
| 22 | + else if (postType == PostType.SocialPost) |
| 23 | + { |
| 24 | + <MudMarkdown MarkupContent="@textContent" /> |
| 25 | + @if (mediaFilesPreviews.Any()) |
| 26 | + { |
| 27 | + <MudText Typo="Typo.h6" Class="mt-4">Uploaded Files</MudText> |
| 28 | + <MudGrid> |
| 29 | + @foreach (var filePreview in mediaFilesPreviews) |
| 30 | + { |
| 31 | + <MudItem xs="12" sm="6"> |
| 32 | + <MudCard> |
| 33 | + @if (filePreview.IsImage) |
| 34 | + { |
| 35 | + <MudCardMedia Image="@filePreview.Url" Title="Media Preview" AspectRatio="16:9" /> |
| 36 | + } |
| 37 | + else if (filePreview.IsVideo) |
| 38 | + { |
| 39 | + <MudCardMedia AspectRatio="16:9"> |
| 40 | + <video width="100%" controls> |
| 41 | + <source src="@filePreview.Url" type="@filePreview.ContentType"> |
| 42 | + Your browser does not support the video tag. |
| 43 | + </video> |
| 44 | + </MudCardMedia> |
| 45 | + } |
| 46 | + else if (filePreview.IsPdf) |
| 47 | + { |
| 48 | + <MudCardContent> |
| 49 | + <MudButton Variant="Variant.Outlined" Color="Color.Secondary" StartIcon="@Icons.Material.Filled.PictureAsPdf" OnClick="@(async () => await JSRuntime.InvokeVoidAsync("window.open", filePreview.Url, "_blank"))"> |
| 50 | + View PDF |
| 51 | + </MudButton> |
| 52 | + </MudCardContent> |
| 53 | + } |
| 54 | + </MudCard> |
| 55 | + </MudItem> |
| 56 | + } |
| 57 | + </MudGrid> |
| 58 | + } |
| 59 | + } |
| 60 | + </MudPaper> |
| 61 | + </MudItem> |
| 62 | + |
| 63 | + <!-- Right Side: Post Configuration (Administration) --> |
| 64 | + <MudItem xs="12" md="6"> |
| 65 | + <MudPaper Class="pa-4"> |
| 66 | + <MudText Typo="Typo.h5">Post Configuration</MudText> |
| 67 | + <MudForm @ref="form" @onsubmit="HandleSubmit"> |
| 68 | + <!-- Post Type Selection --> |
| 69 | + <MudSelect T="PostType" @bind-Value="postType" Label="Post Type" Required="true" FullWidth Class="mt-2"> |
| 70 | + <MudSelectItem T="PostType" Value="PostType.BlogPost">Blog Post</MudSelectItem> |
| 71 | + <MudSelectItem T="PostType" Value="PostType.SocialPost">Social Post</MudSelectItem> |
| 72 | + </MudSelect> |
| 73 | + |
| 74 | + <!-- Blog Post Specific Fields --> |
| 75 | + @if (postType == PostType.BlogPost) |
| 76 | + { |
| 77 | + <MudText Typo="Typo.subtitle1" Class="mt-4">Blog Post Details</MudText> |
| 78 | + <MudTextField @bind-Value="title" Label="Post Title" FullWidth Immediate="true" Required="true" /> |
| 79 | + |
| 80 | + <!-- Custom MarkdownEditor for Blog Post Content --> |
| 81 | + <MarkdownEditor @bind-MarkdownText="textContent" /> |
| 82 | + |
| 83 | + <MudSelect T="PostContext" @bind-Value="postContext" Label="Post Context" Required="true" FullWidth Class="mt-4"> |
| 84 | + <MudSelectItem T="PostContext" Value="PostContext.UserPage">User Page</MudSelectItem> |
| 85 | + <MudSelectItem T="PostContext" Value="PostContext.OrganizationPage">Organization Page</MudSelectItem> |
| 86 | + <MudSelectItem T="PostContext" Value="PostContext.EventPage">Event Page</MudSelectItem> |
| 87 | + </MudSelect> |
| 88 | + } |
| 89 | + |
| 90 | + <!-- Social Post Specific Fields --> |
| 91 | + @if (postType == PostType.SocialPost) |
| 92 | + { |
| 93 | + <MudText Typo="Typo.subtitle1" Class="mt-4">Social Post Details</MudText> |
| 94 | + <MudTextField @bind-Value="textContent" Label="Description" Multiline="true" Lines="5" FullWidth Immediate="true" Required="true" /> |
| 95 | + <MudButton Color="Color.Primary" Variant="Variant.Outlined" OnClick="UploadMediaFilesClick" StartIcon="@Icons.Material.Filled.Upload" Class="mt-4"> |
| 96 | + Upload Media Files |
| 97 | + </MudButton> |
| 98 | + <InputFile id="fileInputMediaFiles" OnChange="@(async e => await UploadMediaFiles(e))" Multiple="true" style="display: none;" accept=".jpeg,.png,.jpg,.mp4,.pdf" /> |
| 99 | + } |
| 100 | + |
| 101 | + <!-- Post State and Visibility --> |
| 102 | + <MudSelect T="string" @bind-Value="state" Label="State" Required="true" FullWidth Class="mt-4"> |
| 103 | + <MudSelectItem T="string" Value="@("InDraft")">Draft</MudSelectItem> |
| 104 | + <MudSelectItem T="string" Value="@("Published")">Published</MudSelectItem> |
| 105 | + </MudSelect> |
| 106 | + |
| 107 | + <MudSelect T="string" @bind-Value="visibility" Label="Visibility" Required="true" FullWidth Class="mt-4"> |
| 108 | + <MudSelectItem T="string" Value="@("Visible")">Visible</MudSelectItem> |
| 109 | + <MudSelectItem T="string" Value="@("Invisible")">Invisible</MudSelectItem> |
| 110 | + </MudSelect> |
| 111 | + |
| 112 | + <MudDatePicker @bind-Date="publishDate" Label="Publish Date" Class="mt-4" /> |
| 113 | + |
| 114 | + <MudStack Direction="Row" Spacing="2" Class="mt-4"> |
| 115 | + <MudButton Color="Color.Primary" Variant="Variant.Filled" Type="Submit" StartIcon="@Icons.Material.Filled.Check">Create Post</MudButton> |
| 116 | + <MudButton Color="Color.Secondary" Variant="Variant.Outlined" OnClick="HandleCancel" StartIcon="@Icons.Material.Filled.Cancel">Cancel</MudButton> |
| 117 | + </MudStack> |
| 118 | + </MudForm> |
| 119 | + </MudPaper> |
| 120 | + </MudItem> |
| 121 | + </MudGrid> |
83 | 122 | </MudContainer>
|
84 | 123 |
|
85 | 124 | @code {
|
86 | 125 | private MudForm form;
|
87 |
| - private string textContent; |
| 126 | + private string textContent = "## Markdown Content\n"; |
| 127 | + private string title; |
88 | 128 | private List<FilePreview> mediaFilesPreviews = new();
|
89 | 129 | private List<string> uploadedMediaUrls = new List<string>();
|
90 | 130 | private string state = "InDraft";
|
91 | 131 | private string visibility = "Visible";
|
92 | 132 | private DateTime? publishDate = DateTime.Now;
|
93 | 133 | private bool isUploading = false;
|
| 134 | + private PostType postType = PostType.SocialPost; // Default to Social Post |
| 135 | + private PostContext postContext = PostContext.UserPage; // Default context |
94 | 136 |
|
95 | 137 | private async Task UploadMediaFilesClick()
|
96 | 138 | {
|
|
163 | 205 | State = state,
|
164 | 206 | Visibility = visibility,
|
165 | 207 | PublishDate = publishDate,
|
166 |
| - Context = PostContext.UserPage |
| 208 | + Context = postContext // The context now reflects UserPage, OrganizationPage, or EventPage |
167 | 209 | };
|
168 | 210 |
|
169 | 211 | var response = await PostsService.CreatePostAsync(command);
|
|
0 commit comments