Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Figma link 🥳 #56

Merged
merged 35 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
27f54fb
feat(svgr): pull from s3 and display highlight zones
GaspardC Oct 11, 2022
d93cef7
refac(zones): selector drawn and figma
GaspardC Oct 11, 2022
b5ab31c
feat(figma): zone display
GaspardC Oct 12, 2022
73afa23
feat(tree): structure
GaspardC Oct 12, 2022
7773515
feat(tree): display main group link
GaspardC Oct 12, 2022
038622c
refactor(wip): clean
GaspardC Oct 12, 2022
6906043
feat(28): screenshot when img full width
MathildeIgier Oct 22, 2022
8e586ff
feat(screenshot): manage img smaller than 400px
MathildeIgier Oct 28, 2022
ccdfd37
feat(delete): figma zone
GaspardC Nov 3, 2022
aefd467
feat(hide): figma zone
GaspardC Nov 3, 2022
c15b206
feat(svg): link to figma plugin
GaspardC Nov 3, 2022
2de5bef
Merge branch 'master' into figma-link
GaspardC Nov 3, 2022
088acd3
fixes merge
GaspardC Nov 3, 2022
691f43e
merge re add drawn zones
GaspardC Nov 3, 2022
0229215
flex svg
GaspardC Nov 3, 2022
142a6b6
fix(newzones): link zoneParams
GaspardC Nov 4, 2022
af182c2
fix(link): reco updates
GaspardC Nov 4, 2022
7136992
fix(img): link
GaspardC Nov 4, 2022
3249d9d
Merge branch 'fix-28' into figma-link
GaspardC Nov 4, 2022
859b71e
merge(image): screenshot draw zone
GaspardC Nov 4, 2022
347e5bb
Merge branch 'master' into figma-link
GaspardC Nov 4, 2022
61b5f03
merge
GaspardC Nov 4, 2022
8b674f7
create dragable zone
GaspardC Nov 4, 2022
247c9da
merge zones homogene
GaspardC Nov 4, 2022
19580fa
feat(tree): do not take into account root node in tree
GaspardC Nov 4, 2022
e044ed7
fix update zone
GaspardC Nov 4, 2022
7d1b966
reset figma zone init
GaspardC Nov 4, 2022
93e8357
clean unused code
GaspardC Nov 4, 2022
71772d0
remove unused lib
GaspardC Nov 4, 2022
8741be9
rename back to new zone
GaspardC Nov 4, 2022
181f683
fix typo const
GaspardC Nov 7, 2022
09aa334
display a toast when url is not valid
GaspardC Nov 7, 2022
6233fb4
fix(id): reset all, add TODO
GaspardC Nov 8, 2022
1b609e2
Merge branch 'master' into figma-link
GaspardC Nov 8, 2022
bd744ae
fix zoom fetched svg
GaspardC Nov 8, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"multiline-ternary": "off",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{ "argsIgnorePattern": "^_" }
"warn",
{ "argsIgnorePattern": "^_" }
],
"dot-notation": "off",
"func-call-spacing": "off"
Expand Down
3 changes: 3 additions & 0 deletions config-overrides.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function override(config, env) {
return config;
};
38,567 changes: 0 additions & 38,567 deletions package-lock.json

This file was deleted.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"private": true,
"homepage": "https://MediaComem.github.io/bytesim-webapp",
"dependencies": {
"@chakra-ui/icons": "^2.0.11",
GaspardC marked this conversation as resolved.
Show resolved Hide resolved
"@chakra-ui/react": "^2.2.1",
"@emotion/css": "^11.9.0",
"@emotion/react": "^11.9.3",
Expand All @@ -24,6 +25,7 @@
"react": "^18.2.0",
"react-dnd": "^16.0.1",
"react-dom": "^18.2.0",
"react-inlinesvg": "^3.0.1",
"react-rectangle-selection": "^1.0.4",
"react-redux": "^8.0.2",
"react-reflex": "^4.0.9",
Expand Down Expand Up @@ -65,6 +67,7 @@
"eslint-plugin-n": "^15.2.3",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-react": "^7.30.1",
"gh-pages": "^4.0.0"
"gh-pages": "^4.0.0",
"react-app-rewired": "^2.2.1"
}
}
}
21 changes: 11 additions & 10 deletions src/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
import { css } from "@emotion/css";
import * as React from "react";
import { useDispatch } from "react-redux";
import { colorTheme } from ".";
import { useAppSelector } from "./app/hooks";
import ConfirmModal, { confirmText } from "./components/layout/ConfirmModal";
import Panel from "./components/layout/Panel";
Expand All @@ -22,16 +21,18 @@ import GeneralFormAccordion from "./components/project/GeneralForm";
import ZonesList from "./components/zones/ZonesList";
import ZonesView from "./components/zones/ZonesView";
import { projectReset } from "./features/project/projectSlice";

