Skip to content

Commit 396414f

Browse files
add framework control & add auth prompt banner
1 parent 0c7f540 commit 396414f

4 files changed

Lines changed: 150 additions & 10 deletions

File tree

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import styled from "@emotion/styled";
2+
import React, { useEffect } from "react";
3+
import { useAuthState } from "hooks";
4+
import { useRouter } from "next/router";
5+
6+
export function SigninToContinueBannerPrmoptProvider({
7+
children,
8+
}: {
9+
children: React.ReactNode;
10+
}) {
11+
const authstate = useAuthState();
12+
13+
const shouldshow = authstate == "expired" || authstate == "unauthorized";
14+
15+
return (
16+
<>
17+
{children}
18+
{shouldshow && <SigninToContinueBannerPrmopt />}
19+
</>
20+
);
21+
}
22+
23+
export function SigninToContinueBannerPrmopt() {
24+
const router = useRouter();
25+
const onnextclick = () => {
26+
const signinurl = `https://accounts.grida.co/signin?redirect_uri=${window.location.href}`;
27+
router.replace(signinurl);
28+
};
29+
30+
return (
31+
<Positioner>
32+
<Contents>
33+
<Desc>Ready to build your apps with Grida?</Desc>
34+
<NextButton onClick={onnextclick}>Next</NextButton>
35+
</Contents>
36+
</Positioner>
37+
);
38+
}
39+
40+
const Positioner = styled.div`
41+
display: flex;
42+
align-items: center;
43+
flex-direction: column;
44+
justify-content: center;
45+
46+
position: fixed;
47+
bottom: 0;
48+
left: 0px;
49+
right: 0px;
50+
51+
background-color: #fff;
52+
z-index: 998;
53+
54+
justify-content: center;
55+
flex-direction: column;
56+
align-items: end;
57+
box-sizing: border-box;
58+
padding: 16px 20px;
59+
60+
a {
61+
margin: 0px 2px;
62+
text-decoration: underline;
63+
}
64+
`;
65+
66+
const Contents = styled.div`
67+
display: flex;
68+
justify-content: flex-end;
69+
flex-direction: row;
70+
align-items: center;
71+
flex: none;
72+
gap: 48px;
73+
width: 439px;
74+
height: 59px;
75+
box-sizing: border-box;
76+
`;
77+
78+
const Desc = styled.span`
79+
color: rgba(0, 0, 0, 1);
80+
text-overflow: ellipsis;
81+
font-size: 16px;
82+
font-family: "Helvetica Neue", sans-serif;
83+
font-weight: 500;
84+
text-align: center;
85+
`;
86+
87+
const NextButton = styled.button`
88+
display: flex;
89+
justify-content: center;
90+
flex-direction: row;
91+
align-items: center;
92+
flex: none;
93+
gap: 10px;
94+
border-radius: 4px;
95+
width: 116px;
96+
height: 59px;
97+
background-color: rgba(45, 66, 255, 1);
98+
box-sizing: border-box;
99+
padding: 10px 10px;
100+
101+
outline: none;
102+
border: none;
103+
104+
color: rgba(255, 255, 255, 1);
105+
text-overflow: ellipsis;
106+
font-size: 21px;
107+
font-family: "Helvetica Neue", sans-serif;
108+
font-weight: 400;
109+
text-align: left;
110+
111+
:hover {
112+
opacity: 0.9;
113+
}
114+
115+
:focus {
116+
opacity: 0.9;
117+
}
118+
`;

editor/hooks/use-auth-state.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
import { useAuthState as useGridaAuthState } from "@base-sdk-fp/auth-components-react";
1+
import {
2+
useAuthState as useGridaAuthState,
3+
LoginState,
4+
} from "@base-sdk-fp/auth-components-react";
25
import { useEffect, useState } from "react";
36

47
export function useAuthState() {
5-
const [authState, setAuthState] = useState<any>();
8+
const [authState, setAuthState] = useState<LoginState>();
69
const gridaauthstate = useGridaAuthState();
710

811
useEffect(() => {

editor/pages/to-code/index.tsx

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import { DesignInput } from "@designto/config/input";
2828
import { ClearRemoteDesignSessionCache } from "components/clear-remote-design-session-cache";
2929
import { WidgetTree } from "components/visualization/json-visualization/json-tree";
3030
import { personal } from "@design-sdk/figma-auth-store";
31+
import { CodeOptionsControl } from "components/codeui-code-options-control";
32+
import { SigninToContinueBannerPrmoptProvider } from "components/prompt-banner-signin-to-continue";
3133

3234
export default function DesignToCodeUniversalPage() {
3335
const router = useRouter();
@@ -36,7 +38,9 @@ export default function DesignToCodeUniversalPage() {
3638
const [result, setResult] = useState<Result>();
3739
const [preview, setPreview] = useState<Result>();
3840

39-
const framework_config = get_framework_config_from_query(router.query);
41+
const [framework_config, set_framework_config] = useState(
42+
get_framework_config_from_query(router.query)
43+
);
4044
const preview_runner_framework = get_preview_runner_framework(router.query);
4145
const enable_components = get_enable_components_config_from_query(
4246
router.query
@@ -78,6 +82,13 @@ export default function DesignToCodeUniversalPage() {
7882
setPreview(result);
7983
}
8084
});
85+
}
86+
}, [design, framework_config.framework]);
87+
88+
useEffect(() => {
89+
if (design) {
90+
const { reflect, raw } = design;
91+
const { id, name } = reflect;
8192
// ----- for preview -----
8293
if (framework_config.framework !== preview_runner_framework.framework) {
8394
designToCode({
@@ -104,11 +115,11 @@ export default function DesignToCodeUniversalPage() {
104115
}
105116

106117
const { code, scaffold, name: componentName } = result;
107-
console.log("design to code result::", result);
108118

109-
const runner_platform = get_runner_platform(framework_config);
119+
// const runner_platform = get_runner_platform(framework_config);
120+
110121
return (
111-
<>
122+
<SigninToContinueBannerPrmoptProvider>
112123
<DefaultEditorWorkspaceLayout
113124
leftbar={
114125
<></>
@@ -139,8 +150,15 @@ export default function DesignToCodeUniversalPage() {
139150
</WorkspaceContentPanel>
140151
<WorkspaceContentPanel key={design.node}>
141152
<InspectionPanelContentWrap>
153+
<CodeOptionsControl
154+
initialPreset={router.query.framework as string}
155+
fallbackPreset="react_default"
156+
onUseroptionChange={(o) => {
157+
set_framework_config(get_framework_config(o.framework));
158+
}}
159+
/>
142160
<CodeEditor
143-
// key={code.raw}
161+
key={code.raw}
144162
height="100vh"
145163
options={{
146164
automaticLayout: true,
@@ -200,7 +218,7 @@ export default function DesignToCodeUniversalPage() {
200218
)}
201219
</WorkspaceContentPanelGridLayout>
202220
</DefaultEditorWorkspaceLayout>
203-
</>
221+
</SigninToContinueBannerPrmoptProvider>
204222
);
205223
}
206224

@@ -211,6 +229,7 @@ function get_enable_components_config_from_query(
211229
if (enable_components) {
212230
return enable_components === "true";
213231
}
232+
// disabled by default
214233
return false;
215234
}
216235

@@ -268,6 +287,6 @@ function get_runner_platform(config: FrameworkConfig) {
268287

269288
const InspectionPanelContentWrap = styled.div`
270289
display: flex;
271-
flex-direction: row;
290+
flex-direction: column;
272291
align-items: stretch;
273292
`;

0 commit comments

Comments
 (0)