Skip to content

Commit 8e70564

Browse files
committed
Add typings to browser from port opened
1 parent 61d7352 commit 8e70564

File tree

4 files changed

+25
-17
lines changed

4 files changed

+25
-17
lines changed

packages/app/src/app/overmind/namespaces/server/actions.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Action } from 'app/overmind';
22
import {
33
ServerStatus,
44
ServerContainerStatus,
5+
ServerPort,
56
} from '@codesandbox/common/lib/types';
67
import { NotificationStatus } from '@codesandbox/notifications/lib/state';
78

@@ -171,20 +172,26 @@ export const onCodeSandboxAPIMessage: Action<{
171172
}
172173
};
173174

175+
type BrowserOptions = { title?: string; url?: string } & (
176+
| {
177+
port: number;
178+
}
179+
| { url: string });
180+
174181
export const onBrowserTabOpened: Action<{
175-
port: any;
176-
}> = ({ actions }, { port }) => {
182+
options: BrowserOptions;
183+
}> = ({ actions }, { options }) => {
177184
actions.editor.onDevToolsTabAdded({
178185
tab: {
179186
id: 'codesandbox.browser',
180187
closeable: true,
181-
options: port,
188+
options,
182189
},
183190
});
184191
};
185192

186193
export const onBrowserFromPortOpened: Action<{
187-
port: any;
194+
port: ServerPort;
188195
}> = ({ actions }, { port }) => {
189196
actions.editor.onDevToolsTabAdded({
190197
tab: port.main
@@ -195,7 +202,6 @@ export const onBrowserFromPortOpened: Action<{
195202
options: {
196203
port: port.port,
197204
url: `https://${port.hostname}`,
198-
title: port.title,
199205
},
200206
},
201207
});

packages/app/src/app/overmind/namespaces/server/state.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import {
22
ServerStatus,
33
ServerContainerStatus,
4+
ServerPort,
45
} from '@codesandbox/common/lib/types';
56

67
type State = {
78
status: ServerStatus;
89
containerStatus: ServerContainerStatus;
910
error: string;
1011
hasUnrecoverableError: false;
11-
ports: any[];
12+
ports: ServerPort[];
1213
};
1314

1415
export const state: State = {

packages/app/src/app/pages/Sandbox/Editor/Workspace/items/Server/index.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Margin from '@codesandbox/common/lib/components/spacing/Margin';
2+
import { ServerPort } from '@codesandbox/common/lib/types';
23
import React, { FunctionComponent } from 'react';
34
import BrowserIcon from 'react-icons/lib/go/browser';
45

@@ -22,19 +23,12 @@ import { EnvironmentVariables } from './EnvVars';
2223
import { Status } from './Status';
2324
import { Tasks } from './Tasks';
2425

25-
type Port = {
26-
main: boolean;
27-
port: number;
28-
hostname: string;
29-
name?: string;
30-
};
31-
3226
export const Server: FunctionComponent = () => {
3327
const {
3428
actions: {
3529
server: {
36-
onBrowserFromPortOpened,
3730
onBrowserTabOpened,
31+
onBrowserFromPortOpened,
3832
restartContainer,
3933
restartSandbox,
4034
},
@@ -47,7 +41,7 @@ export const Server: FunctionComponent = () => {
4741

4842
const disconnected = server.status !== 'connected';
4943

50-
const openPort = (port: Port) => {
44+
const openPort = (port: ServerPort) => {
5145
onBrowserFromPortOpened({ port });
5246
};
5347

@@ -88,7 +82,7 @@ export const Server: FunctionComponent = () => {
8882

8983
<Margin top={0.5}>
9084
{server.ports.length ? (
91-
server.ports.map((port: Port) => (
85+
server.ports.map((port: ServerPort) => (
9286
<EntryContainer
9387
style={{ position: 'relative' }}
9488
onClick={() => openPort(port)}
@@ -115,7 +109,7 @@ export const Server: FunctionComponent = () => {
115109
style={{ position: 'relative' }}
116110
onClick={() =>
117111
onBrowserTabOpened({
118-
port: {
112+
options: {
119113
url:
120114
sandbox.template === 'gridsome'
121115
? '/___explore'

packages/common/src/types/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,13 @@ export enum ServerContainerStatus {
468468
ERROR = 'error',
469469
}
470470

471+
export type ServerPort = {
472+
main: boolean;
473+
port: number;
474+
hostname: string;
475+
name?: string;
476+
};
477+
471478
export type ZeitUser = {
472479
uid: string;
473480
email: string;

0 commit comments

Comments
 (0)