From dc26db28642fb04d436148f62ba580c8f2807df6 Mon Sep 17 00:00:00 2001 From: mantikoros Date: Wed, 10 Aug 2022 12:17:33 -0500 Subject: [PATCH] add salem to sidebar; clean up code --- common/util/array.ts | 16 +++++++ web/components/nav/sidebar.tsx | 87 +++++++++++++++------------------- 2 files changed, 54 insertions(+), 49 deletions(-) diff --git a/common/util/array.ts b/common/util/array.ts index d81edba1..2ad86843 100644 --- a/common/util/array.ts +++ b/common/util/array.ts @@ -1,3 +1,19 @@ export function filterDefined(array: (T | null | undefined)[]) { return array.filter((item) => item !== null && item !== undefined) as T[] } + +export function buildArray( + ...params: (T | T[] | false | undefined | null)[] +) { + const array: T[] = [] + + for (const el of params) { + if (Array.isArray(el)) { + array.push(...el) + } else if (el) { + array.push(el) + } + } + + return array +} diff --git a/web/components/nav/sidebar.tsx b/web/components/nav/sidebar.tsx index d45fdf19..3a3c932f 100644 --- a/web/components/nav/sidebar.tsx +++ b/web/components/nav/sidebar.tsx @@ -30,6 +30,7 @@ import { useUnseenPreferredNotifications } from 'web/hooks/use-notifications' import { PrivateUser } from 'common/user' import { useWindowSize } from 'web/hooks/use-window-size' import { CHALLENGES_ENABLED } from 'common/challenge' +import { buildArray } from 'common/util/array' const logout = async () => { // log out, and then reload the page, in case SSR wants to boot them out @@ -61,42 +62,31 @@ function getMoreNavigation(user?: User | null) { } if (!user) { - if (CHALLENGES_ENABLED) - return [ - { name: 'Challenges', href: '/challenges' }, - { name: 'Charity', href: '/charity' }, - { name: 'Blog', href: 'https://news.manifold.markets' }, - { name: 'Discord', href: 'https://discord.gg/eHQBNBqXuh' }, - { name: 'Twitter', href: 'https://twitter.com/ManifoldMarkets' }, - ] - else - return [ + return buildArray( + CHALLENGES_ENABLED && { name: 'Challenges', href: '/challenges' }, + [ { name: 'Charity', href: '/charity' }, + { + name: 'Salem tournament', + href: 'https://salemcenter.manifold.markets/', + }, { name: 'Blog', href: 'https://news.manifold.markets' }, { name: 'Discord', href: 'https://discord.gg/eHQBNBqXuh' }, { name: 'Twitter', href: 'https://twitter.com/ManifoldMarkets' }, ] + ) } - if (CHALLENGES_ENABLED) - return [ - { name: 'Challenges', href: '/challenges' }, - { name: 'Referrals', href: '/referrals' }, - { name: 'Charity', href: '/charity' }, - { name: 'Send M$', href: '/links' }, - { name: 'Discord', href: 'https://discord.gg/eHQBNBqXuh' }, - { name: 'About', href: 'https://docs.manifold.markets/$how-to' }, - { - name: 'Sign out', - href: '#', - onClick: logout, - }, - ] - else - return [ + return buildArray( + CHALLENGES_ENABLED && { name: 'Challenges', href: '/challenges' }, + [ { name: 'Referrals', href: '/referrals' }, { name: 'Charity', href: '/charity' }, { name: 'Send M$', href: '/links' }, + { + name: 'Salem tournament', + href: 'https://salemcenter.manifold.markets/', + }, { name: 'Discord', href: 'https://discord.gg/eHQBNBqXuh' }, { name: 'About', href: 'https://docs.manifold.markets/$how-to' }, { @@ -105,6 +95,7 @@ function getMoreNavigation(user?: User | null) { onClick: logout, }, ] + ) } const signedOutNavigation = [ @@ -141,29 +132,27 @@ const signedInMobileNavigation = [ ] function getMoreMobileNav() { - return [ - ...(IS_PRIVATE_MANIFOLD - ? [] - : CHALLENGES_ENABLED - ? [ - { name: 'Challenges', href: '/challenges' }, - { name: 'Referrals', href: '/referrals' }, - { name: 'Charity', href: '/charity' }, - { name: 'Send M$', href: '/links' }, - { name: 'Discord', href: 'https://discord.gg/eHQBNBqXuh' }, - ] - : [ - { name: 'Referrals', href: '/referrals' }, - { name: 'Charity', href: '/charity' }, - { name: 'Send M$', href: '/links' }, - { name: 'Discord', href: 'https://discord.gg/eHQBNBqXuh' }, - ]), - { - name: 'Sign out', - href: '#', - onClick: logout, - }, - ] + const signOut = { + name: 'Sign out', + href: '#', + onClick: logout, + } + if (IS_PRIVATE_MANIFOLD) return [signOut] + + return buildArray( + CHALLENGES_ENABLED && { name: 'Challenges', href: '/challenges' }, + [ + { name: 'Referrals', href: '/referrals' }, + { + name: 'Salem tournament', + href: 'https://salemcenter.manifold.markets/', + }, + { name: 'Charity', href: '/charity' }, + { name: 'Send M$', href: '/links' }, + { name: 'Discord', href: 'https://discord.gg/eHQBNBqXuh' }, + ], + signOut + ) } export type Item = {