|
| 1 | +'use client'; |
| 2 | + |
| 3 | +import { useNotificationStatus } from '@stream-io/feeds-react-sdk'; |
| 4 | +import { type PropsWithChildren } from 'react'; |
| 5 | +import { FollowSuggestions } from './components/FollowSuggestions'; |
| 6 | +import { useOwnFeedsContext } from './own-feeds-context'; |
| 7 | +import { SearchInput } from './components/utility/SearchInput'; |
| 8 | +import { NavLink } from './components/utility/NavLink'; |
| 9 | + |
| 10 | +export const AppSkeleton = ({ children }: PropsWithChildren) => { |
| 11 | + const { ownNotifications } = useOwnFeedsContext(); |
| 12 | + const notificationStatus = useNotificationStatus(ownNotifications); |
| 13 | + const unreadCount = notificationStatus?.unread ?? 0; |
| 14 | + |
| 15 | + return ( |
| 16 | + <div className="drawer h-full max-h-full lg:drawer-open"> |
| 17 | + <input id="my-drawer" type="checkbox" className="drawer-toggle" /> |
| 18 | + <div className="drawer-content max-h-full min-h-0 h-full max-h-full flex flex-col gap-1 items-center justify-center"> |
| 19 | + <nav className="hidden md:flex lg:hidden navbar w-full bg-base-100"> |
| 20 | + <div className="flex-none lg:hidden"> |
| 21 | + <label |
| 22 | + htmlFor="my-drawer" |
| 23 | + className="drawer-button btn btn-square btn-ghost" |
| 24 | + > |
| 25 | + <span className="material-symbols-outlined">menu</span> |
| 26 | + </label> |
| 27 | + </div> |
| 28 | + </nav> |
| 29 | + <div className="h-full max-h-full overflow-y-auto w-full md:p-10 p-4 flex flex-row gap-10 items-start justify-center"> |
| 30 | + <div className="h-full max-h-full lg:w-[70%] w-full flex flex-col items-center justify-start"> |
| 31 | + <div className="w-full h-full max-h-full fle flex-col items-center justify-center"> |
| 32 | + {children} |
| 33 | + </div> |
| 34 | + </div> |
| 35 | + <div className="lg:flex hidden w-[30%] flex-col items-stretch justify-start gap-4"> |
| 36 | + <SearchInput /> |
| 37 | + <FollowSuggestions /> |
| 38 | + </div> |
| 39 | + </div> |
| 40 | + <Dock hasUnreadNotifications={unreadCount > 0} /> |
| 41 | + </div> |
| 42 | + <DrawerSide unreadCount={unreadCount} /> |
| 43 | + </div> |
| 44 | + ); |
| 45 | +}; |
| 46 | + |
| 47 | +const DrawerSide = ({ unreadCount }: { unreadCount: number }) => { |
| 48 | + return ( |
| 49 | + <div className="drawer-side"> |
| 50 | + <label |
| 51 | + htmlFor="my-drawer" |
| 52 | + aria-label="close sidebar" |
| 53 | + className="drawer-overlay" |
| 54 | + ></label> |
| 55 | + <ul className="menu bg-base-200 min-h-full w-60 p-4"> |
| 56 | + <li> |
| 57 | + <HomeLink /> |
| 58 | + </li> |
| 59 | + <li> |
| 60 | + <PopularLink /> |
| 61 | + </li> |
| 62 | + <li> |
| 63 | + <NotificationsLink> |
| 64 | + {unreadCount > 0 && ( |
| 65 | + <div className="badge badge-primary badge-xs position-absolute left-23"> |
| 66 | + {unreadCount} |
| 67 | + </div> |
| 68 | + )} |
| 69 | + </NotificationsLink> |
| 70 | + </li> |
| 71 | + <li> |
| 72 | + <BookmarksLink /> |
| 73 | + </li> |
| 74 | + <li> |
| 75 | + <ProfileLink /> |
| 76 | + </li> |
| 77 | + </ul> |
| 78 | + </div> |
| 79 | + ); |
| 80 | +}; |
| 81 | + |
| 82 | +const Dock = ({ |
| 83 | + hasUnreadNotifications, |
| 84 | +}: { |
| 85 | + hasUnreadNotifications: boolean; |
| 86 | +}) => { |
| 87 | + return ( |
| 88 | + <div className="dock md:hidden w-full"> |
| 89 | + <button> |
| 90 | + <HomeLink /> |
| 91 | + </button> |
| 92 | + |
| 93 | + <button> |
| 94 | + <ExploreLink /> |
| 95 | + </button> |
| 96 | + |
| 97 | + <button> |
| 98 | + <AddLink /> |
| 99 | + </button> |
| 100 | + |
| 101 | + <button> |
| 102 | + <NotificationsLink> |
| 103 | + {hasUnreadNotifications && ( |
| 104 | + <div className="badge badge-primary h-[0.25rem] w-[0.25rem] p-[0.25rem] absolute left-[70%] top-[5%]" /> |
| 105 | + )} |
| 106 | + </NotificationsLink> |
| 107 | + </button> |
| 108 | + |
| 109 | + <button> |
| 110 | + <ProfileLink /> |
| 111 | + </button> |
| 112 | + </div> |
| 113 | + ); |
| 114 | +}; |
| 115 | + |
| 116 | +const HomeLink = () => { |
| 117 | + return <NavLink href="/home" icon="home" label="Home" />; |
| 118 | +}; |
| 119 | + |
| 120 | +const PopularLink = () => { |
| 121 | + return <NavLink href="/explore" icon="whatshot" label="Popular" />; |
| 122 | +}; |
| 123 | + |
| 124 | +const ExploreLink = () => { |
| 125 | + return <NavLink href="/explore" icon="search" />; |
| 126 | +}; |
| 127 | + |
| 128 | +const NotificationsLink = ({ children }: { children?: React.ReactNode }) => { |
| 129 | + return ( |
| 130 | + <NavLink href="/notifications" icon="notifications" label="Notifications"> |
| 131 | + {children} |
| 132 | + </NavLink> |
| 133 | + ); |
| 134 | +}; |
| 135 | + |
| 136 | +const ProfileLink = () => { |
| 137 | + return <NavLink href="/profile" icon="account_circle" label="Profile" />; |
| 138 | +}; |
| 139 | + |
| 140 | +const AddLink = () => { |
| 141 | + return <NavLink href="/activity-compose" icon="add" label="Add" />; |
| 142 | +}; |
| 143 | + |
| 144 | +const BookmarksLink = () => { |
| 145 | + return <NavLink href="/bookmarks" icon="bookmark" label="Bookmarks" />; |
| 146 | +}; |
0 commit comments