fix: clicking posts in filtered lists
This commit is contained in:
@@ -1028,14 +1028,21 @@ export const Editor: React.FC = () => {
|
|||||||
}
|
}
|
||||||
}, [activeView, selectedMediaId, media, isLoading, setSelectedMedia]);
|
}, [activeView, selectedMediaId, media, isLoading, setSelectedMedia]);
|
||||||
|
|
||||||
// Close tab if the item doesn't exist anymore
|
// Close tab if the item doesn't exist anymore, or fetch it if not yet loaded
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (activeTab && !isLoading) {
|
if (activeTab && !isLoading) {
|
||||||
if (activeTab.type === 'post') {
|
if (activeTab.type === 'post') {
|
||||||
const postExists = posts.some(p => p.id === activeTab.id);
|
const postExists = posts.some(p => p.id === activeTab.id);
|
||||||
if (!postExists) {
|
if (!postExists) {
|
||||||
|
// Post might not be loaded yet (pagination / filtered view) — try fetching it
|
||||||
|
window.electronAPI?.posts.get(activeTab.id).then((post) => {
|
||||||
|
if (post) {
|
||||||
|
useAppStore.getState().addPost(post as PostData);
|
||||||
|
} else {
|
||||||
closeTab(activeTab.id);
|
closeTab(activeTab.id);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
} else if (activeTab.type === 'media') {
|
} else if (activeTab.type === 'media') {
|
||||||
const mediaExists = media.some(m => m.id === activeTab.id);
|
const mediaExists = media.some(m => m.id === activeTab.id);
|
||||||
if (!mediaExists) {
|
if (!mediaExists) {
|
||||||
|
|||||||
Reference in New Issue
Block a user