From d4b8ee5136473bc392be352b20ce30d1d8e08818 Mon Sep 17 00:00:00 2001 From: Jake Date: Mon, 23 Dec 2024 16:14:21 -0800 Subject: [PATCH] Update memos extension - feat: support memos@0.23.0 - feat: support memos@0.23.0 - Initial commit --- extensions/memos/CHANGELOG.md | 4 +++ extensions/memos/src/api.ts | 35 ++++++++++++++++++++------- extensions/memos/src/sendMemoForm.tsx | 27 ++++++++++++++------- extensions/memos/src/types.ts | 13 +++++----- 4 files changed, 55 insertions(+), 24 deletions(-) diff --git a/extensions/memos/CHANGELOG.md b/extensions/memos/CHANGELOG.md index 3a5b3e1437d..c6cfb81fa5f 100644 --- a/extensions/memos/CHANGELOG.md +++ b/extensions/memos/CHANGELOG.md @@ -1,5 +1,9 @@ # Send To Memos Changelog +## [Update] - 2024-12-23 + +- support memos@0.23.0. + ## [Update] - 2024-07-20 - support sendMemoForm. diff --git a/extensions/memos/src/api.ts b/extensions/memos/src/api.ts index 1396e58d2cc..d0c56048745 100644 --- a/extensions/memos/src/api.ts +++ b/extensions/memos/src/api.ts @@ -8,7 +8,7 @@ import mime from "mime"; import axios, { AxiosRequestConfig } from "axios"; import { Preferences, ResponseData, ROW_STATUS, ResourceObj } from "./types"; -import { MeResponse, PostFileResponse, PostMemoParams, MemoInfoResponse, TagResponse } from "./types"; +import { MeResponse, PostFileResponse, PostMemoParams, MemoInfoResponse } from "./types"; const cache = new Cache(); @@ -125,15 +125,32 @@ export const sendMemo = (data: PostMemoParams) => { }); }; -export const getTags = () => { - const url = getRequestUrl(`/api/v1/memos/-/tags`); +export const getRecentTags = async (): Promise => { + const me = await getFetch({ + url: getRequestUrl(`/api/v1/auth/status`), + method: "POST", + }); - return getUseFetch(url, { - keepPreviousData: true, - initialData: { - tagAmounts: {}, - }, + const memos = await getFetch<{ + memos: MemoInfoResponse[]; + }>({ + url: getRequestUrl(`/api/v1/memos?pageSize=50&filter=creator=='users/${me.id}'`), + method: "GET", + }); + + const recentTags: string[] = []; + + memos.memos.forEach((memo) => { + const tags = memo.property?.tags || []; + + tags.forEach((tag) => { + if (!recentTags.includes(tag)) { + recentTags.push(tag); + } + }); }); + + return recentTags; }; export const postFile = (filePath: string, filename: string) => { @@ -246,7 +263,7 @@ export const deleteMemo = (memoId: string) => { export const getResourceBin = (resourceName: string, resourceFilename: string) => { const url = getRequestUrl(`/file/${resourceName}/${resourceFilename}`); - return getFetch({ + return getFetch({ url, method: "GET", responseType: "blob", diff --git a/extensions/memos/src/sendMemoForm.tsx b/extensions/memos/src/sendMemoForm.tsx index 8f4610578b6..5b86df70e1d 100644 --- a/extensions/memos/src/sendMemoForm.tsx +++ b/extensions/memos/src/sendMemoForm.tsx @@ -1,7 +1,7 @@ import { Form, Detail, ActionPanel, Action, showToast, Toast, open, popToRoot } from "@raycast/api"; -import { useState } from "react"; +import { useEffect, useState } from "react"; import { MemoInfoResponse, PostFileResponse, PostMemoParams } from "./types"; -import { getOriginUrl, getRequestUrl, getTags, postFile, postMemoResources, sendMemo } from "./api"; +import { getOriginUrl, getRecentTags, getRequestUrl, postFile, postMemoResources, sendMemo } from "./api"; import { VISIBILITY } from "./constant"; interface FormData { @@ -12,11 +12,22 @@ interface FormData { } export default function SendMemoFormCommand(): JSX.Element { - const { isLoading, data: existTags } = getTags(); const [nameError, setNameError] = useState(); const [files, setFiles] = useState([]); const [createdMarkdown, setCreatedMarkdown] = useState(); const [createdUrl, setCreatedUrl] = useState(); + const [isLoading, setIsLoading] = useState(true); + const [recentTags, setRecentTags] = useState([]); + + useEffect(() => { + getRecentTags() + .then((tags) => { + setRecentTags(tags); + }) + .finally(() => { + setIsLoading(false); + }); + }, []); function dropNameErrorIfNeeded() { if (nameError && nameError.length > 0) { @@ -152,12 +163,10 @@ export default function SendMemoFormCommand(): JSX.Element { - - {Object.keys(existTags?.tagAmounts) - ?.filter((tag) => !!existTags?.tagAmounts[tag]) - ?.map((tag) => { - return ; - })} + + {recentTags.map((tag) => { + return ; + })} diff --git a/extensions/memos/src/types.ts b/extensions/memos/src/types.ts index e94935b2811..fc641a312e6 100644 --- a/extensions/memos/src/types.ts +++ b/extensions/memos/src/types.ts @@ -53,13 +53,14 @@ export interface MemoInfoResponse { pinned: boolean; displayTs: number; resources: ResourceObj[]; -} - -export type TagResponse = { - tagAmounts: { - [tag: string]: number; + property: { + tags: string[]; + hasLink: boolean; + hasTaskList: boolean; + hasCode: boolean; + hasIncompleteTasks: boolean; }; -}; +} export interface MeResponse { id: number;