Skip to content

Conversation

boomwwww
Copy link
Contributor

@boomwwww boomwwww commented Aug 11, 2025

整理路由模块

  • 将路由相关的代码整理至src/router/index.tsx文件,这些代码原本在App组件内或在useHashRoute.ts文件内
  • 修改了部分拼写,将useHashRoute改为useHashRouter,将routers改为routes,将redirect改为goTo,如此更符合它们的语义
  • 移动GameEditorProviderTemplateEditorProvider组件。原本它们在src/components/Provider/文件夹下,但这两个组件在全局只会使用一次,将它们放在src/components/文件夹下不太合理,因为这里通常存放会复用的组件,因此本人将它们分别移动到了src/pages/editor/文件夹下和src/pages/templateEditor/文件夹下

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @boomwwww, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

I've undertaken a significant refactoring of the application's routing system. The primary goal was to centralize and streamline the routing logic, which was previously scattered across multiple files, including the main App.tsx component and a dedicated hook. This refactor introduces a new, dedicated router index file that encapsulates all routing definitions and navigation utilities. The changes also involve renaming key routing elements for better semantic clarity and relocating certain components to more appropriate directories based on their usage scope. This effort aims to enhance the overall maintainability, readability, and future extensibility of the application's navigation flow.

Highlights

  • Centralized Routing Logic: I've consolidated all routing-related code into a new central file, src/router/index.tsx. This includes the route definitions, the hash-based routing hook, and the navigation utility function. This change significantly improves the organization and maintainability of the routing logic, making it easier to understand and modify in the future.
  • Improved Naming Conventions: I've renamed several routing-related identifiers to improve their clarity and semantic meaning. Specifically, useHashRoute is now useHashRouter, routers is now routes, and redirect is now goTo. These changes make the code more intuitive and align better with common naming conventions.
  • Component Relocation for Better Encapsulation: The GameEditorProvider and TemplateEditorProvider components, which were previously located in src/components/Provider/, have been moved to their respective page directories (src/pages/editor/ and src/pages/templateEditor/). This relocation reflects their specific usage within those pages rather than as globally reusable components, enhancing module encapsulation.
  • Modernized Navigation Button Implementation: The navigation buttons within GameElement and TemplateElement components have been updated. Instead of using <a> tags with href attributes for navigation, they now use standard Button components with onClick handlers that call the new goTo utility function. This change provides more programmatic control over navigation and aligns with modern React practices for handling routing.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a nice refactoring that centralizes the routing logic into a dedicated src/router module, improving code organization and clarity. The renaming of functions and variables like useHashRoute to useHashRouter and redirect to goTo makes the code more semantic and easier to understand.

My review focuses on a pattern I noticed in the provider components (GameEditorProvider and TemplateEditorProvider). When these components perform a redirect, they don't stop their render execution, which can lead to unnecessary processing. I've suggested adding early returns to address this, which will make the components more efficient and robust.

Comment on lines 13 to 15
if (page !== 'game' || !gameDir) {
redirect('dashboard', 'game');
goTo('dashboard', 'game');
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

When a component redirects, it's a good practice to stop its rendering process to avoid unnecessary computations and potential side effects from hooks that run after the redirection logic. Here, the component continues to render after goTo is called. You should add return null; to exit early. This also allows removing the redundant semicolon on line 15.

  if (page !== 'game' || !gameDir) {
    goTo('dashboard', 'game');
    return null;
  }

Comment on lines 21 to 23
if (!fristLoading && !inGameList) {
redirect('dashboard', 'game');
goTo('dashboard', 'game');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the check above, you should return null after redirecting to prevent the component from rendering further in the current pass.

  if (!fristLoading && !inGameList) {
    goTo('dashboard', 'game');
    return null;
  }

Comment on lines 13 to 15
if (page !== 'template' || !templateDir) {
redirect('dashboard', 'template');
goTo('dashboard', 'template');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

When a component redirects, it's a good practice to stop its rendering process to avoid unnecessary computations. Here, the component continues to render after goTo is called. You should add return null; to exit early.

  if (page !== 'template' || !templateDir) {
    goTo('dashboard', 'template');
    return null;
  }

Comment on lines 21 to 23
if (!fristLoading && !inTemplateList) {
redirect('dashboard', 'template');
goTo('dashboard', 'template');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the check above, you should return null after redirecting to prevent the component from rendering further in the current pass.

  if (!fristLoading && !inTemplateList) {
    goTo('dashboard', 'template');
    return null;
  }

const page = useEditorStore.use.page();
const subPage = useEditorStore.use.subPage();
if (page !== 'template' || !subPage) redirect('dashboard');
if (page !== 'template' || !subPage) goTo('dashboard');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To prevent the component from continuing its render cycle after redirection, you should return early. This avoids running subsequent hooks and logic unnecessarily.

  if (page !== 'template' || !subPage) {
    goTo('dashboard');
    return null;
  }

<span className={styles.templateElement_dir}>{props.templateInfo.dir}</span>
<div className={styles.templateElement_action} onClick={(event) => event.stopPropagation()}>
<Button appearance='primary' as='a' href={`${routers.template.url}/${props.templateInfo.dir}`}>
<Button appearance='primary' onClick={() => goTo('template', props.templateInfo.dir)}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

先前的做法可以方便用户用鼠标中键在新标签页打开编辑界面

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已改回

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants