1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-06-10 03:35:16 +02:00

fix items pane and logout/login btn

This commit is contained in:
Kushagra Gour 2019-07-17 11:30:39 +05:30
parent 455babbf19
commit 6ffb623ece
3 changed files with 61 additions and 51 deletions

View File

@ -95,20 +95,22 @@ export function MainHeader(props) {
</svg> </svg>
<Trans>Open</Trans> <Trans>Open</Trans>
</button> </button>
{!props.user ? (
<Button <Button
onClick={props.loginBtnHandler} onClick={props.loginBtnHandler}
data-event-category="ui" data-event-category="ui"
data-event-action="loginButtonClick" data-event-action="loginButtonClick"
class="hide-on-login btn btn--dark hint--rounded hint--bottom-left" class="btn btn--dark hint--rounded hint--bottom-left"
> >
<Trans>Login/Signup</Trans> <Trans>Login/Signup</Trans>
</Button> </Button>
) : (
<Button <Button
onClick={props.profileBtnHandler} onClick={props.profileBtnHandler}
data-event-category="ui" data-event-category="ui"
data-event-action="headerAvatarClick" data-event-action="headerAvatarClick"
aria-label={i18n._(t`See profile or Logout`)} aria-label={i18n._(t`See profile or Logout`)}
class="hide-on-logout btn--dark hint--rounded hint--bottom-left" class="btn--dark hint--rounded hint--bottom-left"
> >
<img <img
id="headerAvatarImg" id="headerAvatarImg"
@ -119,6 +121,7 @@ export function MainHeader(props) {
class="main-header__avatar-img" class="main-header__avatar-img"
/> />
</Button> </Button>
)}
</div> </div>
</div> </div>
)} )}

View File

@ -303,11 +303,14 @@ export default class App extends Component {
} }
updateProfileUi() { updateProfileUi() {
if (this.state.user) { this.setState(prevState => {
if (prevState.user) {
document.body.classList.add('is-logged-in'); document.body.classList.add('is-logged-in');
} else { } else {
document.body.classList.remove('is-logged-in'); document.body.classList.remove('is-logged-in');
} }
return null;
});
} }
refreshEditor() { refreshEditor() {
@ -464,23 +467,27 @@ export default class App extends Component {
populateItemsInSavedPane(items) { populateItemsInSavedPane(items) {
// TODO: sort desc. by updation date // TODO: sort desc. by updation date
this.setState({ // this.setState({
savedItems: { ...this.state.savedItems } // savedItems: { ...this.state.savedItems }
}); // });
this.toggleSavedItemsPane(); this.toggleSavedItemsPane();
// HACK: Set overflow after sometime so that the items can animate without getting cropped. // HACK: Set overflow after sometime so that the items can animate without getting cropped.
// setTimeout(() => $('#js-saved-items-wrap').style.overflowY = 'auto', 1000); // setTimeout(() => $('#js-saved-items-wrap').style.overflowY = 'auto', 1000);
} }
toggleSavedItemsPane(shouldOpen) { toggleSavedItemsPane(shouldOpen) {
this.setState({ this.setState(prevState => {
isSavedItemPaneOpen: const isSavedItemPaneOpen =
shouldOpen === undefined ? !this.state.isSavedItemPaneOpen : shouldOpen shouldOpen === undefined ? !prevState.isSavedItemPaneOpen : shouldOpen;
});
document.body.classList[this.state.isSavedItemPaneOpen ? 'add' : 'remove']( document.body.classList[isSavedItemPaneOpen ? 'add' : 'remove'](
'overlay-visible' 'overlay-visible'
); );
return {
isSavedItemPaneOpen
};
});
} }
/** /**
@ -490,17 +497,17 @@ export default class App extends Component {
* @return {promise} Promise. * @return {promise} Promise.
*/ */
async fetchItems(shouldSaveGlobally, shouldFetchLocally) { async fetchItems(shouldSaveGlobally, shouldFetchLocally) {
// HACK: This empty assignment is being used when importing locally saved items
// to cloud, `fetchItems` runs once on account login which clears the
// savedItems object and hence, while merging no saved item matches with itself.
this.state.savedItems = {};
var items = []; var items = [];
const savedItems = {};
items = await itemService.getAllItems(shouldFetchLocally); items = await itemService.getAllItems(shouldFetchLocally);
trackEvent('fn', 'fetchItems', items.length); trackEvent('fn', 'fetchItems', items.length);
if (shouldSaveGlobally) { if (shouldSaveGlobally) {
items.forEach(item => { items.forEach(item => {
this.state.savedItems[item.id] = item; savedItems[item.id] = item;
});
this.setState({
savedItems
}); });
} }
return items; return items;
@ -1178,7 +1185,7 @@ export default class App extends Component {
} }
} }
mergeImportedItems(items) { mergeImportedItems(items, isMergingToCloud = false) {
var existingItemIds = []; var existingItemIds = [];
var toMergeItems = {}; var toMergeItems = {};
const d = deferred(); const d = deferred();
@ -1187,10 +1194,10 @@ export default class App extends Component {
// We can access `savedItems` here because this gets set when user // We can access `savedItems` here because this gets set when user
// opens the saved creations panel. And import option is available // opens the saved creations panel. And import option is available
// inside the saved items panel. // inside the saved items panel.
// HACK: Also when this fn is called for importing locally saved items
// to cloud, `fetchItems` runs once on account login which clears the // When we are merging to cloud, savedItems contains the local items. And if we start matching,
// savedItems object and hence, no match happens for `existingItemIds`. // all items will match with themselves and nothing would import :P
if (savedItems[item.id]) { if (!isMergingToCloud && savedItems[item.id]) {
// Item already exists // Item already exists
existingItemIds.push(item.id); existingItemIds.push(item.id);
} else { } else {
@ -1231,7 +1238,7 @@ export default class App extends Component {
* Called from inside ask-to-import-modal * Called from inside ask-to-import-modal
*/ */
importCreationsAndSettingsIntoApp() { importCreationsAndSettingsIntoApp() {
this.mergeImportedItems(this.oldSavedItems).then(() => { this.mergeImportedItems(this.oldSavedItems, true).then(() => {
trackEvent('fn', 'oldItemsImported'); trackEvent('fn', 'oldItemsImported');
this.dontAskToImportAnymore(); this.dontAskToImportAnymore();
}); });

View File

@ -39,7 +39,7 @@ export const itemService = {
var d = deferred(); var d = deferred();
let itemIds = await this.getUserItemIds(shouldFetchLocally); let itemIds = await this.getUserItemIds(shouldFetchLocally);
itemIds = Object.getOwnPropertyNames(itemIds || {}); itemIds = Object.getOwnPropertyNames(itemIds || {});
log('itemids', itemIds); // log('itemids', itemIds);
if (!itemIds.length) { if (!itemIds.length) {
d.resolve([]); d.resolve([]);