-
Notifications
You must be signed in to change notification settings - Fork 81
docs(Chat): improve examples to follow style guide #3236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,21 +19,42 @@ To bind the Chat to data, set its `Data` parameter to an `IEnumerable<T>` where | |
>caption Basic data binding | ||
|
||
````Razor | ||
<TelerikChat Data="@Messages" | ||
<TelerikChat Data="@ChatData" | ||
AuthorId="@CurrentUserId" | ||
OnSendMessage="@HandleSendMessage"> | ||
OnSendMessage="@OnChatSendMessage"> | ||
</TelerikChat> | ||
|
||
@code { | ||
private List<ChatMessage> Messages { get; set; } = new List<ChatMessage> | ||
#region Component Parameters | ||
|
||
private List<ChatMessage> ChatData { get; set; } | ||
private string CurrentUserId { get; set; } = "user1"; | ||
|
||
#endregion | ||
|
||
#region Lifecycle Methods | ||
|
||
protected override void OnInitialized() | ||
{ | ||
new ChatMessage { Id = "1", Text = "Hello!", AuthorId = "user1", Timestamp = DateTime.Now.AddMinutes(-5) }, | ||
new ChatMessage { Id = "2", Text = "Hi there!", AuthorId = "user2", Timestamp = DateTime.Now.AddMinutes(-3) } | ||
}; | ||
ChatData = new List<ChatMessage>(); | ||
|
||
for (int i = 1; i <= 2; i++) | ||
{ | ||
ChatData.Add(new ChatMessage | ||
{ | ||
Id = i.ToString(), | ||
Text = i == 1 ? "Hello!" : "Hi there!", | ||
AuthorId = i == 1 ? "user1" : "user2", | ||
Timestamp = DateTime.Now.AddMinutes(-5 + (i * 2)) | ||
}); | ||
} | ||
} | ||
|
||
private string CurrentUserId { get; set; } = "user1"; | ||
|
||
private void HandleSendMessage(ChatSendMessageEventArgs args) | ||
#endregion | ||
|
||
#region Methods | ||
|
||
private void OnChatSendMessage(ChatSendMessageEventArgs args) | ||
{ | ||
var newMessage = new ChatMessage | ||
{ | ||
|
@@ -43,8 +64,12 @@ To bind the Chat to data, set its `Data` parameter to an `IEnumerable<T>` where | |
Timestamp = DateTime.Now | ||
}; | ||
|
||
Messages.Add(newMessage); | ||
ChatData.Add(newMessage); | ||
} | ||
|
||
#endregion | ||
|
||
#region Class Declarations | ||
|
||
public class ChatMessage | ||
{ | ||
|
@@ -72,6 +97,8 @@ To bind the Chat to data, set its `Data` parameter to an `IEnumerable<T>` where | |
|
||
public IEnumerable<FileSelectFileInfo> Attachments { get; set; } = new List<FileSelectFileInfo>(); | ||
} | ||
|
||
#endregion | ||
} | ||
```` | ||
|
||
|
@@ -98,24 +125,44 @@ The Chat component provides field mapping parameters to work with different data | |
The Chat component automatically reflects changes to the bound data collection. You can add, modify, or remove messages programmatically: | ||
|
||
````Razor | ||
<TelerikChat @ref="@Chat1" | ||
Data="@Messages" | ||
TextField="Content" | ||
<TelerikChat @ref="@ChatRef" | ||
Data="@ChatData" | ||
TextField="@nameof(ChatMessage.Content)" | ||
AuthorId="@CurrentUserId" | ||
OnSendMessage="@HandleSendMessage"> | ||
OnSendMessage="@OnChatSendMessage"> | ||
</TelerikChat> | ||
|
||
<div style="margin-top: 20px;"> | ||
<TelerikButton OnClick="@AddSystemMessage">Add System Message</TelerikButton> | ||
<TelerikButton OnClick="@ClearMessages">Clear All Messages</TelerikButton> | ||
<TelerikButton OnClick="@OnAddSystemMessageClick">Add System Message</TelerikButton> | ||
<TelerikButton OnClick="@OnClearMessagesClick">Clear All Messages</TelerikButton> | ||
</div> | ||
|
||
@code { | ||
private TelerikChat<ChatMessage> Chat1 { get; set; } | ||
private List<ChatMessage> Messages { get; set; } = new List<ChatMessage>(); | ||
private string CurrentUserId = "user1"; | ||
#region Component References | ||
|
||
private TelerikChat<ChatMessage> ChatRef { get; set; } | ||
|
||
#endregion | ||
|
||
#region Component Parameters | ||
|
||
private List<ChatMessage> ChatData { get; set; } | ||
private string CurrentUserId { get; set; } = "user1"; | ||
|
||
#endregion | ||
|
||
#region Lifecycle Methods | ||
|
||
protected override void OnInitialized() | ||
{ | ||
ChatData = new List<ChatMessage>(); | ||
} | ||
|
||
#endregion | ||
|
||
#region Methods | ||
|
||
private void HandleSendMessage(ChatSendMessageEventArgs args) | ||
private void OnChatSendMessage(ChatSendMessageEventArgs args) | ||
{ | ||
var newMessage = new ChatMessage | ||
{ | ||
|
@@ -126,14 +173,14 @@ The Chat component automatically reflects changes to the bound data collection. | |
Timestamp = DateTime.Now | ||
}; | ||
|
||
Messages.Add(newMessage); | ||
ChatData.Add(newMessage); | ||
|
||
Chat1?.Refresh(); | ||
ChatRef?.Refresh(); | ||
} | ||
|
||
private void AddSystemMessage() | ||
private void OnAddSystemMessageClick() | ||
{ | ||
Messages.Add(new ChatMessage | ||
ChatData.Add(new ChatMessage | ||
{ | ||
Id = Guid.NewGuid().ToString(), | ||
Content = "System notification: New user joined the chat", | ||
|
@@ -142,25 +189,37 @@ The Chat component automatically reflects changes to the bound data collection. | |
Timestamp = DateTime.Now | ||
}); | ||
|
||
Chat1?.Refresh(); | ||
ChatRef?.Refresh(); | ||
} | ||
|
||
private void ClearMessages() | ||
private void OnClearMessagesClick() | ||
{ | ||
Messages.Clear(); | ||
Chat1?.Refresh(); | ||
ChatData.Clear(); | ||
ChatRef?.Refresh(); | ||
} | ||
|
||
#endregion | ||
|
||
#region Class Declarations | ||
|
||
public class ChatMessage | ||
{ | ||
public string Id { get; set; } | ||
|
||
|
||
public string AuthorId { get; set; } | ||
|
||
public string AuthorName { get; set; } | ||
|
||
public string Content { get; set; } | ||
|
||
public DateTime Timestamp { get; set; } | ||
|
||
public string Status { get; set; } | ||
|
||
public IEnumerable<FileSelectFileInfo> Attachments { get; set; } = new List<FileSelectFileInfo>(); | ||
} | ||
|
||
#endregion | ||
} | ||
```` | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.