import { ReactComponent as ResetIcon } from "./assets/ResetIcon_Active_MouseOver.svg";
import ExportButton from "./components/recommandations/ExportButton";
import { colorTheme } from "./theme";
import RecoWarning from "./components/recommandations/RecoWarning";
import {
allZonesReset,
getUncompleteZones,
zoneAdded,
} from "./features/zones/zonesSlice";
import { ReactComponent as ResetIcon } from "./assets/ResetIcon_Active_MouseOver.svg";
import ExportButton from "./components/recommandations/ExportButton";
import "react-reflex/styles.css";
import { ReflexContainer, ReflexElement, ReflexSplitter } from "react-reflex";
import RecoWarning from "./components/recommandations/RecoWarning";

export default function Home() {
const dispatch = useDispatch();
Expand Down Expand Up @@ -149,10 +150,10 @@ export default function Home() {
label={`${zoom}%`}
>
<SliderThumb
className={css({ boxShadow: "none" })}
width="10px"
height="10px"
/>
className={css({ boxShadow: "none" })}
width="10px"
height="10px"
/>
</Tooltip>
</Slider>
<Button
Expand Down Expand Up @@ -239,8 +240,8 @@ export default function Home() {
}
>
{uncompleteZones.length !== 0 && (
<RecoWarning uncompleteZoneNames={uncompleteZones} />
)}
<RecoWarning uncompleteZoneNames={uncompleteZones} />
)}
<RecoReport />
</Panel>
</ReflexElement>
Expand Down
21 changes: 15 additions & 6 deletions src/app/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { createDraftSafeSelector } from "@reduxjs/toolkit";
import { TypedUseSelectorHook, useDispatch, useSelector } from "react-redux";
import simulationService from "../services/simulationService";
import { isZoneComplete } from "../utils/utils";
Expand All @@ -14,8 +15,16 @@ import { VideoParameters } from "./types/videoTypes";
export const useAppDispatch: () => AppDispatch = useDispatch;
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;

const selectZones = (state: RootState) => state.zonesSlice.zones;
export const zoneSelector = createDraftSafeSelector(
selectZones,
(state) => state
);

export const useAppZones = () => useAppSelector(zoneSelector);

