Skip to content

Commit

Permalink
add editor loading screen
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoecheza committed Jul 23, 2024
1 parent 743245b commit 81b98c4
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 51 deletions.
2 changes: 2 additions & 0 deletions packages/main/src/mainWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ async function createWindow() {
},
});

browserWindow.setMenuBarVisibility(false);

Check failure on line 17 in packages/main/src/mainWindow.ts

View workflow job for this annotation

GitHub Actions / tests / tests (windows-latest)

tests/unit.spec.ts > Should create a new window

TypeError: browserWindow.setMenuBarVisibility is not a function ❯ createWindow src/mainWindow.ts:17:17 ❯ Module.restoreOrCreateWindow src/mainWindow.ts:68:20 ❯ tests/unit.spec.ts:42:9

Check failure on line 17 in packages/main/src/mainWindow.ts

View workflow job for this annotation

GitHub Actions / tests / tests (windows-latest)

tests/unit.spec.ts > Should restore an existing window

TypeError: browserWindow.setMenuBarVisibility is not a function ❯ createWindow src/mainWindow.ts:17:17 ❯ Module.restoreOrCreateWindow src/mainWindow.ts:68:20 ❯ tests/unit.spec.ts:59:9

Check failure on line 17 in packages/main/src/mainWindow.ts

View workflow job for this annotation

GitHub Actions / tests / tests (windows-latest)

tests/unit.spec.ts > Should create a new window if the previous one was destroyed

TypeError: browserWindow.setMenuBarVisibility is not a function ❯ createWindow src/mainWindow.ts:17:17 ❯ Module.restoreOrCreateWindow src/mainWindow.ts:68:20 ❯ tests/unit.spec.ts:73:9

Check failure on line 17 in packages/main/src/mainWindow.ts

View workflow job for this annotation

GitHub Actions / tests / tests (ubuntu-latest)

tests/unit.spec.ts > Should create a new window

TypeError: browserWindow.setMenuBarVisibility is not a function ❯ createWindow src/mainWindow.ts:17:17 ❯ Module.restoreOrCreateWindow src/mainWindow.ts:68:20 ❯ tests/unit.spec.ts:42:9

Check failure on line 17 in packages/main/src/mainWindow.ts

View workflow job for this annotation

GitHub Actions / tests / tests (ubuntu-latest)

tests/unit.spec.ts > Should restore an existing window

TypeError: browserWindow.setMenuBarVisibility is not a function ❯ createWindow src/mainWindow.ts:17:17 ❯ Module.restoreOrCreateWindow src/mainWindow.ts:68:20 ❯ tests/unit.spec.ts:59:9

Check failure on line 17 in packages/main/src/mainWindow.ts

View workflow job for this annotation

GitHub Actions / tests / tests (ubuntu-latest)

tests/unit.spec.ts > Should create a new window if the previous one was destroyed

TypeError: browserWindow.setMenuBarVisibility is not a function ❯ createWindow src/mainWindow.ts:17:17 ❯ Module.restoreOrCreateWindow src/mainWindow.ts:68:20 ❯ tests/unit.spec.ts:73:9

Check failure on line 17 in packages/main/src/mainWindow.ts

View workflow job for this annotation

GitHub Actions / tests / tests (macos-latest)

tests/unit.spec.ts > Should create a new window

TypeError: browserWindow.setMenuBarVisibility is not a function ❯ createWindow src/mainWindow.ts:17:17 ❯ Module.restoreOrCreateWindow src/mainWindow.ts:68:20 ❯ tests/unit.spec.ts:42:9

Check failure on line 17 in packages/main/src/mainWindow.ts

View workflow job for this annotation

GitHub Actions / tests / tests (macos-latest)

tests/unit.spec.ts > Should restore an existing window

TypeError: browserWindow.setMenuBarVisibility is not a function ❯ createWindow src/mainWindow.ts:17:17 ❯ Module.restoreOrCreateWindow src/mainWindow.ts:68:20 ❯ tests/unit.spec.ts:59:9

Check failure on line 17 in packages/main/src/mainWindow.ts

View workflow job for this annotation

GitHub Actions / tests / tests (macos-latest)

tests/unit.spec.ts > Should create a new window if the previous one was destroyed

TypeError: browserWindow.setMenuBarVisibility is not a function ❯ createWindow src/mainWindow.ts:17:17 ❯ Module.restoreOrCreateWindow src/mainWindow.ts:68:20 ❯ tests/unit.spec.ts:73:9

