Skip to content

Commit 721f6a0

Browse files
authored
doc(Chat): update chat sample (#5759)
1 parent 552dd1d commit 721f6a0

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

src/BootstrapBlazor.Server/Components/Pages/Chats.razor

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77

88
<h4>@Localizer["ChatsDescription"]</h4>
99

10+
<HeadContent>
11+
<style>
12+
.bb-ad {
13+
display: none;
14+
}
15+
</style>
16+
</HeadContent>
17+
1018
<DemoBlock Title="@Localizer["ChatNormalTitle"]" Introduction="@Localizer["ChatNormalIntro"]" Name="Normal" ShowCode="false">
1119
<div class="chat-title">@Localizer["ChatUserTitle"]</div>
1220
<div class="chat-body">
@@ -47,7 +55,7 @@
4755
}
4856
</div>
4957
<div class="chat-footer">
50-
<label class="chat-info">@((MarkupString)Localizer["ChatInfo", _currentCount, _totalCount].Value)</label>
58+
<label class="chat-info">@((MarkupString)Localizer["ChatInfo", _currentCount, TotalCount].Value)</label>
5159
<div class="d-flex">
5260
<Textarea Id="@Id" class="chat-footer-tx" rows="3" @bind-Value="@Context" PlaceHolder="Type user query here. (Shift + Enter for new line)"></Textarea>
5361
<div class="chat-buttons">

src/BootstrapBlazor.Server/Components/Pages/Chats.razor.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,10 @@ public partial class Chats
3232
.AddClass("msg-stack-assistant", role == ChatRole.Assistant)
3333
.Build();
3434

35-
private static readonly ConcurrentDictionary<string, int> _cache = new();
36-
35+
private const int TotalCount = 50;
36+
private static readonly ConcurrentDictionary<string, int> Cache = new();
3737
private string? _code;
38-
39-
private readonly int _totalCount = 50;
40-
4138
private int _currentCount;
42-
4339
private bool _isDisabled;
4440

4541
/// <summary>
@@ -51,7 +47,7 @@ protected override async Task OnInitializedAsync()
5147
await base.OnInitializedAsync();
5248

5349
_code = await GetFingerCodeAsync();
54-
_currentCount = _cache.GetOrAdd(_code, key => _totalCount);
50+
_currentCount = Cache.GetOrAdd(_code, key => TotalCount);
5551
_isDisabled = _currentCount < 1;
5652
}
5753

@@ -112,7 +108,7 @@ private async Task GetCompletionsAsync()
112108
await Task.Delay(100);
113109
if (!string.IsNullOrEmpty(_code))
114110
{
115-
_currentCount = _cache.AddOrUpdate(_code, key => _totalCount, (key, number) => number - 1);
111+
_currentCount = Cache.AddOrUpdate(_code, key => TotalCount, (key, number) => number - 1);
116112
_isDisabled = _currentCount < 1;
117113
}
118114
else

src/BootstrapBlazor.Server/Components/Pages/Chats.razor.css

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
.chat-body {
77
min-height: 210px;
8-
max-height: 786px;
8+
max-height: calc(100vh - 441px);
99
overflow-y: auto;
1010
background-color: #faf9f8;
1111
}
@@ -53,6 +53,17 @@
5353
flex: 1;
5454
}
5555

56+
::deep div:has(pre) {
57+
overflow: hidden;
58+
}
59+
60+
::deep pre {
61+
margin-bottom: 1rem;
62+
border: 1px solid #ddd;
63+
border-radius: var(--bs-border-radius);
64+
padding: 4px 10px;
65+
}
66+
5667
.chat-auth {
5768
margin-top: .5rem;
5869
}

0 commit comments

Comments
 (0)