Skip to content

Commit

Permalink
prettier?
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoecheza committed Jul 4, 2024
1 parent fb4903f commit 0a832d8
Show file tree
Hide file tree
Showing 56 changed files with 277 additions and 330 deletions.
2 changes: 1 addition & 1 deletion packages/main/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {restoreOrCreateWindow} from '/@/mainWindow';
import {platform} from 'node:process';
import updater from 'electron-updater';

import { initIpc } from './ipc';
import {initIpc} from './ipc';
import './security-restrictions';

/**
Expand Down
11 changes: 4 additions & 7 deletions packages/main/src/ipc/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { contextBridge } from 'electron';
import {contextBridge} from 'electron';

import { initWorkspaceApi } from './workspace';
import type { IpcHandlers, IpcModule } from '../types';
import {initWorkspaceApi} from './workspace';
import type {IpcHandlers, IpcModule} from '../types';

// Q: this function is only to enforce the "IpcHandlers" type on the api constant below,
// but is it necessary to do that?
function createApi<
K extends IpcModule,
T extends { [key: string]: IpcHandlers<K> },
>(api: T) {
function createApi<K extends IpcModule, T extends {[key: string]: IpcHandlers<K>}>(api: T) {
return api;
}

Expand Down
6 changes: 3 additions & 3 deletions packages/main/src/ipc/api/workspace.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ipcRenderer } from 'electron';
import {ipcRenderer} from 'electron';

import type { initWorkspace } from '../handlers/workspace';
import { MessageType, type IpcHandlers} from '../types';
import type {initWorkspace} from '../handlers/workspace';
import {MessageType, type IpcHandlers} from '../types';

export function initWorkspaceApi() {
const workspaceApi: IpcHandlers<ReturnType<typeof initWorkspace>> = {
Expand Down
6 changes: 3 additions & 3 deletions packages/main/src/ipc/handlers/workspace.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { IpcMainInvokeEvent } from 'electron';
import type {IpcMainInvokeEvent} from 'electron';

import { handleInvoke, MessageType } from '../types';
import { getWorkspace } from '../../modules/workspace';
import {handleInvoke, MessageType} from '../types';
import {getWorkspace} from '../../modules/workspace';

export function initWorkspace() {
function getWorkspaceHandler(_: IpcMainInvokeEvent) {
Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/ipc/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { initWorkspace } from './handlers/workspace';
import {initWorkspace} from './handlers/workspace';

export function initIpc() {
return {
Expand Down
11 changes: 4 additions & 7 deletions packages/main/src/ipc/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ipcMain, type IpcMainInvokeEvent } from 'electron';
import {ipcMain, type IpcMainInvokeEvent} from 'electron';

import type { Tail as IgnoreEvent } from '/shared/types/utils';
import type {Tail as IgnoreEvent} from '/shared/types/utils';

// Main
export type IpcHandlerType = 'INVOKE';
Expand All @@ -9,10 +9,7 @@ export enum MessageType {
GET_WORKSPACE = 'get_workspace',
}

export type HandlerFn<P extends any[], K> = (
e: IpcMainInvokeEvent,
...args: P
) => K;
export type HandlerFn<P extends any[], K> = (e: IpcMainInvokeEvent, ...args: P) => K;

export type Handler<T extends IpcHandlerType, P extends any[], K> = {
type: T;
Expand All @@ -26,7 +23,7 @@ export function handleInvoke<T extends MessageType, P extends any[], K>(
handler: HandlerFn<P, K>,
): InvokeHandler<P, K> {
ipcMain.handle(type, handler);
return { type: 'INVOKE', handler };
return {type: 'INVOKE', handler};
}

// Renderer
Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/modules/cwd.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { app } from 'electron';
import {app} from 'electron';
import fs from 'fs';

// set default workspace to user's home directory for now
Expand Down
14 changes: 4 additions & 10 deletions packages/main/src/modules/pkg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type PackageJson = {
engines: {
node: string;
};
bin?: { [command: string]: string };
bin?: {[command: string]: string};
dependencies?: Record<string, string>;
devDependencies?: Record<string, string>;
};
Expand All @@ -17,19 +17,14 @@ type PackageJson = {
* @param moduleName The name of the module
* @returns The package json object
*/
export function getPackageJson(
_path: string,
moduleName?: string | null,
): PackageJson {
export function getPackageJson(_path: string, moduleName?: string | null): PackageJson {
const packageJsonPath = moduleName
? path.join(_path, './node_modules', moduleName, 'package.json')
: path.join(_path, 'package.json');
try {
return JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
} catch (error: any) {
throw new Error(
`Could not get package.json for module "${moduleName}": ${error.message}`,
);
throw new Error(`Could not get package.json for module "${moduleName}": ${error.message}`);
}
}

Expand All @@ -51,7 +46,6 @@ export function getPackageVersion(_path: string, moduleName?: string) {
export function hasDependency(_path: string, moduleName: string) {
const pkg = getPackageJson(_path, undefined);
const isDependency = !!pkg.dependencies && moduleName in pkg.dependencies;
const isDevDependency =
!!pkg.devDependencies && moduleName in pkg.devDependencies;
const isDevDependency = !!pkg.devDependencies && moduleName in pkg.devDependencies;
return isDependency || isDevDependency;
}
20 changes: 10 additions & 10 deletions packages/main/src/modules/scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type Coords = {
*/
export function parseCoords(coords: string): Coords {
const [x, y] = coords.split(',');
return { x: parseInt(x, 10), y: parseInt(y, 10) };
return {x: parseInt(x, 10), y: parseInt(y, 10)};
}

/**
Expand All @@ -22,25 +22,25 @@ export function getRowsAndCols(parcels: Coords[]): {
rows: number;
cols: number;
} {
if (!parcels.length) return { rows: 0, cols: 0 };
if (!parcels.length) return {rows: 0, cols: 0};

const limits: { min: Coords; max: Coords } = {
min: { x: Infinity, y: Infinity },
max: { x: -Infinity, y: -Infinity },
const limits: {min: Coords; max: Coords} = {
min: {x: Infinity, y: Infinity},
max: {x: -Infinity, y: -Infinity},
};

parcels.forEach((parcel) => {
const { x, y } = parcel;
parcels.forEach(parcel => {
const {x, y} = parcel;

if (limits.min.y >= y) {
limits.min = { x: Math.min(limits.min.x, x), y };
limits.min = {x: Math.min(limits.min.x, x), y};
}

if (y >= limits.max.y) {
limits.max = { x: Math.max(limits.max.x, x), y };
limits.max = {x: Math.max(limits.max.x, x), y};
}

return { x, y };
return {x, y};
});

return {
Expand Down
16 changes: 7 additions & 9 deletions packages/main/src/modules/workspace.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import fs from 'fs';
import path from 'path';
import type { Scene } from '@dcl/schemas';
import type {Scene} from '@dcl/schemas';

import type { Project } from '/shared/types/projects';
import { hasDependency } from './pkg';
import { getCwd } from './cwd';
import { getRowsAndCols, parseCoords } from './scene';
import type {Project} from '/shared/types/projects';
import {hasDependency} from './pkg';
import {getCwd} from './cwd';
import {getRowsAndCols, parseCoords} from './scene';

export type Workspace = {
projects: Project[];
Expand Down Expand Up @@ -59,7 +59,7 @@ export function hasNodeModules(_path: string): boolean {
export function getProject(_path: string): Project {
try {
const scene = getScene(_path);
const parcels = scene.scene.parcels.map(($) => parseCoords($));
const parcels = scene.scene.parcels.map($ => parseCoords($));

return {
path: _path,
Expand All @@ -75,9 +75,7 @@ export function getProject(_path: string): Project {
templateStatus: null,
};
} catch (error: any) {
throw new Error(
`Could not get scene.json info for project in "${_path}": ${error.message}`,
);
throw new Error(`Could not get scene.json info for project in "${_path}": ${error.message}`);
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/preload/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { initRendererApi } from '../../main/src/ipc/api';
import {initRendererApi} from '../../main/src/ipc/api';

const api = initRendererApi();

export { api };
export {api};
36 changes: 21 additions & 15 deletions packages/renderer/src/components/App/component.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { useEffect } from 'react';
import { Provider as StoreProvider } from 'react-redux';
import { MemoryRouter as Router, Routes, Route } from 'react-router-dom';
import { ThemeProvider } from '@mui/material/styles';
import { dark } from 'decentraland-ui2/dist/theme';
import {useEffect} from 'react';
import {Provider as StoreProvider} from 'react-redux';
import {MemoryRouter as Router, Routes, Route} from 'react-router-dom';
import {ThemeProvider} from '@mui/material/styles';
import {dark} from 'decentraland-ui2/dist/theme';

import { store, useDispatch, useSelector } from '../../modules/store';
import { TranslationProvider } from '../../dapps-v2/TranslationProvider';
import { fetchTranslations } from '../../modules/store/reducers/translation';
import { locales } from '../../modules/store/reducers/translation/utils';
import { getWorkspace } from '../../modules/store/reducers/workspace/thunks';
import {store, useDispatch, useSelector} from '../../modules/store';
import {TranslationProvider} from '../../dapps-v2/TranslationProvider';
import {fetchTranslations} from '../../modules/store/reducers/translation';
import {locales} from '../../modules/store/reducers/translation/utils';
import {getWorkspace} from '../../modules/store/reducers/workspace/thunks';

import { ScenesPage } from '../ScenesPage';
import { SortBy } from '../ScenesPage/types';
import {ScenesPage} from '../ScenesPage';
import {SortBy} from '../ScenesPage/types';

import '../../themes';

const noop = () => undefined;

function Root() {
const dispatch = useDispatch();
const workspace = useSelector((state) => state.workspace);
const workspace = useSelector(state => state.workspace);

useEffect(() => {
dispatch(getWorkspace());
Expand All @@ -40,11 +40,17 @@ function Root() {
export function App() {
return (
<StoreProvider store={store}>
<TranslationProvider locales={locales} fetchTranslations={fetchTranslations}>
<TranslationProvider
locales={locales}
fetchTranslations={fetchTranslations}
>
<ThemeProvider theme={dark}>
<Router>
<Routes>
<Route path="/" element={<Root />} />
<Route
path="/"
element={<Root />}
/>
</Routes>
</Router>
</ThemeProvider>
Expand Down
4 changes: 2 additions & 2 deletions packages/renderer/src/components/App/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import { App } from './component';
export { App };
import {App} from './component';
export {App};
33 changes: 9 additions & 24 deletions packages/renderer/src/components/DeploymentStatus/component.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,22 @@
import classNames from 'classnames';
import { Badge } from 'decentraland-ui2';
import {Badge} from 'decentraland-ui2';

import { DeploymentStatus as Status } from '../../modules/deployment';
import { t } from '../../dapps-v2/translation/utils';
import {DeploymentStatus as Status} from '../../modules/deployment';
import {t} from '../../dapps-v2/translation/utils';

import type { Props } from './types';
import type {Props} from './types';

import './styles.css';

export function DeploymentStatus(props: Props) {
const { status, className = '', type } = props;
const {status, className = '', type} = props;
const classes = classNames('DeploymentStatus', 'status-badge', className);

if (
status === Status.PUBLISHED ||
(type === 'pool' && status === Status.NEEDS_SYNC)
) {
return (
<Badge className={classes}>
{t('scene_detail_page.published')}
</Badge>
);
if (status === Status.PUBLISHED || (type === 'pool' && status === Status.NEEDS_SYNC)) {
return <Badge className={classes}>{t('scene_detail_page.published')}</Badge>;
}
if (status === Status.NEEDS_SYNC) {
return (
<Badge className={classes}>
{t('scene_detail_page.unsynced')}
</Badge>
);
return <Badge className={classes}>{t('scene_detail_page.unsynced')}</Badge>;
}
return (
<Badge className={classes}>
{t('scene_detail_page.draft')}
</Badge>
);
return <Badge className={classes}>{t('scene_detail_page.draft')}</Badge>;
}
4 changes: 2 additions & 2 deletions packages/renderer/src/components/DeploymentStatus/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import { DeploymentStatus } from './component';
export { DeploymentStatus };
import {DeploymentStatus} from './component';
export {DeploymentStatus};
2 changes: 1 addition & 1 deletion packages/renderer/src/components/DeploymentStatus/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DeploymentStatus } from '../../modules/deployment';
import type {DeploymentStatus} from '../../modules/deployment';

export type Props = {
className?: string;
Expand Down
13 changes: 4 additions & 9 deletions packages/renderer/src/components/Icon/component.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type MouseEvent, type KeyboardEvent, useCallback } from 'react';
import {type MouseEvent, type KeyboardEvent, useCallback} from 'react';
import classNames from 'classnames';

import type { Props } from './types';
import type {Props} from './types';

import './styles.css';
import './sprite.css';
Expand All @@ -19,7 +19,7 @@ const isKeyboardEvent = (
): e is KeyboardEvent<HTMLElement> => (e as KeyboardEvent).key !== ' ';

export function Icon(props: Props) {
const { name, isActive = false, onClick, className = '' } = props;
const {name, isActive = false, onClick, className = ''} = props;
const iconName = isActive ? `${name}-active` : name;

const handleEvent = useCallback(
Expand All @@ -34,12 +34,7 @@ export function Icon(props: Props) {

return (
<div
className={classNames(
'Icon',
iconName,
{ clickeable: !!onClick },
className,
)}
className={classNames('Icon', iconName, {clickeable: !!onClick}, className)}
onClick={handleEvent}
onKeyUp={handleEvent}
/>
Expand Down
4 changes: 2 additions & 2 deletions packages/renderer/src/components/Icon/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import { Icon } from './component';
export { Icon };
import {Icon} from './component';
export {Icon};
Loading

0 comments on commit 0a832d8

Please sign in to comment.