@@ -24,22 +24,38 @@ import { TAB } from './constant'
2424/* eslint-disable-next-line */
2525const log = buildLog ( 'S:WallpaperEditor' )
2626
27- const WallpaperEditor = T . model ( 'WallpaperEditor' , {
28- tab : T . optional ( T . enumeration ( values ( TAB ) ) , TAB . BUILDIN ) ,
27+ const initWallpaperModalFields = {
2928 wallpaper : T . optional ( T . string , 'green' ) ,
30-
3129 // for gradient colors
3230 hasPattern : T . optional ( T . boolean , true ) ,
3331 hasBlur : T . optional ( T . boolean , false ) ,
3432 direction : T . optional ( T . string , 'bottom' ) ,
33+ }
34+
35+ const InitWallpaper = T . model ( 'WallpaperInit' , initWallpaperModalFields )
36+
37+ const WallpaperEditor = T . model ( 'WallpaperEditor' , {
38+ tab : T . optional ( T . enumeration ( values ( TAB ) ) , TAB . BUILDIN ) ,
39+ ...initWallpaperModalFields ,
40+ initWallpaper : T . optional ( InitWallpaper , { } ) ,
3541} )
3642 . views ( ( self ) => ( {
3743 get curCommunity ( ) : TCommunity {
3844 const root = getParent ( self ) as TRootStore
3945
4046 return toJS ( root . viewing . community )
4147 } ,
48+ get isTouched ( ) : boolean {
49+ const slf = self as TStore
50+ const init = slf . initWallpaper
4251
52+ return (
53+ self . wallpaper !== init . wallpaper ||
54+ self . hasPattern !== init . hasPattern ||
55+ self . hasBlur !== init . hasBlur ||
56+ self . direction !== init . direction
57+ )
58+ } ,
4359 get patternWallpapers ( ) : Record < string , TWallpaper > {
4460 const slf = self as TStore
4561 const wallpapers = clone ( PATTERN_WALLPAPER )
@@ -101,6 +117,16 @@ const WallpaperEditor = T.model('WallpaperEditor', {
101117 } ,
102118 } ) )
103119 . actions ( ( self ) => ( {
120+ rollbackEdit ( ) : void {
121+ const slf = self as TStore
122+ const init = slf . initWallpaper
123+
124+ self . wallpaper = init . wallpaper
125+ self . hasPattern = init . hasPattern
126+ self . hasBlur = init . hasBlur
127+ self . direction = init . direction
128+ } ,
129+
104130 mark ( sobj : Record < string , unknown > ) : void {
105131 markStates ( sobj , self )
106132 } ,
0 commit comments