-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Create the User Popup for the cluster map (#129)
* feat: Creating the Cluster Popup and rework ClusterMap to be more sexy to implement 🔞 * feat: Release the UserPopup features on ClusterMaps with docs
- Loading branch information
Showing
23 changed files
with
596 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import Loader from '@components/Loader'; | ||
import useSidebar from '@components/Sidebar'; | ||
import { UserPopup, PopupConsumer, PopupProvider } from '@components/UserPopup'; | ||
import { useClusterViewQuery, User } from '@graphql.d'; | ||
import { isFirstLoading } from '@lib/apollo'; | ||
import { ClusterSidebar } from '../../containers/clusters/ClusterSidebar'; | ||
import { ClusterContainerComponent } from './types'; | ||
|
||
/** | ||
* ClusterContainer component is used to display the cluster map and the cluster | ||
* sidebar. It is used in the cluster page ONLY. This component give facilities | ||
* to display the cluster map with popup management. | ||
* | ||
* Children function parameters: | ||
* - locations: the locations of the cluster and campus | ||
* - showPopup: a function to show the popup | ||
* - hidePopup: a function to hide the popup | ||
* | ||
* Example: | ||
* ``` | ||
<ClusterContainer campus="Paris" cluster={cluster}> | ||
{({ locations, showPopup, hidePopup }) => ( | ||
<div></div> | ||
)} | ||
</ClusterContainer> | ||
* ``` | ||
* | ||
* You can see a fully fonctionnal example on Paris cluster map at | ||
* `src/pages/clusters/paris/[cluster].tsx` | ||
*/ | ||
export const ClusterContainer: ClusterContainerComponent = ({ | ||
campus, | ||
cluster, | ||
children, | ||
}) => { | ||
const { SidebarProvider, PageContainer, PageContent } = useSidebar(); | ||
const { data, networkStatus, error } = useClusterViewQuery({ | ||
variables: { campusName: campus, identifierPrefix: cluster }, | ||
}); | ||
|
||
return ( | ||
<SidebarProvider> | ||
<PageContainer> | ||
<PopupProvider> | ||
<> | ||
<ClusterSidebar campus="paris" cluster={cluster as string} /> | ||
<PageContent | ||
className={ | ||
'p-2 flex-1 flex justify-center min-h-screen items-center' | ||
} | ||
> | ||
{isFirstLoading(networkStatus) && <Loader />} | ||
{error && <div>Error!</div>} | ||
|
||
{!isFirstLoading(networkStatus) && data && ( | ||
<PopupConsumer> | ||
{([state, dispatch]) => ( | ||
<> | ||
{children({ | ||
locations: data.locationsByCluster, | ||
showPopup: (s) => dispatch('SHOW_POPUP', s), | ||
hidePopup: () => dispatch('HIDE_POPUP', null), | ||
})} | ||
<UserPopup | ||
user={state.user as User} | ||
location={state.location} | ||
position={state.position} | ||
onClickOutside={() => dispatch('HIDE_POPUP', null)} | ||
/> | ||
</> | ||
)} | ||
</PopupConsumer> | ||
)} | ||
</PageContent> | ||
</> | ||
</PopupProvider> | ||
</PageContainer> | ||
</SidebarProvider> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { | ||
useCreateFriendshipMutation, | ||
useDeleteFriendshipMutation, | ||
} from '@graphql.d'; | ||
import { Menu, Transition } from '@headlessui/react'; | ||
import classNames from 'classnames'; | ||
import { Fragment } from 'react'; | ||
import { DropdownMenuComponent } from './types'; | ||
|
||
const DropdownMenu: DropdownMenuComponent = ({ | ||
userID, | ||
isFriend = false, | ||
buttonAlwaysShow = false, | ||
refetchQueries = [], | ||
}) => { | ||
const [deleteFriendship] = useDeleteFriendshipMutation(); | ||
const [addFriendship] = useCreateFriendshipMutation(); | ||
|
||
return ( | ||
<div className="text-right absolute top-2 right-2"> | ||
<Menu as="div" className="relative inline-block text-left"> | ||
<Menu.Button className="inline-flex justify-center w-full"> | ||
<i | ||
className={classNames( | ||
'fa-light fa-ellipsis-vertical w-[18px] h-[18px] text-lg rounded-full p-2 hover:text-indigo-800 dark:hover:text-indigo-200 hover:bg-indigo-500/20', | ||
buttonAlwaysShow ? 'visible' : 'invisible group-hover:visible' | ||
)} | ||
></i> | ||
</Menu.Button> | ||
<Transition | ||
as={Fragment} | ||
enter="transition ease-out duration-100" | ||
enterFrom="transform opacity-0 scale-95" | ||
enterTo="transform opacity-100 scale-100" | ||
leave="transition ease-in duration-75" | ||
leaveFrom="transform opacity-100 scale-100" | ||
leaveTo="transform opacity-0 scale-95" | ||
> | ||
<Menu.Items | ||
className={classNames( | ||
'absolute right-0 w-56 mt-2 origin-top-right bg-white dark:bg-slate-900 divide-y divide-gray-100 dark:divide-slate-800 rounded-md shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none', | ||
buttonAlwaysShow ? 'visible' : 'invisible group-hover:visible' | ||
)} | ||
> | ||
<div className="px-1 py-1"> | ||
{!isFriend && ( | ||
<Menu.Item> | ||
<button | ||
onClick={() => { | ||
addFriendship({ | ||
variables: { userID: userID }, | ||
refetchQueries: refetchQueries, | ||
}); | ||
}} | ||
className="hover:bg-indigo-500 hover:text-white text-indigo-500 group flex rounded-md items-center w-full px-2 py-2 text-sm" | ||
> | ||
<i className="fa-light fa-user-plus pr-2"></i> | ||
<span>Add Friend</span> | ||
</button> | ||
</Menu.Item> | ||
)} | ||
{isFriend && ( | ||
<Menu.Item> | ||
<button | ||
onClick={() => { | ||
deleteFriendship({ | ||
variables: { userID: userID }, | ||
refetchQueries: refetchQueries, | ||
}); | ||
}} | ||
className="hover:bg-red-500 hover:text-white text-red-500 group flex rounded-md items-center w-full px-2 py-2 text-sm" | ||
> | ||
<i className="fa-light fa-user-xmark pr-2"></i> | ||
<span>Remove Friend</span> | ||
</button> | ||
</Menu.Item> | ||
)} | ||
</div> | ||
</Menu.Items> | ||
</Transition> | ||
</Menu> | ||
</div> | ||
); | ||
}; | ||
|
||
export default DropdownMenu; |
Oops, something went wrong.