-
Notifications
You must be signed in to change notification settings - Fork 101
frontend: convert sidebar to functional component #2314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
frontend: convert sidebar to functional component #2314
Conversation
17c7cf6
to
e9dd306
Compare
e9dd306
to
276abad
Compare
}; | ||
}; | ||
}, [sidebarStatus]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this whole effect could probably become a hook, but keeping it here for now to not have too many changes.
This is nice but there will be some conflicts with #2283 and #2308. If you plan more refactorings, let's check first if there will be conflicts in the staging branches to avoid needless rebasing effort. Now that this is done, of course feel free to merge it and I'll try to resolve the conflicts when pulling master to staging-watchonly. |
I think we should refactor and cleanup, before starting new features. Reason that sidebar should be functional is so that we can finally get rid of the share HOC decorators (2 shared stores are left, rates and sidebar state). EDIT: lets wait for bitsurance and watch-only before we merge this PR. I'll rebase it accordingly once that all is merged. |
276abad
to
16e0a10
Compare
rebased |
f550c2c
to
855186d
Compare
rebased |
eb78710
to
855186d
Compare
setKeystores(keystores); | ||
|
||
}); | ||
return subscribeKeystores(setKeystores); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`subscribeKeystore should be called without the return, otherwise the subscription only happens when unmounting the component, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no quiet. But I did a short cut here, so it looks a bit confusing. This is the same as:
const unsubscribeFn = subscribeKeystores(keystores => setKeystores(keystores));
return () => {
unsibscribeFn();
};
the returned function is only called when the dependency-list (2nd arg of useEffect) is changing or on unmount. In this case (with empty deplist) only on unmount.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh looking at the code I see your point, sorry. But I tested it and it seemed to me that the sidebar didn't update when connecting/disconneting a new keystore.. I'll check that again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You were right, it works nicely. Don't know why it seemed different before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want I can also rewrite and store the unsubscribe fn in a variable like I did in the code example, for better readability... but I think we do use the shortcut way in a few other places already... let me know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no no, this is nice!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe a comment would be nice for readability, but I think this is fine either way
</div> | ||
const hidden = sidebarStatus === 'forceHidden'; | ||
const hasOnlyBTCAccounts = accounts.every(({ coinCode }) => isBitcoinOnly(coinCode)); | ||
const accountsByKeystore = getAccountsByKeystore(accounts); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess these don't need a `useEffect' hook as the whole component is re-rendered when the account list changes, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes these lines are currently executed on every render, like before this commit (those lines were just in render function).
But there is some potential for optimization here, as hasOnlyBTCAccounts
and accountsByKeystore
only depend on accounts
. So we probably should move this so that accounts.every(
and getAccountsByKeystore(accounts)
only is executed when accounts
change. This way it would not do the operations on every render.
title={t('accountSummary.title')} | ||
onClick={handleSidebarItemClick}> | ||
<div className={style.single}> | ||
<img draggable={false} src={info} alt={t('sidebar.addAccount')} /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alt text looks wrong
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for catching this, I accidentally re-added during rebase. I'll remove the alt attribute and fixup the last commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
<img draggable={false} src={settings} alt={t('sidebar.settings')} /> | ||
to="/buy/info"> | ||
<div className={style.single}> | ||
<img draggable={false} src={coins} alt={t('sidebar.exchanges')} /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sidebar.exchanges
doesn't seem to exist in the locales file. This was already like this on master, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
855186d
to
c165f87
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tACK! Very nice
Note the Sidebar component is still using share HOC decorator, but this can now be easier replaced with react context. Also remove 2 unused translation strings on image alt attributes that had no corresponding translations.
c165f87
to
a8be91a
Compare
No description provided.