一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
91 行
2.5 KiB
TypeScript
91 行
2.5 KiB
TypeScript
import { Dispatch } from 'redux';
|
|
import Folder from './models/Folder';
|
|
import Setting from './models/Setting';
|
|
import shim from './shim';
|
|
import { FolderLoadOptions } from './models/utils/types';
|
|
|
|
const refreshCalls_: boolean[] = [];
|
|
let scheduleRefreshFoldersIID_: ReturnType<typeof shim.setTimeout> = null;
|
|
|
|
export const allForDisplay = async (options: FolderLoadOptions = {}) => {
|
|
const orderDir = Setting.value('folders.sortOrder.reverse') ? 'DESC' : 'ASC';
|
|
|
|
const folderOptions: FolderLoadOptions = {
|
|
caseInsensitive: true,
|
|
order: [
|
|
{
|
|
by: 'title',
|
|
dir: orderDir,
|
|
},
|
|
],
|
|
...options,
|
|
};
|
|
|
|
let folders = await Folder.all(folderOptions);
|
|
|
|
if (Setting.value('folders.sortOrder.field') === 'last_note_user_updated_time') {
|
|
folders = await Folder.orderByLastModified(folders, orderDir);
|
|
}
|
|
|
|
if (Setting.value('showNoteCounts')) {
|
|
await Folder.addNoteCounts(folders,
|
|
Setting.value('showCompletedTodos'));
|
|
}
|
|
|
|
return folders;
|
|
};
|
|
|
|
// `selectedFolderId` should be the currently selected folder. Set it to an empty string if that
|
|
// information is not available in the current context.
|
|
export const refreshFolders = async (dispatch: Dispatch, selectedFolderId: string) => {
|
|
refreshCalls_.push(true);
|
|
try {
|
|
const folders = await allForDisplay({
|
|
includeConflictFolder: true,
|
|
includeTrash: true,
|
|
});
|
|
|
|
dispatch({
|
|
type: 'FOLDER_UPDATE_ALL',
|
|
items: folders,
|
|
});
|
|
|
|
// If the currently selected folder no longer exists and a smart filter is not set, select a default folder
|
|
const notesParent = Setting.value('notesParent');
|
|
if ((!notesParent || JSON.parse(notesParent).type !== 'SmartFilter') && selectedFolderId && !folders.find(f => f.id === selectedFolderId)) {
|
|
const defaultFolder = await Folder.defaultFolder();
|
|
if (defaultFolder) {
|
|
dispatch({
|
|
type: 'FOLDER_SELECT',
|
|
id: defaultFolder.id,
|
|
});
|
|
}
|
|
}
|
|
} finally {
|
|
refreshCalls_.pop();
|
|
}
|
|
};
|
|
|
|
export const scheduleRefreshFolders = async (dispatch: Dispatch, selectedFolderId: string) => {
|
|
if (scheduleRefreshFoldersIID_) shim.clearTimeout(scheduleRefreshFoldersIID_);
|
|
scheduleRefreshFoldersIID_ = shim.setTimeout(() => {
|
|
scheduleRefreshFoldersIID_ = null;
|
|
void refreshFolders(dispatch, selectedFolderId);
|
|
}, 1000);
|
|
};
|
|
|
|
export const cancelTimers = async () => {
|
|
if (scheduleRefreshFoldersIID_) {
|
|
shim.clearTimeout(scheduleRefreshFoldersIID_);
|
|
scheduleRefreshFoldersIID_ = null;
|
|
}
|
|
return new Promise((resolve) => {
|
|
const iid = shim.setInterval(() => {
|
|
if (!refreshCalls_.length) {
|
|
shim.clearInterval(iid);
|
|
resolve(null);
|
|
}
|
|
}, 100);
|
|
});
|
|
};
|