Skip to content

Commit

Permalink
🔥 chore: arrange code
Browse files Browse the repository at this point in the history
  • Loading branch information
Yu-Core committed Oct 17, 2023
1 parent a0c1314 commit ffb8334
Show file tree
Hide file tree
Showing 44 changed files with 429 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace SwashbucklerDiary.Components
public partial class PreviewImageDialog : DialogComponentBase, IAsyncDisposable
{
private IJSObjectReference module = default!;

private readonly string Id = $"zoom-image-{Guid.NewGuid()}";

[Inject]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected virtual async Task HandleOnSave(MouseEventArgs _)
var TagModels = new List<TagModel>();
foreach (var item in SelectedTagIds)
{
var TagModel = Tags.FirstOrDefault(it=>it.Id.ToString() == item.ToString());
var TagModel = Tags.FirstOrDefault(it => it.Id.ToString() == item.ToString());
if (TagModel != null)
{
TagModels.Add(TagModel);
Expand All @@ -62,7 +62,7 @@ protected virtual async Task HandleOnSave(MouseEventArgs _)

private void SetValue(bool value)
{
if(_value == value)
if (_value == value)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ namespace SwashbucklerDiary.Components
{
public partial class DiaryCard : MyComponentBase
{
private string? Title;

private string? Text;

private bool ShowMenu;

private List<DynamicListItem> MenuItems = new();
Expand All @@ -28,6 +32,13 @@ protected override void OnInitialized()
base.OnInitialized();
}

protected override void OnParametersSet()
{
Title = GetTitle();
Text = GetText();
base.OnParametersSet();
}

private bool HasTitle => !string.IsNullOrWhiteSpace(Value?.Title);

private bool HasContent => !string.IsNullOrWhiteSpace(Value?.Content);
Expand All @@ -44,22 +55,18 @@ protected override void OnInitialized()

private string? DateFormat => DiaryCardList.DateFormat;

private string? Title => GetTitle();

private string? Text => GetText();

private string TopText()
private string TopText()
=> IsTop ? "Diary.CancelTop" : "Diary.Top";

private string PrivateText()
private string PrivateText()
=> IsPrivate ? "Read.ClosePrivacy" : "Read.OpenPrivacy";

private string PrivateIcon()
private string PrivateIcon()
=> IsPrivate ? "mdi-lock-open-variant-outline" : "mdi-lock-outline";

private string? WeatherIcon =>
string.IsNullOrWhiteSpace(Value.Weather) ? null : IconService.GetWeatherIcon(Value.Weather);

private string? MoodIcon =>
string.IsNullOrWhiteSpace(Value.Mood) ? null : IconService.GetMoodIcon(Value.Mood);

Expand Down Expand Up @@ -103,14 +110,18 @@ private void LoadView()
{
return Value.Content!.Substring(0, index + 1);
}
else
{
return SubText(Value.Content, 0, 200);
}
}

return null;
}

private string? GetText()
{
string text = SubText(Value.Content, 0, 1000);
string text = SubText(Value.Content, 0, 2000);
if (!HasTitle && Title is not null && HasContent)
{
var subText = SubText(text, Title.Length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace SwashbucklerDiary.Components
public partial class MyTextarea : IAsyncDisposable
{
private IJSObjectReference module = default!;

private MTextarea MTextarea = default!;

[Inject]
Expand Down
3 changes: 3 additions & 0 deletions SwashbucklerDiary/IRepository/IBaseRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ namespace SwashbucklerDiary.IRepository
public interface IBaseRepository<T> : ISimpleClient<T> where T : class, new()
{
Task<bool> DeleteAsync();

Task<int> CountAsync();

Task<List<T>> GetListTakeAsync(int count);

Task<List<T>> GetListTakeAsync(int count, Expression<Func<T, bool>> func);
}
}
5 changes: 5 additions & 0 deletions SwashbucklerDiary/IRepository/IDiaryRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ namespace SwashbucklerDiary.IRepository
public interface IDiaryRepository : IBaseRepository<DiaryModel>
{
Task<bool> UpdateTagsAsync(DiaryModel model);

Task<List<TagModel>> GetTagsAsync(Guid id);

Task<bool> UpdateIncludesAsync(DiaryModel model);

Task<bool> ImportAsync(List<DiaryModel> diaries);

Task<List<DateOnly>> GetAllDates();

Task<List<DateOnly>> GetAllDates(Expression<Func<DiaryModel, bool>> func);
}
}
1 change: 1 addition & 0 deletions SwashbucklerDiary/IRepository/ITagRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace SwashbucklerDiary.IRepository
public interface ITagRepository : IBaseRepository<TagModel>
{
Task<TagModel> GetByIdIncludesAsync(dynamic id);

Task<TagModel> GetFirstIncludesAsync(Expression<Func<TagModel, bool>> whereExpression);
}
}
1 change: 1 addition & 0 deletions SwashbucklerDiary/IRepository/IUserStateModelRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace SwashbucklerDiary.IRepository
public interface IUserStateModelRepository : IBaseRepository<UserStateModel>
{
Task<UserStateModel> InsertOrUpdateAsync(AchievementType type);

Task<UserStateModel> InsertOrUpdateAsync(AchievementType type, int count);
}
}
2 changes: 2 additions & 0 deletions SwashbucklerDiary/IServices/IAchievementService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ namespace SwashbucklerDiary.IServices
public interface IAchievementService
{
Task<List<string>> UpdateUserState(AchievementType type);

Task<List<string>> UpdateUserState(AchievementType type, int count);

Task<List<AchievementModel>> GetAchievements();
}
}
13 changes: 13 additions & 0 deletions SwashbucklerDiary/IServices/IAlertService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,31 @@ namespace SwashbucklerDiary.IServices
public interface IAlertService
{
void Initialize(object popupService);

void SetTimeout(int timeout);

Task Alert(string? message);

Task Alert(string? title, string? message);

Task Success(string? message);

Task Success(string? title, string? message);

Task Error(string? message);

Task Error(string? title, string? message);

Task Info(string? message);

Task Info(string? title , string? message);

Task Warning(string? message);

Task Warning(string? title, string? message);

Task StartLoading(bool opacity = true);

Task StopLoading();
}
}
25 changes: 25 additions & 0 deletions SwashbucklerDiary/IServices/IAppDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,66 @@ namespace SwashbucklerDiary.IServices
public interface IAppDataService
{
string GetBackupFileName();

/// <summary>
/// 清除缓存
/// </summary>
void ClearCache();

/// <summary>
/// 获取缓存大小
/// </summary>
/// <returns></returns>
string GetCacheSize();

Task<Stream> BackupDatabase(List<DiaryModel> diaries, bool copyResources);

Task<string?> BackupDatabase(string path,List<DiaryModel> diaries, bool copyResources);

/// <summary>
/// 恢复数据库
/// </summary>
/// <param name="filePath">数据库文件路径</param>
Task<bool> RestoreDatabase(string filePath);

Task<bool> RestoreDatabase(Stream stream);

Task<string> ExportTxtZipFileAsync(List<DiaryModel> diaries);

Task<string> ExportJsonZipFileAsync(List<DiaryModel> diaries);

Task<string> ExportMdZipFileAsync(List<DiaryModel> diaries);

Task<string> ExportDBZipFileAsync(List<DiaryModel> diaries, bool copyResources);

Task<string> ExportXlsxFileAsync(List<DiaryModel> diaries);

Task<bool> ExportTxtZipFileAndSaveAsync(List<DiaryModel> diaries);

Task<bool> ExportJsonZipFileAndSaveAsync(List<DiaryModel> diaries);

Task<bool> ExportMdZipFileAndSaveAsync(List<DiaryModel> diaries);

Task<bool> ExportXlsxFileAndSaveAsync(List<DiaryModel> diaries);

Task<string> CreateCacheFileAsync(string filePath, string contents);

Task<string> CreateCacheFileAsync(string filePath, byte[] contents);

Task<string> CreateAppDataFileAsync(string fn, string filePath);

Task<string> CreateAppDataImageFileAsync(string filePath);

Task<string> CreateAppDataAudioFileAsync(string filePath);

Task<string> CreateAppDataVideoFileAsync(string filePath);

Task<bool> DeleteAppDataFileByFilePathAsync(string filePath);

Task<bool> DeleteAppDataFileByCustomSchemeAsync(string uri);

Task<List<DiaryModel>> ImportJsonFileAsync(string filePath);

string CustomSchemeUriToFilePath(string uri);
}
}
17 changes: 17 additions & 0 deletions SwashbucklerDiary/IServices/IBaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,39 @@ namespace SwashbucklerDiary.IServices
public interface IBaseService<TEntity> where TEntity : class, new()
{
Task<bool> AddAsync(TEntity entity);

Task<bool> AddAsync(List<TEntity> entities);

Task<int> AddReturnIdAsync(TEntity entity);

Task<TEntity> AddReturnEntityAsync(TEntity entity);

Task<bool> DeleteAsync();

Task<bool> DeleteAsync(TEntity entity);

Task<bool> DeleteAsync(Guid id);

Task<bool> DeleteAsync(Expression<Func<TEntity, bool>> func);

Task<bool> UpdateAsync(TEntity entity);

Task<List<TEntity>> QueryAsync();

Task<List<TEntity>> QueryAsync(Expression<Func<TEntity, bool>> func);

Task<List<TEntity>> QueryTakeAsync(int count);

Task<List<TEntity>> QueryTakeAsync(int count, Expression<Func<TEntity, bool>> func);

Task<TEntity> FindAsync(Guid id);

Task<TEntity> FindAsync(Expression<Func<TEntity, bool>> func);

Task<int> CountAsync();

Task<int> CountAsync(Expression<Func<TEntity, bool>> func);

Task<bool> AnyAsync(Expression<Func<TEntity, bool>> func);
}
}
7 changes: 7 additions & 0 deletions SwashbucklerDiary/IServices/IDiaryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@ namespace SwashbucklerDiary.IServices
public interface IDiaryService : IBaseService<DiaryModel>
{
Task<bool> UpdateTagsAsync(DiaryModel model);

Task<List<TagModel>> GetTagsAsync(Guid id);

Task<bool> UpdateIncludesAsync(DiaryModel model);

Task<int> GetWordCount(WordCountType type);

int GetWordCount(List<DiaryModel> diaries, WordCountType type);

Task<bool> ImportAsync(List<DiaryModel> diaries);

Task<List<DateOnly>> GetAllDates();

Task<List<DateOnly>> GetAllDates(Expression<Func<DiaryModel, bool>> func);
}
}
7 changes: 7 additions & 0 deletions SwashbucklerDiary/IServices/II18nService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@ namespace SwashbucklerDiary.IServices
public interface II18nService
{
event Action OnChanged;

CultureInfo Culture { get; }

Dictionary<string, string> Languages { get; }

void Initialize(object i18n);

string T(string? key);

string? T(string? key, bool whenNullReturnKey);

void SetCulture(string culture);

string ToWeek(DateTime? dateTime = null);
}
}
3 changes: 3 additions & 0 deletions SwashbucklerDiary/IServices/IIconService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
public interface IIconService
{
Dictionary<string, string> GetWeatherIcons();

Dictionary<string, string> GetMoodIcons();

string GetWeatherIcon(string key);

string GetMoodIcon(string key);
}
}
9 changes: 9 additions & 0 deletions SwashbucklerDiary/IServices/ILANService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,23 @@ namespace SwashbucklerDiary.IServices
public interface ILANService
{
bool IsConnection();

string GetLocalIPv4();

string GetIPPrefix(string ipAddress);

bool Ping(IPAddress address);

LANDeviceInfo GetLocalLANDeviceInfo();

string GetLocalDeviceName();

DevicePlatformType GetLocalDevicePlatformType();

string GetDevicePlatformTypeIcon(DevicePlatformType platformType);

Task LANSendAsync(List<DiaryModel> diaries, Stream stream, Func<long, long, Task> func);

Task<List<DiaryModel>> LANReceiverAsync(Stream stream, long size, Func<long, long, Task> func);
}
}
Loading

0 comments on commit ffb8334

Please sign in to comment.