@@ -29,6 +29,7 @@ import DeleteConfirmationDialog from './DeleteConfirmationDialog';
2929import Content from './Content' ;
3030import { isFocusableElement , isInputElement , focus } from '../../utils/dom' ;
3131import { FOLDER_FIELDS_TO_FETCH } from '../../utils/fields' ;
32+ import LocalStore from '../../utils/LocalStore' ;
3233import {
3334 isFeatureEnabled ,
3435 withFeatureConsumer ,
@@ -134,9 +135,10 @@ type State = {
134135 sortBy : SortBy ,
135136 sortDirection : SortDirection ,
136137 view : View ,
137- viewMode : ViewMode ,
138138} ;
139139
140+ const localStoreViewMode = 'bce.defaultViewMode' ;
141+
140142class ContentExplorer extends Component < Props , State > {
141143 id : string ;
142144
@@ -156,6 +158,8 @@ class ContentExplorer extends Component<Props, State> {
156158
157159 firstLoad : boolean = true ; // Keeps track of very 1st load
158160
161+ store : LocalStore = new LocalStore ( ) ;
162+
159163 static defaultProps = {
160164 rootFolderId : DEFAULT_ROOT ,
161165 sortBy : FIELD_NAME ,
@@ -248,7 +252,6 @@ class ContentExplorer extends Component<Props, State> {
248252 sortBy,
249253 sortDirection,
250254 view : VIEW_FOLDER ,
251- viewMode : VIEW_MODE_LIST ,
252255 } ;
253256 }
254257
@@ -281,7 +284,7 @@ class ContentExplorer extends Component<Props, State> {
281284 * @return {void }
282285 */
283286 componentDidMount ( ) {
284- const { defaultView , currentFolderId } : Props = this . props ;
287+ const { currentFolderId , defaultView } : Props = this . props ;
285288 this . rootElement = ( ( document . getElementById ( this . id ) : any ) : HTMLElement ) ;
286289 this . appElement = ( ( this . rootElement . firstElementChild : any ) : HTMLElement ) ;
287290
@@ -1249,14 +1252,26 @@ class ContentExplorer extends Component<Props, State> {
12491252 this . setState ( { currentOffset : newOffset } , this . refreshCollection ) ;
12501253 } ;
12511254
1255+ getViewMode = ( ) : ViewMode => {
1256+ const { features } : Props = this . props ;
1257+ const viewModePreference = this . store . getItem ( localStoreViewMode ) ;
1258+ const isGridViewEnabled = isFeatureEnabled ( features , 'contentExplorer.gridView.enabled' ) ;
1259+ return isGridViewEnabled && viewModePreference ? viewModePreference : VIEW_MODE_LIST ;
1260+ } ;
1261+
12521262 /**
12531263 * Change the current view mode
12541264 *
12551265 * @param {ViewMode } viewMode - the new view mode
12561266 * @return {void }
12571267 */
12581268 changeViewMode = ( viewMode : ViewMode ) : void => {
1259- this . setState ( { viewMode } ) ;
1269+ const { features } : Props = this . props ;
1270+
1271+ if ( isFeatureEnabled ( features , 'contentExplorer.gridView.enabled' ) ) {
1272+ this . store . setItem ( localStoreViewMode , viewMode ) ;
1273+ this . forceUpdate ( ) ;
1274+ }
12601275 } ;
12611276
12621277 /**
@@ -1302,7 +1317,6 @@ class ContentExplorer extends Component<Props, State> {
13021317
13031318 const {
13041319 view,
1305- viewMode,
13061320 rootName,
13071321 currentCollection,
13081322 currentPageSize,
@@ -1325,6 +1339,8 @@ class ContentExplorer extends Component<Props, State> {
13251339 const allowUpload : boolean = canUpload && ! ! can_upload ;
13261340 const allowCreate : boolean = canCreateNewFolder && ! ! can_upload ;
13271341
1342+ const viewMode = this . getViewMode ( ) ;
1343+
13281344 /* eslint-disable jsx-a11y/no-static-element-interactions */
13291345 /* eslint-disable jsx-a11y/no-noninteractive-tabindex */
13301346 return (
0 commit comments