From cf0307af0fb40ac3c0806a806ff8a091c78dd4aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Wed, 30 Mar 2022 17:37:30 +0200 Subject: [PATCH] typescript, ThumbNavigationLink component MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- ..._with_counter.js => icon_with_counter.tsx} | Bin 644 -> 665 bytes .../components/thumb_navigation-link.tsx | 57 ++++++++++++++ app/soapbox/components/thumb_navigation.js | Bin 5536 -> 0 bytes app/soapbox/components/thumb_navigation.tsx | 72 ++++++++++++++++++ 4 files changed, 129 insertions(+) rename app/soapbox/components/{icon_with_counter.js => icon_with_counter.tsx} (68%) create mode 100644 app/soapbox/components/thumb_navigation-link.tsx delete mode 100644 app/soapbox/components/thumb_navigation.js create mode 100644 app/soapbox/components/thumb_navigation.tsx diff --git a/app/soapbox/components/icon_with_counter.js b/app/soapbox/components/icon_with_counter.tsx similarity index 68% rename from app/soapbox/components/icon_with_counter.js rename to app/soapbox/components/icon_with_counter.tsx index c7de5f8968cbf6451e8f7916fd89a18c5d320ab0..0e09503cf4161af611e33f1ce0bcb3d12e9ecda6 100644 GIT binary patch delta 193 zcmZo+oyj^;rKLVIuOzi7EipM&!P7H2KQBD9B*Qts6eOsST2Ydkmr|?{l$w}aqURCf z>*H8bQk0ogT9R691LC@5mbvDn=BDPA*eO(VDJUd^G+HU-mF6a;7U=*5GJz)ATPYL+ sb>*d70|knUl9BkeTwI1g6~!eAXjWT6?R0atL3fqi#=WkLlT(-!0OQI-bN~PV delta 150 zcmbQq+QO=mnOl%wRH6`2lwS~1S&&++kXDqRtDs&0zSON7oJ&?;hbNZSCU$!2T};pXsb}orJ#@rl(#|{r&nB3l$n>V1C&Vy=|GmsE6q&; Vnvhu>lv-GtS(KWhGr5FG6#!z3G==~G diff --git a/app/soapbox/components/thumb_navigation-link.tsx b/app/soapbox/components/thumb_navigation-link.tsx new file mode 100644 index 0000000000..ae3c4facbb --- /dev/null +++ b/app/soapbox/components/thumb_navigation-link.tsx @@ -0,0 +1,57 @@ +import classNames from 'classnames'; +import React from 'react'; +import { NavLink, useLocation } from 'react-router-dom'; + +import IconWithCounter from 'soapbox/components/icon_with_counter'; +import { Icon, Text } from 'soapbox/components/ui'; + +interface IThumbNavigationLink { + count?: number, + src: string, + text: string | React.ReactElement, + to: string, + exact?: boolean, + paths?: Array, +} + +const ThumbNavigationLink: React.FC = ({ count, src, text, to, exact, paths }): JSX.Element => { + const location = useLocation(); + + const active = paths + ? paths.some(location.pathname.startsWith) + : (exact + ? location.pathname === to + : location.pathname.startsWith(to)); + + + return ( + + {count !== undefined ? ( + + ) : ( + + )} + + + {text} + + + ); +}; + +export default ThumbNavigationLink; diff --git a/app/soapbox/components/thumb_navigation.js b/app/soapbox/components/thumb_navigation.js deleted file mode 100644 index 021c18ced11e4042d8d9d0c746a3e5d959a5ba92..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5536 zcmd5=ZEqVl4F2w4!F;LCt?kP&bRW`O*CIo)0Bcbs0rsIN0_9G&wcd*->5_DY|NBVk zbni)=HhVFWHm9RVihTHxvdlJxG7zU+>km8=8kVZafZ2td7TBwabV46hvAOuVsbx0! zJU6t^$ealtn@WeGznfR5Symc;m5RO|D>s+^^_=wf)NbKjp)ziaNZt#r`AWd9ZDlTV zlQyQd5Epqa(37r|5=nX67W=@jf0Ox_8Qe&-J}XKiRDX+IoF_$w`+Ov}uoC9H;G3)B z_N2&{a#iorZZ*WC%Ocld_1qXeMb~~uYbQmSlQ|b}zb!5>*15=y4kZd+l3$mx6K!;C zfwauvLfke-98poq_8#>4o#3Wam_Z*Gzo|4b)#0*wO-Dro+CauP=Y|_`QBc-2M4;&r zqSvsU0EL-^@Y$^|&_=*A!KSb3w@MJiv^{TI?lccRF`i^HXER{MM&xHsl6{^o?2&_( z7QR7PT=Vn+HT;H4BlFeUN_irv%`!b?B%$rSsk`YdkF>c-$SASr@7E+&yKTC=EcUIHF zA?^tJqV#^}3LsB}3Z_*=T&Zt;Da>HtI3lWs;tb2cS(t%$3rQyevzB_XAuh31R@Yfz zaRqRk$m^yZMa)o2=Xsq|_PP>8(Tcsn6cGyr1I4& zj<(7LD_}&z#ET+X=<5}m?mDuKt!@3M4u}}rAGV&qgq!(Gb_7P1!X=;)U+Hjc$&{Ht#xz3ttlk{O8zq z8pBr+(;J>M(DE-4v0L2g1?uX;Mv { + const account = useOwnAccount(); + const notificationCount = useAppSelector((state) => state.notifications.unread); + const chatsCount = useAppSelector((state) => state.chats.get('items').reduce((acc: number, curr: any) => acc + Math.min(curr.get('unread', 0), 1), 0)); + // const dashboardCount = useAppSelector((state) => state.admin.openReports.count() + state.admin.awaitingApproval.count()); + const features = getFeatures(useAppSelector((state) => state.instance)); + + return ( +
+ } + to='/' + exact + /> + + } + to='/search' + exact + /> + + {account && ( + } + to='/notifications' + exact + count={notificationCount} + /> + )} + + {account && ( + features.chats ? ( + } + to='/chats' + exact + count={chatsCount} + /> + ) : ( + } + to='/messages' + paths={['/messages', '/conversations']} + /> + ) + )} + + {/* (account && isStaff(account)) && ( + } + to='/admin' + count={dashboardCount} + /> + ) */} +
+ ); +}; + +export default ThumbNavigation;