Compare commits
2 commits
main
...
feature/re
Author | SHA1 | Date | |
---|---|---|---|
e194b32541 | |||
ef0f6af97f |
2 changed files with 57 additions and 7 deletions
|
@ -7,6 +7,7 @@ import * as os from '@/os';
|
|||
import copyToClipboard from '@/scripts/copy-to-clipboard';
|
||||
import { url } from '@/config';
|
||||
import { noteActions } from '@/store';
|
||||
import { del } from '@/scripts/request';
|
||||
|
||||
export function getNoteMenu(props: {
|
||||
note: foundkey.entities.Note;
|
||||
|
@ -25,20 +26,18 @@ export function getNoteMenu(props: {
|
|||
|
||||
const appearNote = isRenote ? props.note.renote as foundkey.entities.Note : props.note;
|
||||
|
||||
function del(): void {
|
||||
function deleteNote(): void {
|
||||
os.confirm({
|
||||
type: 'warning',
|
||||
text: i18n.ts.noteDeleteConfirm,
|
||||
}).then(({ canceled }) => {
|
||||
if (canceled) return;
|
||||
|
||||
os.api('notes/delete', {
|
||||
noteId: appearNote.id,
|
||||
});
|
||||
del(`/api/v2/notes/${appearNote.id}`);
|
||||
});
|
||||
}
|
||||
|
||||
function delEdit(): void {
|
||||
function deleteEditNote(): void {
|
||||
os.confirm({
|
||||
type: 'warning',
|
||||
text: i18n.ts.deleteAndEditConfirm,
|
||||
|
@ -310,13 +309,13 @@ export function getNoteMenu(props: {
|
|||
appearNote.userId === $i.id ? {
|
||||
icon: 'fas fa-edit',
|
||||
text: i18n.ts.deleteAndEdit,
|
||||
action: delEdit,
|
||||
action: deleteEditNote,
|
||||
} : undefined,
|
||||
{
|
||||
icon: 'fas fa-trash-alt',
|
||||
text: i18n.ts.delete,
|
||||
danger: true,
|
||||
action: del,
|
||||
action: deleteNote,
|
||||
}]
|
||||
: []
|
||||
)]
|
||||
|
|
51
packages/client/src/scripts/request.ts
Normal file
51
packages/client/src/scripts/request.ts
Normal file
|
@ -0,0 +1,51 @@
|
|||
import { $i } from '@/account';
|
||||
|
||||
export const request = async (url: string, body?: Record<string, any>, options?: Record<string, any>, token?: string) => {
|
||||
let requestOptions = {};
|
||||
|
||||
const authorizationToken = token ?? $i?.token ?? undefined;
|
||||
const authorization = authorizationToken ? `Bearer ${authorizationToken}` : undefined;
|
||||
|
||||
requestOptions = {
|
||||
...{
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
...(authorization ? { authorization } : {}),
|
||||
},
|
||||
},
|
||||
...options,
|
||||
};
|
||||
|
||||
const response = await fetch(url, {
|
||||
...requestOptions,
|
||||
body: body ? JSON.stringify(body) : undefined,
|
||||
});
|
||||
|
||||
const responseBody = response.status === 204 ? null : await response.json();
|
||||
|
||||
if (response.status === 200) {
|
||||
return responseBody;
|
||||
}
|
||||
else if (response.status === 204) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
throw new Error(responseBody.error);
|
||||
}
|
||||
};
|
||||
|
||||
export const get = async (url: string, options?: Record<string, any>, token?: string) => {
|
||||
return request(url, undefined, { method: 'GET' }, token);
|
||||
};
|
||||
|
||||
export const post = async (url: string, body: Record<string, any>, options?: Record<string, any>, token?: string) => {
|
||||
return request(url, body, { method: 'POST' }, token);
|
||||
};
|
||||
|
||||
export const put = async (url: string, body: Record<string, any>, options?: Record<string, any>, token?: string) => {
|
||||
return request(url, body, { method: 'PUT' }, token);
|
||||
};
|
||||
|
||||
export const del = async (url: string, options?: Record<string, any>, token?: string) => {
|
||||
return request(url, undefined, { method: 'DELETE' }, token);
|
||||
};
|
Loading…
Reference in a new issue