Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update memos extension #16023

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions extensions/memos/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Send To Memos Changelog

## [Update] - 2024-12-23

- support [email protected].

## [Update] - 2024-07-20

- support sendMemoForm.
Expand Down
35 changes: 26 additions & 9 deletions extensions/memos/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -125,15 +125,32 @@ export const sendMemo = (data: PostMemoParams) => {
});
};

export const getTags = () => {
const url = getRequestUrl(`/api/v1/memos/-/tags`);
export const getRecentTags = async (): Promise<string[]> => {
const me = await getFetch<MeResponse>({
url: getRequestUrl(`/api/v1/auth/status`),
method: "POST",
});

return getUseFetch<TagResponse>(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) => {
Expand Down Expand Up @@ -246,7 +263,7 @@ export const deleteMemo = (memoId: string) => {
export const getResourceBin = (resourceName: string, resourceFilename: string) => {
const url = getRequestUrl(`/file/${resourceName}/${resourceFilename}`);

return getFetch<BinaryData>({
return getFetch<Blob>({
url,
method: "GET",
responseType: "blob",
Expand Down
27 changes: 18 additions & 9 deletions extensions/memos/src/sendMemoForm.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -12,11 +12,22 @@ interface FormData {
}

export default function SendMemoFormCommand(): JSX.Element {
const { isLoading, data: existTags } = getTags();
const [nameError, setNameError] = useState<string>();
const [files, setFiles] = useState<string[]>([]);
const [createdMarkdown, setCreatedMarkdown] = useState<string>();
const [createdUrl, setCreatedUrl] = useState<string>();
const [isLoading, setIsLoading] = useState(true);
const [recentTags, setRecentTags] = useState<string[]>([]);

useEffect(() => {
getRecentTags()
.then((tags) => {
setRecentTags(tags);
})
.finally(() => {
setIsLoading(false);
});
}, []);

function dropNameErrorIfNeeded() {
if (nameError && nameError.length > 0) {
Expand Down Expand Up @@ -152,12 +163,10 @@ export default function SendMemoFormCommand(): JSX.Element {

<Form.FilePicker id="files" value={files} onChange={setFiles} />

<Form.TagPicker id="tags" title="Exist Tags">
{Object.keys(existTags?.tagAmounts)
?.filter((tag) => !!existTags?.tagAmounts[tag])
?.map((tag) => {
return <Form.TagPicker.Item key={tag} value={tag} title={tag} />;
})}
<Form.TagPicker id="tags" title="Recent Tags">
{recentTags.map((tag) => {
return <Form.TagPicker.Item key={tag} value={tag} title={tag} />;
})}
</Form.TagPicker>

<Form.Dropdown id="visibility" title="Limit" defaultValue="PRIVATE">
Expand Down
13 changes: 7 additions & 6 deletions extensions/memos/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading