janhq / jan

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer. Multiple engine support (llama.cpp, TensorRT-LLM)
https://jan.ai/
GNU Affero General Public License v3.0
23.74k stars 1.38k forks source link

chore: refactor rerender components #4040

Closed urmauur closed 1 week ago

urmauur commented 1 week ago

Describe Your Changes

  1. electron/managers/window.ts:

    • Added a new property show: false when creating the main window configuration.
    • Added an event listener for 'ready-to-show' on the main window. This feature toggle controls whether to show the main window once it is ready to be displayed.
  2. web/containers/Providers/DataLoader.tsx:

    • Imported additional functions and types from @janhq/core, including events and ModelEvent.
    • Introduced a new state variable isUpdated and an effect hook that listens for model updates using the useModels hook.
    • Inside this effect, it checks if isUpdated is true and then calls the loadDataModel function to reload the models.
  3. web/hooks/useModels.ts:

    • Removed the local variable isUpdated as it was being used inconsistently throughout the file.
    • Introduced a return object from the useModels hook that includes both loadDataModel and isUpdated.
    • Updated the useEffect to listen for model updates only if isUpdated is true, ensuring that the models are reloaded only when necessary.

These changes primarily involve improving the window management in Electron and enhancing the data loading process in a React component by incorporating real-time updates based on model changes. The introduction of feature toggles (show: false) and conditional event listeners helps in managing the visibility and behavior of application components more effectively.

Fixes Issues

Self Checklist

github-actions[bot] commented 1 week ago

Barecheck - Code coverage report

Total: 69.39% Your code coverage diff: 0.15% ▴
Uncovered files and lines
FileLines
core/src/browser/extension.ts105, 113-114, 125-126, 144-145, 147-149, 155, 199, 201, 208-212, 214-215
web/hooks/useModels.ts45, 59, 61, 65, 81-82, 85, 89, 100-101
web/hooks/usePath.ts9-11, 13, 15, 17-19, 22-23, 25-27, 30-32, 34-35, 37, 40-42, 45-46, 48, 50-54, 57-58, 60-64, 67