Skip to content

Commit

Permalink
🚧
Browse files Browse the repository at this point in the history
  • Loading branch information
cruzdanilo committed Dec 2, 2024
1 parent 2b4ae2e commit daf7e59
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ RUN foundryup
WORKDIR /usr/src/app
COPY . .
RUN --mount=type=cache,id=pnpm,target=/root/.local/share/pnpm/store pnpm install --frozen-lockfile
RUN pnpm expo export --platform web --source-maps --output-dir server/app && \
RUN pnpm expo export --dev --no-minify --platform web --source-maps --output-dir server/app && \
pnpm run --filter server build && \
pnpm deploy --filter server --prod /prod/server

Expand Down
2 changes: 2 additions & 0 deletions app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import "dotenv/config";
import type { IntercomPluginProps } from "@intercom/intercom-react-native/lib/typescript/expo-plugins/@types";
import type { withSentry } from "@sentry/react-native/expo";
import type { ExpoConfig } from "expo/config";
import type { AssetProps } from "expo-asset/plugin/build/withAssets";
import type { PluginConfigType as BuildPropertiesConfig } from "expo-build-properties/build/pluginConfig";
import type withCamera from "expo-camera/plugin/build/withCamera";
import type { FontProps } from "expo-font/plugin/build/withFonts";
Expand Down Expand Up @@ -96,6 +97,7 @@ export default {
],
} satisfies FontProps,
],
["expo-asset", { assets: ["src/assets/icon.png"] } satisfies AssetProps],
"expo-router",
[
"@intercom/intercom-react-native",
Expand Down
24 changes: 24 additions & 0 deletions public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"$schema": "https://raw.githubusercontent.com/SchemaStore/schemastore/refs/heads/master/src/schemas/json/web-manifest.json",
"short_name": "Exa",
"name": "Exa",
"icons": [
{ "src": "favicon.ico", "type": "image/x-icon", "sizes": "48x48" },
{ "src": "assets/src/assets/icon.f9538ae2aa18c66272006c460191b34f.png", "type": "image/png", "sizes": "1024x1024" }
],
"id": "/",
"lang": "en",
"start_url": ".",
"display": "standalone",
"orientation": "portrait",
"theme_color": "#0BD8B6",
"background_color": "#171918",
"prefer_related_applications": true,
"related_applications": [
{
"platform": "play",
"id": "app.exactly",
"url": "https://play.google.com/store/apps/details?id=app.exactly"
}
]
}
2 changes: 2 additions & 0 deletions src/app/(app)/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Redirect, SplashScreen, Stack } from "expo-router";
import React, { useEffect } from "react";

import handleError from "../../utils/handleError";
import { enablePrompt } from "../../utils/onesignal";
import queryClient from "../../utils/queryClient";
import useBackgroundColor from "../../utils/useBackgroundColor";

Expand All @@ -13,6 +14,7 @@ export default function AppLayout() {
useEffect(() => {
if (isLoading || !isFetched) return;
SplashScreen.hideAsync().catch(handleError);
enablePrompt();
}, [isFetched, isLoading]);
if (noPasskey) return <Redirect href="/onboarding" />;
if (isLoading || !isFetched) return;
Expand Down
1 change: 1 addition & 0 deletions src/app/+html.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default function HTML({ children }: { children: ReactNode }) {
name="viewport"
content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1.00001,viewport-fit=cover"
/>
<link rel="manifest" href="/manifest.json" />
<ScrollViewStyleReset />
</head>
<body>{children}</body>
Expand Down
4 changes: 4 additions & 0 deletions src/app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ToastProvider } from "@tamagui/toast";
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
import { PersistQueryClientProvider } from "@tanstack/react-query-persist-client";
import { isRunningInExpoGo } from "expo";
import { useAssets } from "expo-asset";
import { type FontSource, useFonts } from "expo-font";
import { SplashScreen, Stack, useNavigationContainerRef } from "expo-router";
import React, { useEffect } from "react";
Expand All @@ -17,6 +18,7 @@ import BDOGroteskRegular from "../assets/fonts/BDOGrotesk-Regular.otf";
import IBMPlexMonoBold from "../assets/fonts/IBMPlexMono-Bold.otf";
import IBMPlexMonoRegular from "../assets/fonts/IBMPlexMono-Regular.otf";
import IBMPlexMonoSemiBold from "../assets/fonts/IBMPlexMono-SemiBold.otf";
import AppIcon from "../assets/icon.png";
import { OnboardingProvider } from "../components/context/OnboardingProvider";
import ThemeProvider from "../components/context/ThemeProvider";
import handleError from "../utils/handleError";
Expand All @@ -42,6 +44,7 @@ init({
spotlight: __DEV__,
});
const useServerFonts = typeof window === "undefined" ? useFonts : () => undefined;
const useServerAssets = typeof window === "undefined" ? useAssets : () => undefined;
const devtools = !!JSON.parse(process.env.EXPO_PUBLIC_DEVTOOLS ?? "false");

export default wrap(function RootLayout() {
Expand All @@ -54,6 +57,7 @@ export default wrap(function RootLayout() {
"IBMPlexMono-Regular": IBMPlexMonoRegular as FontSource,
"IBMPlexMono-SemiBold": IBMPlexMonoSemiBold as FontSource,
});
useServerAssets([AppIcon]);
useEffect(() => {
routingInstrumentation.registerNavigationContainer(navigationContainer);
}, [navigationContainer]);
Expand Down
35 changes: 32 additions & 3 deletions src/utils/onesignal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,40 @@ import type * as OneSignalWeb from "react-onesignal";

import handleError from "./handleError";

const { initialization, login, logout } = (
const { initialization, enablePrompt, login, logout } = (
Platform.OS === "web" && typeof window !== "undefined"
? () => {
const { default: OneSignal } = require("react-onesignal") as typeof OneSignalWeb; // eslint-disable-line @typescript-eslint/no-require-imports, unicorn/prefer-module
let displayPrompt: (() => void) | undefined;
return {
initialization: appId
? OneSignal.init({ appId, allowLocalhostAsSecureOrigin: __DEV__ }).catch(handleError)
? OneSignal.init({
appId,
allowLocalhostAsSecureOrigin: __DEV__,
notifyButton: {
enabled: true,
showCredit: false,
displayPredicate: () =>
new Promise((resolve) => {
console.log("displayPredicate"); // eslint-disable-line no-console
displayPrompt = () => {
// eslint-disable-next-line no-console
console.log("displayPrompt", {
permission: OneSignal.Notifications.permission,
isPushSupported: OneSignal.Notifications.isPushSupported(),
});
displayPrompt = undefined;
resolve(!OneSignal.Notifications.permission && OneSignal.Notifications.isPushSupported());
};
}),
},
}).catch(handleError)
: Promise.resolve(),
enablePrompt: () => {
console.trace("enablePrompt", appId, !!displayPrompt); // eslint-disable-line no-console
if (!appId) return;
displayPrompt?.();
},
login: (userId: string) => {
if (appId) return OneSignal.login(userId);
return Promise.resolve();
Expand All @@ -30,6 +56,9 @@ const { initialization, login, logout } = (
if (appId) OneSignal.initialize(appId);
return Promise.resolve();
})(),
enablePrompt: () => {
if (appId) OneSignal.InAppMessages.addTrigger("onboard", "1");
},
login: (userId: string) => {
if (appId) OneSignal.login(userId);
return Promise.resolve();
Expand All @@ -42,4 +71,4 @@ const { initialization, login, logout } = (
}
)();

export { initialization, login, logout };
export { initialization, enablePrompt, login, logout };

0 comments on commit daf7e59

Please sign in to comment.