/**
* If the 'show' property of the BrowserWindow's constructor is omitted from the initialization options,
* it then defaults to 'true'. This can cause flickering as the window loads the html content,
Expand Down
11 changes: 7 additions & 4 deletions packages/renderer/src/components/Dropdown/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ function Dropdown(props: Props) {
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
const open = Boolean(anchorEl);

const handleClick = useCallback((event: MouseEvent<HTMLElement>) => {
setAnchorEl(event.currentTarget);
const handleClick = useCallback((e: MouseEvent<HTMLElement>) => {
e.stopPropagation();
setAnchorEl(e.currentTarget);
}, []);

const handleSelect = useCallback((_: MouseEvent<HTMLLIElement>, option: Option) => {
const handleSelect = useCallback((e: MouseEvent<HTMLLIElement>, option: Option) => {
e.stopPropagation();
setAnchorEl(null);
option.handler();
}, []);

const handleClose = useCallback(() => {
const handleClose = useCallback((e: MouseEvent<HTMLElement>) => {
e.stopPropagation();
setAnchorEl(null);
}, []);

Expand Down
54 changes: 29 additions & 25 deletions packages/renderer/src/components/ProjectCard/component.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useCallback, useState } from 'react';
import ViewModuleIcon from '@mui/icons-material/ViewModule';
import cx from 'classnames';
import { Link } from 'react-router-dom';

import { getThumbnailUrl } from '/@/modules/project';
import { t } from '/@/modules/store/translation/utils';
Expand All @@ -13,10 +12,14 @@ import type { Props } from './types';

import './styles.css';

export function ProjectCard({ project, onDelete, onDuplicate }: Props) {
export function ProjectCard({ project, onClick, onDelete, onDuplicate }: Props) {
const [open, setOpen] = useState(false);
const parcels = project.layout.cols * project.layout.rows;

const handleClick = useCallback(() => {
if (onClick) onClick(project);
}, [project, onClick]);

const handleDeleteProject = useCallback(() => {
onDelete(project);
handleCloseModal();
Expand Down Expand Up @@ -48,36 +51,37 @@ export function ProjectCard({ project, onDelete, onDuplicate }: Props) {
];

return (
<div className={cx('ProjectCard', { 'has-thumbnail': !!thumbnailUrl })}>
<Link
to={`/editor?path=${encodeURIComponent(project.path)}`}
className="project-thumbnail"
style={thumbnailUrl ? { backgroundImage: `url(${thumbnailUrl})` } : {}}
/>
<div className="project-data">
<Link
to={`/editor?path=${encodeURIComponent(project.path)}`}
className="title-wrapper"
>
<div className="title">{project.title}</div>
<div
className="description"
title={project.description}
>
<ViewModuleIcon className="Icon" /> {t('scene_list.parcel_count', { parcels })}
</div>
</Link>
<Dropdown
className="options-dropdown"
options={dropdownOptions}
<>
<div
className={cx('ProjectCard', { 'has-thumbnail': !!thumbnailUrl })}
onClick={handleClick}
>
<div
className="project-thumbnail"
style={thumbnailUrl ? { backgroundImage: `url(${thumbnailUrl})` } : {}}
/>
<div className="project-data">
<div className="title-wrapper">
<div className="title">{project.title}</div>
<div
className="description"
title={project.description}
>
<ViewModuleIcon className="Icon" /> {t('scene_list.parcel_count', { parcels })}
</div>
</div>
<Dropdown
className="options-dropdown"
options={dropdownOptions}
/>
</div>
</div>
<DeleteProject
open={open}
project={project}
onClose={handleCloseModal}
onSubmit={handleDeleteProject}
/>
</div>
</>
);
}
1 change: 1 addition & 0 deletions packages/renderer/src/components/ProjectCard/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Project } from '/shared/types/projects';

export type Props = {
project: Project;
onClick: (project: Project) => void;
onDelete: (project: Project) => void;
onDuplicate: (project: Project) => void;
};
4 changes: 3 additions & 1 deletion packages/renderer/src/components/SceneList/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ function NoScenesAnchor(content: string) {
}

export function SceneList({ projects, sortBy, onSort }: Props) {
const { deleteProject, duplicateProject, importProject, createProject } = useWorkspace();
const { selectProject, deleteProject, duplicateProject, importProject, createProject } =
useWorkspace();

const sort = useCallback(
(_sortBy: SortBy) => {
Expand Down Expand Up @@ -65,6 +66,7 @@ export function SceneList({ projects, sortBy, onSort }: Props) {
<ProjectCard
key={project.path}
project={project}
onClick={selectProject}
onDelete={deleteProject}
onDuplicate={duplicateProject}
/>
Expand Down
12 changes: 2 additions & 10 deletions packages/renderer/src/hooks/useEditor.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import { useCallback, useMemo } from 'react';
import { useSearchParams } from 'react-router-dom';
import { useCallback } from 'react';

import { useDispatch, useSelector } from '#store';

import type { DeployOptions } from '/shared/types/ipc';
import { actions } from '/@/modules/store/editor';

import { useWorkspace } from './useWorkspace';

export const useEditor = () => {
const dispatch = useDispatch();
const editor = useSelector(state => state.editor);
const [search] = useSearchParams();
const path = useMemo(() => search.get('path'), [search]);
const workspace = useWorkspace();
const project = useMemo(() => {
return workspace.projects.find(project => project.path === path);
}, [workspace.projects, path]);
const { project } = editor;

const startInspector = useCallback(() => {
dispatch(actions.startInspector());
Expand Down
30 changes: 21 additions & 9 deletions packages/renderer/src/hooks/useWorkspace.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,60 @@
import { useDispatch, useSelector } from '#store';
import { useCallback } from 'react';
import { actions } from '/@/modules/store/workspace';

import { type Project, type SortBy } from '/shared/types/projects';

import { actions as editorActions } from '/@/modules/store/editor';
import { actions as workspaceActions } from '/@/modules/store/workspace';
import { useNavigate } from 'react-router-dom';

export const useWorkspace = () => {
const dispatch = useDispatch();
const navigate = useNavigate();
const workspace = useSelector(state => state.workspace);

const getWorkspace = useCallback(() => {
dispatch(actions.getWorkspace());
dispatch(workspaceActions.getWorkspace());
}, []);

const setSortBy = useCallback((type: SortBy) => {
dispatch(actions.setSortBy(type));
dispatch(workspaceActions.setSortBy(type));
}, []);

const selectProject = useCallback((project: Project) => {
dispatch(editorActions.setProject(project));
navigate('/editor');
}, []);

const createProject = useCallback(() => {
dispatch(actions.createProject());
dispatch(workspaceActions.createProject());
navigate('/editor');
}, []);

const deleteProject = useCallback((project: Project) => {
dispatch(actions.deleteProject(project.path));
dispatch(workspaceActions.deleteProject(project.path));
}, []);

const duplicateProject = useCallback((project: Project) => {
dispatch(actions.duplicateProject(project.path));
dispatch(workspaceActions.duplicateProject(project.path));
}, []);

const importProject = useCallback(() => {
dispatch(actions.importProject());
dispatch(workspaceActions.importProject());
}, []);

const reimportProject = useCallback((path: string) => {
dispatch(actions.reimportProject(path));
dispatch(workspaceActions.reimportProject(path));
}, []);

const unlistProjects = useCallback((paths: string[]) => {
dispatch(actions.unlistProjects(paths));
dispatch(workspaceActions.unlistProjects(paths));
}, []);

return {
...workspace,
getWorkspace,
setSortBy,
selectProject,
createProject,
deleteProject,
duplicateProject,
Expand Down
18 changes: 16 additions & 2 deletions packages/renderer/src/modules/store/editor/slice.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { editor } from '#preload';
import { createAsyncThunk, createSlice } from '@reduxjs/toolkit';
import { createAsyncThunk, createSlice, type PayloadAction } from '@reduxjs/toolkit';

import { type Project } from '/shared/types/projects';
import { actions as workspaceActions } from '../workspace';

// actions
export const startInspector = createAsyncThunk('editor/startInspector', editor.startInspector);
Expand All @@ -9,6 +12,7 @@ export const openPreview = createAsyncThunk('editor/openPreview', editor.openPre

// state
export type EditorState = {
project?: Project;
inspectorPort: number;
previewPort: number;
publishPort: number;
Expand All @@ -34,7 +38,11 @@ const initialState: EditorState = {
export const slice = createSlice({
name: 'editor',
initialState,
reducers: {},
reducers: {
setProject: (state, { payload: project }: PayloadAction<Project>) => {
state.project = project;
},
},
extraReducers: builder => {
builder.addCase(startInspector.pending, state => {
state.inspectorPort = 0;
Expand Down Expand Up @@ -72,6 +80,12 @@ export const slice = createSlice({
state.error = action.error.message || null;
state.loadingPublish = false;
});
builder.addCase(workspaceActions.createProject.pending, state => {
state.project = undefined;
});
builder.addCase(workspaceActions.createProject.fulfilled, (state, action) => {
state.project = action.payload;
});
},
});

Expand Down

0 comments on commit 81b98c4

Please sign in to comment.