Skip to content

Commit c32594b

Browse files
committed
🆕 feat: When read and write diary, display time
1 parent 1756996 commit c32594b

File tree

13 files changed

+209
-41
lines changed

13 files changed

+209
-41
lines changed

src/SwashbucklerDiary.Rcl/Components/DialogComponents/DatePickerDialog.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
@namespace SwashbucklerDiary.Rcl.Components
1+
@namespace SwashbucklerDiary.Rcl.Components
22
@inherits DialogComponentBase
33

44
<MDialogExtension MyValue="Visible"
55
MyValueChanged="InternalVisibleChanged"
66
ContentClass="rounded-lg"
77
MaxWidth="420"
88
OnBeforeShowContent="BeforeShowContent">
9-
<MDatePicker @bind-Value="internalDate"
9+
<MDatePicker @bind-Value="internalValue"
1010
Class="rounded-lg pt-4 my-picker"
1111
FullWidth="true"
1212
NoTitle="true"

src/SwashbucklerDiary.Rcl/Components/DialogComponents/DatePickerDialog.razor.cs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,14 @@
1-
using Microsoft.AspNetCore.Components;
1+
using Microsoft.AspNetCore.Components;
22
using OneOf;
33

44
namespace SwashbucklerDiary.Rcl.Components
55
{
66
public partial class DatePickerDialog : DialogComponentBase
77
{
8-
private DateOnly _date = DateOnly.FromDateTime(DateTime.Now);
9-
10-
private DateOnly internalDate;
11-
12-
[Parameter]
13-
public override bool Visible { get; set; }
8+
private DateOnly internalValue;
149

1510
[Parameter]
16-
public DateOnly Value
17-
{
18-
get => _date == default ? DateOnly.FromDateTime(DateTime.Now) : _date;
19-
set => _date = value;
20-
}
11+
public DateOnly Value { get; set; } = DateOnly.FromDateTime(DateTime.Now);
2112

2213
[Parameter]
2314
public EventCallback<DateOnly> ValueChanged { get; set; }
@@ -36,12 +27,12 @@ public DateOnly Value
3627

3728
private void BeforeShowContent()
3829
{
39-
internalDate = Value;
30+
internalValue = Value == default ? DateOnly.FromDateTime(DateTime.Now) : Value;
4031
}
4132

4233
private async Task HandleOnOK()
4334
{
44-
Value = internalDate;
35+
Value = internalValue;
4536
if (ValueChanged.HasDelegate)
4637
{
4738
await ValueChanged.InvokeAsync(Value);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
@namespace SwashbucklerDiary.Rcl.Components
2+
@inherits DialogComponentBase
3+
4+
<MDialogExtension MyValue="Visible"
5+
MyValueChanged="InternalVisibleChanged"
6+
ContentClass="rounded-lg"
7+
Width="@("auto")"
8+
OnBeforeShowContent="BeforeShowContent">
9+
<MTimePicker @bind-Value="internalValue"
10+
Landscape
11+
Format="TimeFormat.Hr24"
12+
Scrollable>
13+
<MSpacer></MSpacer>
14+
<MButton Text="true"
15+
OnClick="HandleOnCancel">
16+
@(I18n.T("Share.Cancel"))
17+
</MButton>
18+
<MButton Text="true"
19+
Color="primary"
20+
OnClick="HandleOnOK">
21+
@(I18n.T("Share.OK"))
22+
</MButton>
23+
</MTimePicker>
24+
</MDialogExtension>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Microsoft.AspNetCore.Components;
2+
3+
namespace SwashbucklerDiary.Rcl.Components
4+
{
5+
public partial class TimePickerDialog : DialogComponentBase
6+
{
7+
private TimeOnly? internalValue;
8+
9+
[Parameter]
10+
public TimeOnly Value { get; set; }
11+
12+
[Parameter]
13+
public EventCallback<TimeOnly> ValueChanged { get; set; }
14+
15+
private void BeforeShowContent()
16+
{
17+
internalValue = Value == default ? TimeOnly.FromDateTime(DateTime.Now) : Value;
18+
}
19+
20+
private async Task HandleOnOK()
21+
{
22+
Value = internalValue ?? default;
23+
if (ValueChanged.HasDelegate)
24+
{
25+
await ValueChanged.InvokeAsync(Value);
26+
}
27+
28+
await InternalVisibleChanged(false);
29+
}
30+
}
31+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using Masa.Blazor.Presets;
2+
using Microsoft.AspNetCore.Components;
3+
using SwashbucklerDiary.Rcl.Essentials;
4+
5+
namespace SwashbucklerDiary.Rcl.Components
6+
{
7+
public class PMobileTimePickerExtension : PMobileTimePicker
8+
{
9+
[Inject]
10+
protected INavigateController NavigateController { get; set; } = default!;
11+
12+
[Parameter]
13+
public bool MyVisible
14+
{
15+
get => base.Visible;
16+
set => SetVisible(value);
17+
}
18+
19+
[Parameter]
20+
public EventCallback<bool> MyVisibleChanged
21+
{
22+
get => base.VisibleChanged;
23+
set => base.VisibleChanged = value;
24+
}
25+
26+
public void Dispose()
27+
{
28+
if (Visible)
29+
{
30+
NavigateController.RemoveHistoryAction(Close);
31+
}
32+
33+
GC.SuppressFinalize(this);
34+
}
35+
36+
private void SetVisible(bool value)
37+
{
38+
if (base.Visible == value)
39+
{
40+
return;
41+
}
42+
43+
base.Visible = value;
44+
if (value)
45+
{
46+
NavigateController.AddHistoryAction(Close);
47+
}
48+
else
49+
{
50+
NavigateController.RemoveHistoryAction(Close);
51+
}
52+
}
53+
54+
private async void Close()
55+
{
56+
MyVisible = false;
57+
if (MyVisibleChanged.HasDelegate)
58+
{
59+
await MyVisibleChanged.InvokeAsync(false);
60+
}
61+
}
62+
}
63+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
@namespace SwashbucklerDiary.Rcl.Components
2+
@inherits DialogComponentBase
3+
4+
<MultiDisplay OnUpdate="UpdateDisplay">
5+
<MobileContent>
6+
<PMobileTimePickerExtension MyVisible="Visible"
7+
MyVisibleChanged="InternalVisibleChanged"
8+
Value="Value"
9+
ValueChanged="InternalValueChanged"
10+
Precision="TimePrecision.Minute">
11+
</PMobileTimePickerExtension>
12+
</MobileContent>
13+
<DesktopContent>
14+
<TimePickerDialog Visible="Visible"
15+
VisibleChanged="InternalVisibleChanged"
16+
Value="Value"
17+
ValueChanged="InternalValueChanged">
18+
</TimePickerDialog>
19+
</DesktopContent>
20+
</MultiDisplay>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Microsoft.AspNetCore.Components;
2+
3+
namespace SwashbucklerDiary.Rcl.Components
4+
{
5+
public partial class MultiTimePicker : DialogComponentBase
6+
{
7+
[Parameter]
8+
public TimeOnly Value { get; set; }
9+
10+
[Parameter]
11+
public EventCallback<TimeOnly> ValueChanged { get; set; }
12+
13+
private async Task UpdateDisplay(bool value)
14+
{
15+
if (Visible)
16+
{
17+
await InternalVisibleChanged(false);
18+
}
19+
}
20+
21+
private async Task InternalValueChanged(TimeOnly value)
22+
{
23+
Value = value;
24+
25+
if (ValueChanged.HasDelegate)
26+
{
27+
await ValueChanged.InvokeAsync(value);
28+
}
29+
}
30+
}
31+
}

src/SwashbucklerDiary.Rcl/Pages/ReadPage.razor

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@page "/read/{id:guid}"
1+
@page "/read/{id:guid}"
22
@inherits ImportantComponentBase
33

44
@if (ShowAppBar)
@@ -61,11 +61,15 @@
6161
ContentStyle="padding-top:0px;">
6262
<div id="screenshot" class="primary-background">
6363
<div class="d-flex align-center px-3">
64-
<span class="text-h6 font-weight-bold">
64+
<span class="text-h6 font-weight-bold mr-3">
6565
@(diary.CreateTime.ToString("d"))
6666
</span>
6767

68-
<span class="ml-5 text-subtitle-2">
68+
<span class="font-weight-bold mr-5">
69+
@(diary.CreateTime.ToString("t"))
70+
</span>
71+
72+
<span class="text-subtitle-2">
6973
@(I18n.ToWeek(diary.CreateTime))
7074
</span>
7175

src/SwashbucklerDiary.Rcl/Pages/Search/SearchPage.razor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ protected override void RegisterWatchers(PropertyWatcher watcher)
4949
base.RegisterWatchers(watcher);
5050

5151
watcher.Watch<List<TagModel>>(nameof(SelectedTags), UpdateDiariesAndStateHasChangedAsync)
52-
.Watch<StringNumber?>(nameof(SelectedWeather), UpdateDiariesAndStateHasChangedAsync)
53-
.Watch<StringNumber?>(nameof(SelectedMood), UpdateDiariesAndStateHasChangedAsync)
52+
.Watch<string?>(nameof(SelectedWeather), UpdateDiariesAndStateHasChangedAsync)
53+
.Watch<string?>(nameof(SelectedMood), UpdateDiariesAndStateHasChangedAsync)
5454
.Watch<string?>(nameof(SelectedLocation), UpdateDiariesAndStateHasChangedAsync)
5555
.Watch<List<MediaResource>>(nameof(SelectedFileTypes), UpdateDiariesAndStateHasChangedAsync)
5656
.Watch<DateFilterForm>(nameof(DateFilterForm), UpdateDiariesAndStateHasChangedAsync);

src/SwashbucklerDiary.Rcl/Pages/Write/WritePage.razor

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,12 @@
5454
ContentStyle="height:100%;">
5555
<div>
5656
<div class="d-flex align-center px-3 flex-wrap">
57-
<button class="d-flex align-center text-h6 font-weight-bold mr-5" @onclick="()=>showCreateTime=true">
57+
<button class="d-flex align-center text-h6 font-weight-bold mr-3" @onclick="()=>showDate=true">
5858
@(diary.CreateTime.ToString("d"))
59-
<MIcon Size="20"
60-
Right>
61-
mdi-pencil-outline
62-
</MIcon>
6359
</button>
64-
60+
<button class="d-flex align-center font-weight-bold mr-5" @onclick="()=>showTime=true">
61+
@(diary.CreateTime.ToString("t"))
62+
</button>
6563
<span class="text-subtitle-2">
6664
@(I18n.ToWeek(diary.CreateTime))
6765
</span>
@@ -171,10 +169,14 @@
171169
@bind-Value="diary.Location">
172170
</SelectLocationDialog>
173171

174-
<MultiDatePicker @bind-Visible="showCreateTime"
172+
<MultiDatePicker @bind-Visible="showDate"
175173
@bind-Value="SelectedDate">
176174
</MultiDatePicker>
177175

176+
<MultiTimePicker @bind-Visible="showTime"
177+
@bind-Value="SelectedTime">
178+
</MultiTimePicker>
179+
178180
<MOverlay Value="overlay"
179181
Opacity="0">
180182
</MOverlay>

0 commit comments

Comments
 (0)