66using System . Linq ;
77using System . Text ;
88using System . Threading . Tasks ;
9+ using System . Windows ;
910using System . Windows . Media ;
1011
1112namespace CutCode
@@ -27,10 +28,9 @@ public FavViewModel(IThemeService _themeService, IPageService _pageService, IDat
2728 database = _database ;
2829 AllCodes = database . FavCodes ;
2930 database . FavCodesUpdated += FavCodesUpdated ;
30- }
31-
32- private void FavCodesUpdated ( object sender , EventArgs e ) => AllCodes = database . FavCodes ;
3331
32+ VisChange ( ) ;
33+ }
3434 private void ThemeChanged ( object sender , EventArgs e )
3535 {
3636 SetAppearance ( ) ;
@@ -43,7 +43,54 @@ private void SetAppearance()
4343 searchBarHoverColor = themeService . IsLightTheme ? ColorCon . Convert ( "#D0D1D2" ) : ColorCon . Convert ( "#373737" ) ;
4444 }
4545
46- public ObservableCollection < CodeBoxModel > AllCodes { get ; set ; }
46+ private void FavCodesUpdated ( object sender , EventArgs e )
47+ {
48+ AllCodes = database . FavCodes ;
49+ VisChange ( ) ;
50+ }
51+
52+ private void VisChange ( string text = "You don't have any favourite notes :(" )
53+ {
54+ if ( AllCodes . Count == 0 )
55+ {
56+ labelVis = Visibility . Visible ;
57+ codesVis = Visibility . Hidden ;
58+ emptyLabel = text ;
59+ }
60+ else
61+ {
62+ labelVis = Visibility . Hidden ;
63+ codesVis = Visibility . Visible ;
64+ }
65+ }
66+
67+
68+ private Visibility _labelVis ;
69+ public Visibility labelVis
70+ {
71+ get => _labelVis ;
72+ set => SetAndNotify ( ref _labelVis , value ) ;
73+ }
74+ private Visibility _codesVis ;
75+ public Visibility codesVis
76+ {
77+ get => _codesVis ;
78+ set => SetAndNotify ( ref _codesVis , value ) ;
79+ }
80+
81+ private string _emptyLabel ;
82+ public string emptyLabel
83+ {
84+ get => _emptyLabel ;
85+ set => SetAndNotify ( ref _emptyLabel , value ) ;
86+ }
87+
88+ private ObservableCollection < CodeBoxModel > _AllCodes ;
89+ public ObservableCollection < CodeBoxModel > AllCodes
90+ {
91+ get => _AllCodes ;
92+ set => SetAndNotify ( ref _AllCodes , value ) ;
93+ }
4794
4895 private SolidColorBrush _searchBarBackground ;
4996 public SolidColorBrush searchBarBackground
@@ -86,7 +133,16 @@ public bool IsSearched
86133 public void SearchCommand ( string text )
87134 {
88135 IsSearched = false ;
89- AllCodes = database . SearchCode ( text , "Fav" , AllCodes ) ;
136+ if ( text == "" )
137+ {
138+ AllCodes = database . FavCodes ;
139+ VisChange ( ) ;
140+ }
141+ else
142+ {
143+ AllCodes = database . SearchCode ( text , "Home" ) ;
144+ if ( AllCodes . Count == 0 ) VisChange ( "Not found :(" ) ;
145+ }
90146 IsSearched = true ;
91147 }
92148
0 commit comments