fix: restore AI suggestion filter by selection, cache PromptTemplateManager
Cache PromptTemplateManager in ref to prevent new instance per render. Filter: show only Rearrange/favorites when MIDI item selected, all presets otherwise. Root cause of 'suggestion added at top' was stale array reference from new instance every render.
This commit is contained in:
@@ -7294,6 +7294,7 @@ const App = () => {
|
||||
const [showAiTypeahead, setShowAiTypeahead] = useState(false);
|
||||
const [showAISuggestions, setShowAISuggestions] = useState(true);
|
||||
const [showAIActionLog, setShowAIActionLog] = useState(false);
|
||||
const aiPromptMgrRef = useRef(null);
|
||||
const [selectedProviderId, setSelectedProviderId] = useState('');
|
||||
const [exportSettings, setExportSettings] = useState({
|
||||
sampleRate: '44100',
|
||||
@@ -16176,8 +16177,11 @@ const App = () => {
|
||||
if (panelId === 'ai') {
|
||||
const selMidiInfo = getSelectedMidiItemInfo();
|
||||
const hasSelItem = !!selMidiInfo;
|
||||
const promptMgr = window.PromptTemplateManager ? new window.PromptTemplateManager() : null;
|
||||
const suggestions = promptMgr ? promptMgr.presets : [];
|
||||
if (window.PromptTemplateManager && !aiPromptMgrRef.current) {
|
||||
aiPromptMgrRef.current = new window.PromptTemplateManager();
|
||||
}
|
||||
const promptMgr = aiPromptMgrRef.current;
|
||||
const suggestions = promptMgr ? (hasSelItem ? promptMgr.presets.filter(function(p) { return p.category === 'Rearrange / Variation' || p.is_favorite; }) : promptMgr.presets) : [];
|
||||
const handleApplySuggestion = (preset) => {
|
||||
if (hasSelItem) {
|
||||
setAiPrompt(`Rearrange this melody line in ${preset.name} style`);
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -700,3 +700,9 @@
|
||||
- **Các file ảnh hưởng:** `app/static/js/app.jsx`
|
||||
- **Ghi chú/Test (nếu có):** `npm run build` — build passes.
|
||||
---
|
||||
|
||||
### [2026-07-29 10:12] Task: Restore AI suggestion filter by selection + fix stale instance
|
||||
- **Tóm tắt thay đổi:** Restore filter: khi chọn MIDI item chỉ hiện Rearrange/favorites, không chọn thì hiện tất cả. Fix gốc: cache PromptTemplateManager qua `aiPromptMgrRef` thay vì `new` mỗi render — tránh thay đổi array reference gây re-render suggestion list.
|
||||
- **Các file ảnh hưởng:** `app/static/js/app.jsx`
|
||||
- **Ghi chú/Test (nếu có):** `npm run build` — build passes.
|
||||
---
|
||||
|
||||
Reference in New Issue
Block a user