From 78a5cb759c7cfe33a7ee227a1199a7956bbf3ccf Mon Sep 17 00:00:00 2001 From: dubisdev Date: Sat, 9 Mar 2024 14:01:54 +0100 Subject: [PATCH] chore: remove unused code --- .../todoist/src/components/TaskInfo/index.tsx | 56 -------- .../src/components/TaskInfo/styles.module.css | 23 ---- .../src/services/displayArrayGenerator.tsx | 122 ------------------ .../src/services/startPageAfterUpdate.tsx | 56 -------- 4 files changed, 257 deletions(-) delete mode 100644 extensions/todoist/src/components/TaskInfo/index.tsx delete mode 100644 extensions/todoist/src/components/TaskInfo/styles.module.css delete mode 100644 extensions/todoist/src/services/displayArrayGenerator.tsx delete mode 100644 extensions/todoist/src/services/startPageAfterUpdate.tsx diff --git a/extensions/todoist/src/components/TaskInfo/index.tsx b/extensions/todoist/src/components/TaskInfo/index.tsx deleted file mode 100644 index dd381a8..0000000 --- a/extensions/todoist/src/components/TaskInfo/index.tsx +++ /dev/null @@ -1,56 +0,0 @@ -import { KeyboardNavItem, KeyboardNav } from "@cerebroapp/cerebro-ui"; -import { completeTask, deleteTask, getTaskHour } from "services/taskServices"; -import styles from "./styles.module.css"; -import lang from "lang"; -const strings = lang.TaskInfo; - -const ListItem = ({ children, onSelect = () => {} }) => { - return ( - - {children} - - ); -}; - -const TasksInfoPreview = ({ task, actions, client }) => { - const complete = (task) => { - completeTask(client, task); - actions.hideWindow(); - }; - const del = (task) => { - deleteTask(client, task); - actions.hideWindow(); - }; - - const goToProject = (task) => { - actions.replaceTerm("tds view ##" + task.projectName); - }; - - const taskHour = getTaskHour(task); - const { content, description, projectName } = task; - - return ( -
-

{content}

- -
    - {taskHour && {taskHour}} - {description && {description}} - {projectName && ( - goToProject(task)}> - {projectName} - - )} - complete(task)}> - {strings.completeTaskButton} - - del(task)}> - {strings.deleteTaskButton} - -
-
-
- ); -}; - -export default TasksInfoPreview; diff --git a/extensions/todoist/src/components/TaskInfo/styles.module.css b/extensions/todoist/src/components/TaskInfo/styles.module.css deleted file mode 100644 index c874800..0000000 --- a/extensions/todoist/src/components/TaskInfo/styles.module.css +++ /dev/null @@ -1,23 +0,0 @@ -.wrapper { - background-color: rgba(0, 0, 0, 0.438); - align-self: flex-start; - width: 100%; - margin: -10px; - position: relative; - transition: all 0.3s linear; -} - -.list { - margin: 0; - padding: 0; -} - -@keyframes scroll { - 0% { - top: 50%; - } - - 100% { - top: -25%; - } -} \ No newline at end of file diff --git a/extensions/todoist/src/services/displayArrayGenerator.tsx b/extensions/todoist/src/services/displayArrayGenerator.tsx deleted file mode 100644 index ea5d4ab..0000000 --- a/extensions/todoist/src/services/displayArrayGenerator.tsx +++ /dev/null @@ -1,122 +0,0 @@ -import { getSubCommandText } from 'cerebro-command-router'; -import { completeTask } from './taskServices'; -import pDebounce from 'p-debounce'; -import { TaskInfo } from '../components'; - -import lang from '../lang'; -import type { TodoistApi, Task } from '@doist/todoist-api-typescript'; -import { CerebroScreen } from 'cerebro-command-router/dist/definitions'; -const strings = lang.displayArrayGenerator; - -type Options = { - type?: 'today' | 'view'; - client: TodoistApi; - term: string; - actions: object; - showOverdue?: boolean; -}; - -const ItaskArrayGenerator = (opts: Options) => { - const { type } = opts; - switch (type) { - case 'today': - return todayTaskArrayGenerator(opts); - case 'view': - return filterTaskArrayGenerator(opts); - default: - return todayTaskArrayGenerator(opts); - } -}; - -type tTAG = (opts: Options) => Promise; -const todayTaskArrayGenerator: tTAG = async ({ - client, - showOverdue, - term, - actions -}) => { - let taskArray: Task[]; - - const contentSearch = getSubCommandText(term); - const filter = contentSearch - ? `(today | overdue) & search:${contentSearch}` - : 'today | overdue'; - - try { - taskArray = showOverdue - ? await client.getTasks({ filter }) - : await client.getTasks({ filter: 'today' }); - } catch (err) { - return handleErrors(err); - } - - if (taskArray.length === 0) { - if (contentSearch) return [{ title: strings.noFilteredTasksFound }]; - else return [{ title: strings.noTodayTasks }]; - } - - // API restrictions - only call <= 10 times - if (taskArray.length <= 10) { - taskArray = await Promise.all( - taskArray.map(async (task) => { - const projectName = (await client.getProject(task.projectId)).name; - return { ...task, projectName }; - }) - ); - } - - return taskArray.map((task) => { - return { - title: task.content, - onSelect: () => completeTask(client, task), - getPreview: () => ( - - ) - }; - }); -}; - -const filterTaskArrayGenerator = async ({ client, term, actions }: Options) => { - const filter = getSubCommandText(term); - - if (!filter) return Promise.resolve([{ title: strings.noFilterFound }]); - - let fullTasksList: Task[]; - - try { - fullTasksList = await client.getTasks({ filter }); - } catch (err) { - return handleErrors(err); - } - - if (fullTasksList.length === 0) { return [{ title: strings.noFilteredTasksFound }]; } - - if (fullTasksList.length <= 10) { - fullTasksList = await Promise.all( - fullTasksList.map(async (task) => { - const projectName = (await client.getProject(task.projectId)).name; - return { ...task, projectName }; - }) - ); - } - - return fullTasksList.map((task) => ({ - title: task.content, - onSelect: () => completeTask(client, task), - getPreview: () => ( - - ) - })); -}; - -const handleErrors = (err) => { - if (err?.response?.data?.includes('filter')) { - return [{ title: strings.filterError }]; - } - - return [{ title: lang.TaskInfo.error }]; -}; - -const debouncedTaskArrayGenerator = pDebounce(ItaskArrayGenerator, 275); - -export default debouncedTaskArrayGenerator; diff --git a/extensions/todoist/src/services/startPageAfterUpdate.tsx b/extensions/todoist/src/services/startPageAfterUpdate.tsx deleted file mode 100644 index b004c32..0000000 --- a/extensions/todoist/src/services/startPageAfterUpdate.tsx +++ /dev/null @@ -1,56 +0,0 @@ -import PluginUpdated from "components/UpdatedPluginPage"; -import icon from "../icons"; -import { settings } from "../settings"; -import lang from "../lang"; -import pkgJson from "../../package.json"; -import CerebroRouter from "cerebro-command-router"; -import { - CerebroActions, - CerebroConfig, -} from "cerebro-command-router/dist/definitions"; - -export default ( - config: CerebroConfig, - myRouter: CerebroRouter, - actions: CerebroActions -) => { - let firstUpdateStart = getFirstUpdateStart(config); - - // undefined == not set == first update start - if (firstUpdateStart === undefined) { - myRouter.invalidRoute({ - icon, - order: 0, - title: lang.workflow_update, - getPreview: () => , - }); - } -}; - -export const setFirstUpdateStartToFalse = (config: CerebroConfig) => { - let jsonConfig = config.get("plugins"); - - //delete old version entries --> filter for keys in settings.js - let result = {}; - - for (let key in jsonConfig["cerebro-cerebro-todoist"]) { - if (settings.hasOwnProperty(key)) { - result[key] = jsonConfig["cerebro-cerebro-todoist"][key]; - } - } - - // save previous settings - jsonConfig["cerebro-cerebro-todoist"] = result; - - // update firstUpdateStart - jsonConfig["cerebro-cerebro-todoist"][`firstUpdateStart${pkgJson.version}`] = - false; - - config.set("plugins", jsonConfig); -}; - -export const getFirstUpdateStart = (config: CerebroConfig) => { - return config.get("plugins")["cerebro-cerebro-todoist"]?.[ - `firstUpdateStart${pkgJson.version}` - ]; -};