Skip to content

Commit 9a73f26

Browse files
update early access guards
1 parent b3e9d27 commit 9a73f26

File tree

6 files changed

+66
-38
lines changed

6 files changed

+66
-38
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { useEarlyAccess } from "@assistant-fp/early-access";
2+
import { useHistory } from "react-router-dom";
3+
import { early_access_required_message } from "../k";
4+
5+
export function requiresEarlyAccess<T extends Function>(f: T): T {
6+
const history = useHistory();
7+
const ea = useEarlyAccess();
8+
9+
if (!ea) {
10+
return ((...args) => {
11+
alert(early_access_required_message);
12+
history.push("/upgrade");
13+
}) as any as T;
14+
} else {
15+
return f;
16+
}
17+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export { UpgradePage } from "./register";
2+
export * from "./guards";
23
export * from "./hooks";
34
export { default as store } from "./store";
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
export const __key = "assistant-early-access-activation";
2+
export const early_access_required_message =
3+
"This is a pro feature, please activate";

packages/app-design-lint/fix-your-self.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { LintItemRow } from "@app/design-lint";
77
import { LintProcessPaginator } from "@app/design-lint/lint-process-paginator";
88
import { _APP_EVENT_LINT_RESULT_EK } from "@app/design-lint/__plugin/events";
99
import BackArrowIcon from "@assistant/icons/back-arrow";
10+
import { requiresEarlyAccess } from "@assistant-fp/early-access";
1011

1112
/** Fix your self as page with router props ver. (not used. planned.) */
1213
export function FixYourSelfPage(props: {
@@ -43,12 +44,12 @@ export function FixYourSelf(props: {
4344
chaange_layer_index(0);
4445
}, []);
4546

46-
const chaange_layer_index = (i) => {
47+
const chaange_layer_index = requiresEarlyAccess((i) => {
4748
setLayerIndex(i);
4849
const _target = layerlintMap.get(_key_at_index(i));
4950
setLayerLint(_target);
5051
PluginSdk.focus(_target.node.id);
51-
};
52+
});
5253

5354
const _page_size = layerlintMap.size;
5455

packages/app-design-lint/lint-screen.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { makeSummary, requestLintOnCurrentSelection } from "./actions";
1919
import { FixYourSelf } from "./fix-your-self";
2020
import { mapGrandchildren } from "@design-sdk/core/utils";
2121
import Dialog from "@material-ui/core/Dialog";
22+
import { requiresEarlyAccess } from "@assistant-fp/early-access";
2223

2324
export const LintScreen = () => {
2425
const [feedbacks, setFeedbacks] = useState<ReflectLintFeedback[]>([]);
@@ -50,10 +51,10 @@ export const LintScreen = () => {
5051
}).length;
5152
}
5253

53-
function onFeedbackTap(feedback: ReflectLintFeedback) {
54+
const onFeedbackTap = requiresEarlyAccess((feedback: ReflectLintFeedback) => {
5455
const targetNodeId = feedback.node.id;
5556
PluginSdk.focus(targetNodeId);
56-
}
57+
});
5758

5859
function handleSelectionLayer() {
5960
const summary = makeSummary(feedbacks);

packages/app-photo-loader/photo-loader.tsx

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ import InfiniteScroll from "react-infinite-scroller";
1313
import { useHistory } from "react-router-dom";
1414
import { radmon_query_placeholder } from "./k";
1515
import { ImagePromptBox } from "./image-prompt-box";
16-
import { useEarlyAccess } from "@assistant-fp/early-access";
16+
import {
17+
requiresEarlyAccess,
18+
useEarlyAccess,
19+
} from "@assistant-fp/early-access";
20+
import { early_access_required_message } from "@assistant-fp/early-access/k";
1721

1822
///
1923
/// TODO:
2024
/// 2. Support for DND
21-
/// 3. Support for replace fill(s)
25+
/// 3. Support random images (on multiple selection)
2226
/// 4. Add optimized image loading witn max 4096 in width and height (either)
2327
///
2428

@@ -94,41 +98,43 @@ export function PhotoLoader() {
9498
}
9599
}, [data.from_resources, hidenav, shownav, query]);
96100

97-
const promptGeneration = async (
98-
q: string,
99-
c: {
100-
style?: string;
101-
}
102-
) => {
103-
setLocked(true);
104-
try {
105-
const { images: gens, n } = await api
106-
.fromGenerative(
107-
{
108-
q: q,
109-
style: c.style,
110-
},
111-
accesskey
112-
)
113-
.finally(() => setLocked(false));
101+
const promptGeneration = requiresEarlyAccess(
102+
async (
103+
q: string,
104+
c: {
105+
style?: string;
106+
}
107+
) => {
108+
setLocked(true);
109+
try {
110+
const { images: gens, n } = await api
111+
.fromGenerative(
112+
{
113+
q: q,
114+
style: c.style,
115+
},
116+
accesskey
117+
)
118+
.finally(() => setLocked(false));
114119

115-
setData({
116-
from_resources: data.from_resources,
117-
from_ai: gens.map((g) => ({
118-
src: g,
119-
thumbnail: g,
120-
name: `${n} ${query}`,
121-
})),
122-
});
123-
} catch (e) {
124-
// if e.message == 'Unauthorized'
125-
// then show the activation screen
126-
if (e.message === "Unauthorized") {
127-
alert("This is a pro feature, please activate");
128-
history.push("/upgrade");
120+
setData({
121+
from_resources: data.from_resources,
122+
from_ai: gens.map((g) => ({
123+
src: g,
124+
thumbnail: g,
125+
name: `${n} ${query}`,
126+
})),
127+
});
128+
} catch (e) {
129+
// if e.message == 'Unauthorized'
130+
// then show the activation screen
131+
if (e.message === "Unauthorized") {
132+
alert(early_access_required_message);
133+
history.push("/upgrade");
134+
}
129135
}
130136
}
131-
};
137+
);
132138

133139
const searchResources = useCallback(
134140
async (q: string, page = 1, extend = false) => {

0 commit comments

Comments
 (0)