Skip to content

Commit

Permalink
fix: persistence issue across flutter and iOS; only create platform a…
Browse files Browse the repository at this point in the history
…fter wizard is finished
  • Loading branch information
TGlide committed Feb 14, 2023
1 parent 6b1c63a commit 1070795
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 210 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
import Step2 from './wizard/android/step2.svelte';
import Step3 from './wizard/android/step3.svelte';
import Step4 from './wizard/step4.svelte';
import { sdkForConsole } from '$lib/stores/sdk';
import { trackEvent } from '$lib/actions/analytics';
async function onFinish() {
async function onExit() {
if ($onboarding) {
invalidate(Dependencies.PROJECT);
}
Expand All @@ -20,6 +22,23 @@
wizard.hide();
}
async function onFinish() {
await sdkForConsole.projects.createPlatform(
$createPlatform.projectId,
'android',
$createPlatform.name,
$createPlatform.key,
undefined,
undefined
);
trackEvent('submit_platform_create', {
type: 'android'
});
await onExit();
}
beforeNavigate(() => {
wizard.hide();
});
Expand Down Expand Up @@ -50,5 +69,5 @@
title="Add an Android Project"
steps={stepsComponents}
on:finish={onFinish}
on:exit={onFinish}
on:exit={onExit}
finalAction="Take me to my Dashboard" />
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
<script lang="ts" context="module">
export enum Platform {
iOS = 'apple-ios',
macOS = 'apple-macos',
watchOS = 'apple-watchos',
tvOS = 'apple-tvos'
}
export const isPlatform = (platform: string): platform is Platform => {
return Object.values(Platform).includes(platform as Platform);
};
</script>

<script lang="ts">
import { Wizard } from '$lib/layout';
import { beforeNavigate, invalidate } from '$app/navigation';
Expand All @@ -10,8 +23,10 @@
import Step4 from './wizard/step4.svelte';
import { Dependencies } from '$lib/constants';
import { onboarding } from '../../store';
import { sdkForConsole } from '$lib/stores/sdk';
import { trackEvent } from '$lib/actions/analytics';
async function onFinish() {
async function onExit() {
if ($onboarding) {
invalidate(Dependencies.PROJECT);
}
Expand All @@ -20,6 +35,23 @@
wizard.hide();
}
async function onFinish() {
await sdkForConsole.projects.createPlatform(
$createPlatform.projectId,
$createPlatform.type,
$createPlatform.name,
$createPlatform.key,
undefined,
undefined
);
trackEvent('submit_platform_create', {
type: $createPlatform.type
});
await onExit();
}
beforeNavigate(() => {
wizard.hide();
});
Expand Down Expand Up @@ -50,5 +82,5 @@
title="Add an Apple Project"
steps={stepsComponents}
on:finish={onFinish}
on:exit={onFinish}
on:exit={onExit}
finalAction="Take me to my Dashboard" />
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
<script lang="ts" context="module">
export enum Platform {
Android = 'flutter-android',
Ios = 'flutter-ios',
Linux = 'flutter-linux',
Macos = 'flutter-macos',
Windows = 'flutter-windows',
Web = 'flutter-web'
}
export function isPlatform(value: string): value is Platform {
return Object.values(Platform).includes(value as Platform);
}
</script>

<script lang="ts">
import { Wizard } from '$lib/layout';
import { beforeNavigate, invalidate } from '$app/navigation';
Expand All @@ -10,8 +25,10 @@
import Step4 from './wizard/step4.svelte';
import { Dependencies } from '$lib/constants';
import { onboarding } from '../../store';
import { sdkForConsole } from '$lib/stores/sdk';
import { trackEvent } from '$lib/actions/analytics';
async function onFinish() {
async function onExit() {
if ($onboarding) {
invalidate(Dependencies.PROJECT);
}
Expand All @@ -20,6 +37,23 @@
wizard.hide();
}
async function onFinish() {
await sdkForConsole.projects.createPlatform(
$createPlatform.projectId,
$createPlatform.type,
$createPlatform.name,
$createPlatform.type !== Platform.Web ? $createPlatform.key : undefined,
undefined,
$createPlatform.type === Platform.Web ? $createPlatform.hostname : undefined
);
trackEvent('submit_platform_create', {
type: $createPlatform.type
});
await onExit();
}
beforeNavigate(() => {
wizard.hide();
});
Expand Down Expand Up @@ -50,5 +84,5 @@
title="Add a Flutter Project"
steps={stepsComponents}
on:finish={onFinish}
on:exit={onFinish}
on:exit={onExit}
finalAction="Take me to my Dashboard" />
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
import Step4 from './wizard/step4.svelte';
import { Dependencies } from '$lib/constants';
import { onboarding } from '../../store';
import { sdkForConsole } from '$lib/stores/sdk';
import { trackEvent } from '$lib/actions/analytics';
async function onFinish() {
async function onExit() {
if ($onboarding) {
invalidate(Dependencies.PROJECT);
}
Expand All @@ -20,6 +22,23 @@
wizard.hide();
}
async function onFinish() {
await sdkForConsole.projects.createPlatform(
$createPlatform.projectId,
'web',
$createPlatform.name,
undefined,
undefined,
$createPlatform.hostname
);
trackEvent('submit_platform_create', {
type: 'web'
});
await onExit();
}
beforeNavigate(() => {
wizard.hide();
});
Expand Down Expand Up @@ -50,5 +69,5 @@
title="Add a Web Project"
steps={stepsComponents}
on:finish={onFinish}
on:exit={onFinish}
on:exit={onExit}
finalAction="Take me to my Dashboard" />
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,18 @@
import { page } from '$app/stores';
import { FormList, InputText } from '$lib/elements/forms';
import { WizardStep } from '$lib/layout';
import { sdkForConsole } from '$lib/stores/sdk';
import { createPlatform } from '../store';
import { wizard } from '$lib/stores/wizard';
import { app } from '$lib/stores/app';
import Light from './light.svg';
import { wizard } from '$lib/stores/wizard';
import { createPlatform } from '../store';
import Dark from './dark.svg';
import { trackEvent } from '$lib/actions/analytics';
import Light from './light.svg';
$wizard.media = $app.themeInUse === 'dark' ? Dark : Light;
const projectId = $page.params.project;
async function beforeSubmit() {
if ($createPlatform.$id) {
await sdkForConsole.projects.updatePlatform(
projectId,
$createPlatform.$id,
$createPlatform.name,
$createPlatform.key,
$createPlatform.store,
$createPlatform.hostname
);
return;
}
const platform = await sdkForConsole.projects.createPlatform(
projectId,
'android',
$createPlatform.name,
$createPlatform.key,
undefined,
undefined
);
trackEvent('submit_platform_create', {
type: 'android'
});
$createPlatform.$id = platform.$id;
}
$createPlatform.projectId = $page.params.project;
</script>

<WizardStep {beforeSubmit}>
<WizardStep>
<svelte:fragment slot="title">Register your Android app</svelte:fragment>
<FormList>
<InputText
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,19 @@
import { Pill } from '$lib/elements';
import { FormItem, FormList, InputText } from '$lib/elements/forms';
import { WizardStep } from '$lib/layout';
import { sdkForConsole } from '$lib/stores/sdk';
import { createPlatform } from '../store';
import { wizard } from '$lib/stores/wizard';
import { app } from '$lib/stores/app';
import Light from './light.svg';
import { wizard } from '$lib/stores/wizard';
import { isPlatform, Platform } from '../../createApple.svelte';
import { createPlatform } from '../store';
import Dark from './dark.svg';
import { trackEvent } from '$lib/actions/analytics';
import Light from './light.svg';
$wizard.media = $app.themeInUse === 'dark' ? Dark : Light;
enum Platform {
iOS = 'apple-ios',
macOS = 'apple-macos',
watchOS = 'apple-watchos',
tvOS = 'apple-tvos'
}
let platform: Platform = Platform.iOS;
const projectId = $page.params.project;
async function beforeSubmit() {
if ($createPlatform.$id) {
await sdkForConsole.projects.updatePlatform(
projectId,
$createPlatform.$id,
$createPlatform.name,
$createPlatform.key,
$createPlatform.store,
$createPlatform.hostname
);
return;
}
const response = await sdkForConsole.projects.createPlatform(
projectId,
platform,
$createPlatform.name,
$createPlatform.key,
undefined,
undefined
);
trackEvent('submit_platform_create', {
type: platform
});
$createPlatform.$id = response.$id;
}
$createPlatform.type = isPlatform($createPlatform.type) ? $createPlatform.type : Platform.iOS;
$createPlatform.projectId = $page.params.project;
</script>

<WizardStep {beforeSubmit}>
<WizardStep>
<svelte:fragment slot="title">Register your Apple app</svelte:fragment>

<FormList isCommonSection>
Expand All @@ -64,26 +24,26 @@
<div class="u-flex u-gap-16 u-margin-block-start-8">
<Pill
button
on:click={() => (platform = Platform.iOS)}
selected={platform === Platform.iOS}>
on:click={() => ($createPlatform.type = Platform.iOS)}
selected={$createPlatform.type === Platform.iOS}>
iOS
</Pill>
<Pill
button
on:click={() => (platform = Platform.macOS)}
selected={platform === Platform.macOS}>
on:click={() => ($createPlatform.type = Platform.macOS)}
selected={$createPlatform.type === Platform.macOS}>
macOS
</Pill>
<Pill
button
on:click={() => (platform = Platform.watchOS)}
selected={platform === Platform.watchOS}>
on:click={() => ($createPlatform.type = Platform.watchOS)}
selected={$createPlatform.type === Platform.watchOS}>
watchOS
</Pill>
<Pill
button
on:click={() => (platform = Platform.tvOS)}
selected={platform === Platform.tvOS}>
on:click={() => ($createPlatform.type = Platform.tvOS)}
selected={$createPlatform.type === Platform.tvOS}>
tvOS
</Pill>
</div>
Expand Down
Loading

0 comments on commit 1070795

Please sign in to comment.