export function useCalculateImpact(): { energy: number; co2: number } {
const zones = useAppSelector((state) => state.zones);
const zones = useAppSelector(zoneSelector);
const renewable = useAppSelector(
(state) => state.project.params.server === ServerType.RENEWABLE
);
Expand Down Expand Up @@ -43,7 +52,7 @@ export function useCalculateRecommandationsImpact(): {
energy: number;
co2: number;
} {
const zones = useAppSelector((state) => state.zones);
const zones = useAppSelector(zoneSelector);
const recommandations = useAppSelector((state) => state.recommandations);
const nbVisits = useAppSelector((state) => state.project.params.nbVisit) ?? 1; // if no visitor impact per visit
let renewable = useAppSelector(
Expand All @@ -58,7 +67,7 @@ export function useCalculateRecommandationsImpact(): {
renewable = recommandationRenewable.selectedValue === "better";
}
zones.forEach((zone) => {
if (isZoneComplete(zone)) {
if (isZoneComplete(zone)) {
// TODO optimize code + architecture
const zoneRecommandations = recommandations.filter(
(rec) => rec.zone_id === zone.id
Expand Down Expand Up @@ -119,7 +128,7 @@ export function useCalculateGenericRecommandations(): RecommandationWithZone<
export function useCalculateAllRecommandations(): RecommandationWithZone<
VideoParameters[keyof VideoParameters]
>[] {
const zones = useAppSelector((state) => state.zones);
const zones = useAppZones();
const genericParameters = useAppSelector((state) => state.project.params);
const renewable = genericParameters === ServerType.RENEWABLE;
const recommandations: RecommandationWithZone<
Expand All @@ -130,7 +139,7 @@ export function useCalculateAllRecommandations(): RecommandationWithZone<
recos.forEach((reco) => {
const rec: RecommandationWithZone<
VideoParameters[keyof VideoParameters]
> = { ...reco, zoneId: zone.id, zoneName: zone.name };
> = { ...reco, zoneId: zone.id!, zoneName: zone.name! };
recommandations.push(rec);
});
});
Expand All @@ -155,7 +164,7 @@ export function useCalculateRecommandationsForZone(

export function useSelectedZone(): Zone | undefined {
let zone;
const zones = useAppSelector((state) => state.zones);
const zones = useAppSelector((state) => state.zonesSlice.zones);
zones.forEach((z) => {
if (z.status === "EDITING") zone = z;
});
Expand Down
19 changes: 10 additions & 9 deletions src/app/store.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { configureStore } from '@reduxjs/toolkit'
import projectReducer from '../features/project/projectSlice'
import zonesSlice from '../features/zones/zonesSlice'
import { configureStore } from "@reduxjs/toolkit";
import projectReducer from "../features/project/projectSlice";
import zonesSlice from "../features/zones/zonesSlice";
import { debounce } from "debounce";
import browserStorage from '../services/browserStorage';
import recommandationsSlice from '../features/recommandations/recommandationsSlice';
import browserStorage from "../services/browserStorage";
import recommandationsSlice from "../features/recommandations/recommandationsSlice";

export const store = configureStore({
reducer: {
project: projectReducer,
zones: zonesSlice,
zonesSlice,
// zonesFigma: zonesFigmaSlice,
recommandations: recommandationsSlice,
},
preloadedState: browserStorage.loadState(), // load state from local storage
})
});

// Subscribe to the store changes to persist to local storage
store.subscribe(
Expand All @@ -23,6 +24,6 @@ store.subscribe(
}, 500)
);

export type RootState = ReturnType<typeof store.getState>
export type RootState = ReturnType<typeof store.getState>;
// Inferred type: {posts: PostsState, comments: CommentsState, users: UsersState}
export type AppDispatch = typeof store.dispatch
export type AppDispatch = typeof store.dispatch;
42 changes: 37 additions & 5 deletions src/app/types/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import { GenericParameters } from "./generalFormTypes";

import { ImageParameters } from "./imgTypes";
Expand Down Expand Up @@ -27,6 +26,14 @@ export interface ZoneInfo {
width: number;
height: number;
status: ZoneStatus;
createdFrom?: "user" | "figma";
// only for figma fields
hidden?: boolean;
elementId?: string;
initWidth?: number;
initHeight?: number;
initX?: number;
initY?: number;
}

export interface ZoneUnknown extends ZoneInfo {
Expand All @@ -44,12 +51,33 @@ export interface ZoneImages extends ZoneInfo {
params?: ImageParameters;
}

export interface ZoneText extends ZoneInfo {
zoneType: ZoneType.Text;
params?: any;
}

export interface ZoneDynamic extends ZoneInfo {
zoneType: ZoneType.DynamicContent;
params?: any
params?: any;
}

export type Zone = ZoneUnknown | ZoneVideo | ZoneImages | ZoneDynamic;
export type Zone =
| ZoneUnknown
| ZoneVideo
| ZoneImages
| ZoneText
| ZoneDynamic;

export type ZoneFigma = Omit<Zone, "createdFrom"> & {
id: string;
createdFrom: "figma";
elementId: string;
hidden?: boolean;
};
export type TreeZoneEl = {
id: string;
children?: TreeZoneEl[];
};

export type ProjectStatus = "EDITING" | "SIMULATION" | "LOADING";
export type ZoneStatus = "EDITING" | "ACTIVE" | "LOADING";
Expand All @@ -59,10 +87,14 @@ export enum ZoneType {
Video = "Video",
Images = "Images",
DynamicContent = "DynamicContent",
Text = "Text",
}

export type FormsType = ZoneParamsType | GenericParameters;
export type ZoneParamsType = VideoParameters | ImageParameters | DynContentParameters;
export type ZoneParamsType =
| VideoParameters
| ImageParameters
| DynContentParameters;

export enum EBoolean {
YES = "Yes",
Expand All @@ -75,4 +107,4 @@ export enum EBoolean {
// Modele de calcul -> video pour le POC, 1 par type
// Modele de reco
// Zone View à adapter pour différents formats d'image svg de base
// création de PDF
// création de PDF
1 change: 0 additions & 1 deletion src/components/layout/AccordionChevron.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as React from "react";
import { css, cx } from "@emotion/css";
import { ReactComponent as OpenIcon } from "../../assets/Fleche_Fermee.svg";

interface AccordionChevronProps {
isExpanded: boolean;
setOpen?: () => void;
Expand Down
506 changes: 393 additions & 113 deletions src/components/layout/TestSVG.tsx

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/components/project/UploadButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import * as React from "react";
import { useDispatch } from "react-redux";
import { projectUpdated } from "../../features/project/projectSlice";
import { ReactComponent as AddIcon } from "../../assets/BigPlus.svg";
import { colorTheme } from "../..";
import { colorTheme } from "../../theme";

export default function UploadButton() {
const dispatch = useDispatch();
Expand All @@ -29,7 +29,7 @@ export default function UploadButton() {
justifyContent={"center"}
alignSelf="stretch"
onClick={onOpen}
_hover={{ backgroundColor: colorTheme[50], cursor: 'pointer' }}
_hover={{ backgroundColor: colorTheme[50], cursor: "pointer" }}
>
<Flex direction="column" align="center">
<AddIcon />
Expand Down
8 changes: 5 additions & 3 deletions src/components/recommandations/RecoReport.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Divider, Flex } from "@chakra-ui/react";
import * as React from "react";
import { useEffect } from "react";
import { useDispatch } from "react-redux";
import {
useAppSelector,
useAppZones,
useCalculateAllRecommandations,
useCalculateGenericRecommandations,
} from "../../app/hooks";
Expand Down Expand Up @@ -38,12 +39,13 @@ export function ReportBody({
const dispatch = useDispatch();
const recommandations = useCalculateAllRecommandations();
const genericRecomandations = useCalculateGenericRecommandations();
const zones = useAppSelector((state) => state.zones);
const zones = useAppZones();

/* const zonesParams = useAppSelector((state) => {
return Object.values(state.zones).filter((zone) => zone.filter());
}); */
const projectGeneralParams = useAppSelector((state) => state.project.params);
React.useEffect(() => {
useEffect(() => {
dispatch(
recommandationsPopulated([...genericRecomandations, ...recommandations])
);
Expand Down
4 changes: 4 additions & 0 deletions src/components/recommandations/Recommandation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from "../../app/types/recommandations";
import { VideoParameters } from "../../app/types/videoTypes";
import { recommandationUpdated } from "../../features/recommandations/recommandationsSlice";
import useZoneScreenshot from "../../hooks/useZoneScreenshot";
import AccordionChevron from "../layout/AccordionChevron";
//import { ReportCTX } from "./RecoReport";

Expand All @@ -35,6 +36,8 @@ export default function RecommandationDisplay({
}: RecommandationDisplayProps) {
//const { totalBenefits, setTotalBenefits } = React.useContext(ReportCTX);
const dispatch = useDispatch();
const { ZoneScreenshot } = useZoneScreenshot();

const onChangeParams = React.useCallback(
(v: RecommandationOption) => {
dispatch(
Expand All @@ -52,6 +55,7 @@ export default function RecommandationDisplay({
<Heading mr={1} size="sm">
{recommandation.zoneName}
</Heading>
<ZoneScreenshot zoneId={recommandation.zoneId} />
<Flex>
<Text>{recommandation.parameter}</Text>
<Tooltip label="Biblio de reco + best practices" hasArrow>
Expand Down
2 changes: 1 addition & 1 deletion src/components/recommandations/ReloadRecoButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { Button } from "@chakra-ui/react";
import { css } from "@emotion/css";
import * as React from "react";
import { useDispatch } from "react-redux";
import { colorTheme } from "../..";
import {
useCalculateAllRecommandations,
useCalculateGenericRecommandations,
} from "../../app/hooks";
import { ReactComponent as ResetIcon } from "../../assets/ResetIcon_Active_MouseOver.svg";
import { recommandationsPopulated } from "../../features/recommandations/recommandationsSlice";
import { colorTheme } from "../../theme";
//import { useNavigate } from "react-router-dom";

export default function ReloadRecoButton() {
Expand Down
Loading