Skip to content

Commit

Permalink
Merge pull request #1032 from tchapgouv/1012-gaufre
Browse files Browse the repository at this point in the history
feat(lasuite): add gaufre element in spacepanel
  • Loading branch information
MarcWadai authored Jun 12, 2024
2 parents 9834864 + b466fe9 commit 5f962bd
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import { UIComponent } from "../../../settings/UIFeature";
import { ThreadsActivityCentre } from "./threads-activity-centre/";
import AccessibleButton from "../elements/AccessibleButton";
import TchapUIFeature from "../../../../../../src/tchap/util/TchapUIFeature"; // :TCHAP: extend-remove-thread-buttons
import TchapGaufre from "../../../../../../src/tchap/components/views/common/Gaufre";

const useSpaces = (): [Room[], MetaSpace[], Room[], SpaceKey] => {
const invites = useEventEmitterState<Room[]>(SpaceStore.instance, UPDATE_INVITED_SPACES, () => {
Expand Down Expand Up @@ -423,6 +424,10 @@ const SpacePanel: React.FC = () => {
{TchapUIFeature.isFeatureActiveForHomeserver("feature_thread") ? <ThreadsActivityCentre displayButtonLabel={!isPanelCollapsed} /> : null}
{/** end :TCHAP: */}
<QuickSettingsButton isPanelCollapsed={isPanelCollapsed} />

{/* :TCHAP: lasuite-gaufre-integration */}
<TchapGaufre isPanelCollapsed={isPanelCollapsed}></TchapGaufre>
{/* end :TCHAP: */}
</nav>
</DragDropContext>
)}
Expand Down
4 changes: 4 additions & 0 deletions modules/tchap-translations/tchap_translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -753,5 +753,9 @@
"location_sharing|live_enable_description": {
"en": "Please note: the history of your shared location will still be accessible to other members of the room even after the functionality is stopped",
"fr": "Attention: l'historique des positions partagées sera accessible aux autres membres du salon meme après avoir arreté le partage"
},
"lasuite_numerique": {
"en": "La suite numérique",
"fr": "La suite numérique"
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"@types/react": "17.0.80"
},
"dependencies": {
"@gouvfr-lasuite/integration": "^1.0.1",
"@matrix-org/olm": "3.2.15",
"@matrix-org/react-sdk-module-api": "^2.3.0",
"gfm.css": "^1.1.2",
Expand Down
6 changes: 6 additions & 0 deletions patches/subtree-modifications.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,11 @@
"src/components/views/rooms/RoomHeader.tsx",
"src/components/views/settings/Notifications.tsx"
]
},
"lasuite-gaufre-integration": {
"issue": "https://github.com/tchapgouv/tchap-web-v4/issues/1012",
"files": [
"src/components/views/spaces/SpacePanel.tsx"
]
}
}
8 changes: 8 additions & 0 deletions res/css/common/_TchapGaufre.pcss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.lasuite-gaufre-tchap {
border: solid 1px #9999fc;
color: #9999fc;

&::before {
background: #9999fc;
}
}
90 changes: 90 additions & 0 deletions src/tchap/components/views/common/Gaufre.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@

import React, { useEffect, useRef, useState } from 'react'
import '@gouvfr-lasuite/integration/dist/css/gaufre.css';

import ContextMenu, { ChevronFace, alwaysAboveRightOf, useContextMenu } from 'matrix-react-sdk/src/components/structures/ContextMenu';
import AccessibleButton from 'matrix-react-sdk/src/components/views/elements/AccessibleButton';
import classNames from 'classnames';
import { _t } from '../../../../languageHandler';
import "../../../../../res/css/common/_TchapGaufre.pcss";

const TchapGaufre: React.FC<{
isPanelCollapsed: boolean;
}> = ({ isPanelCollapsed = false }) => {

const [menuDisplayed, handle, openMenu, closeMenu] = useContextMenu<HTMLDivElement>();
const gaufreListElmRef = useRef<HTMLDivElement | null>(null);
const gaufreContentRef = useRef<HTMLDivElement | null>(null);
const [loading, setLoading] = useState<boolean>(true);

const lasuiteOrigin = "https://integration.lasuite.numerique.gouv.fr"

// Getting the content of the gaufre from la-suite
async function getLasuiteList() {
try {
const res = await fetch(`${lasuiteOrigin}/api/v1/gaufre`);
const html = await res.text();
// replacing the origin urls explicitly by lasuiteOrigin to fetch the images
const updatedHtml = html.replace(/(src=|href=|url\()"\//g, `$1"${lasuiteOrigin}/`);
const parser = new DOMParser();
const popupDocument = parser.parseFromString(updatedHtml, "text/html");

// creating an element to put the content retrieved from lasuite
const gaufreElm = document.createElement("div");
gaufreElm.innerHTML = popupDocument.body.innerHTML;
gaufreListElmRef.current = gaufreElm;
setLoading(false);
} catch (error) {
console.error("Error fetching gaufre list:", error);
setLoading(false);
}
}

useEffect(() => {
getLasuiteList()
}, [])

useEffect(() => {
// only display the content if the content was fetched and the menu opened
if (menuDisplayed && gaufreContentRef.current && gaufreListElmRef.current && !gaufreContentRef.current.innerHTML) {
gaufreContentRef.current.appendChild(gaufreListElmRef.current);
}
}, [menuDisplayed]);


let contextMenu: JSX.Element | undefined;

if (menuDisplayed && handle.current) {
contextMenu = (
<ContextMenu
{...alwaysAboveRightOf(handle.current.getBoundingClientRect(), ChevronFace.None, 16)}
wrapperClassName="mx_QuickSettingsButton_ContextMenuWrapper"
onFinished={closeMenu}
managed={false}
focusLock={true}
>
<div id="tchap-gaufre" ref={gaufreContentRef}>
</div>
</ContextMenu>
);
}

return (
<>
<AccessibleButton
className={classNames(["mx_QuickSettingsButton", { expanded: !isPanelCollapsed }, "lasuite-gaufre-tchap", "lasuite-gaufre-mask"])}
onClick={openMenu}
aria-label={_t("lasuite_numerique")}
title={isPanelCollapsed ? _t("lasuite_numerique") : undefined}
ref={handle}
aria-expanded={!isPanelCollapsed}
>
{!isPanelCollapsed ? _t("lasuite_numerique") : null}
</AccessibleButton>

{contextMenu}
</>
);
};

export default TchapGaufre;
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1903,6 +1903,11 @@
resolved "https://registry.yarnpkg.com/@floating-ui/utils/-/utils-0.2.2.tgz#d8bae93ac8b815b2bd7a98078cf91e2724ef11e5"
integrity sha512-J4yDIIthosAsRZ5CPYP/jQvUAQtlZTTD/4suA08/FEnlxqW3sKS9iAhgsa9VYLZ6vDHn/ixJgIqRQPotoBjxIw==

"@gouvfr-lasuite/integration@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@gouvfr-lasuite/integration/-/integration-1.0.1.tgz#26340c3c281fdcd13ea95bda08aee551d6b441e7"
integrity sha512-w1roGR5rG7RFoxmnvs0T1vg3lxB9AHws1Mmio6c3QsIR7GdltHC1HyHI/vZVq5V5TSoyLanlU4qG2lSi5uUnGw==

"@humanwhocodes/config-array@^0.11.14":
version "0.11.14"
resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.11.14.tgz#d78e481a039f7566ecc9660b4ea7fe6b1fec442b"
Expand Down

0 comments on commit 5f962bd

Please sign in to comment.