Skip to content

Commit ab37606

Browse files
refactor(types): more convenient name of types (#16)
1 parent 14e8446 commit ab37606

File tree

9 files changed

+30
-28
lines changed

9 files changed

+30
-28
lines changed

src/main/services/ipc/context-menu.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import { createMenu } from '../../components/menu'
22
import type { MenuItemConstructorOptions } from 'electron'
33
import { BrowserWindow, MenuItem, dialog, ipcMain } from 'electron'
44
import type {
5-
ContextMenuPayload,
5+
ContextMenuRequest,
66
ContextMenuResponse
77
} from '@shared/types/main'
88
import { languages } from '../../../renderer/components/editor/languages'
99

1010
export const subscribeToContextMenu = () => {
11-
ipcMain.handle<ContextMenuPayload, ContextMenuResponse>(
11+
ipcMain.handle<ContextMenuRequest, ContextMenuResponse>(
1212
'context-menu:snippet-fragment',
1313
async (event, payload) => {
1414
const { name, type } = payload
@@ -51,7 +51,7 @@ export const subscribeToContextMenu = () => {
5151
}
5252
)
5353

54-
ipcMain.handle<ContextMenuPayload, ContextMenuResponse>(
54+
ipcMain.handle<ContextMenuRequest, ContextMenuResponse>(
5555
'context-menu:snippet',
5656
async (event, payload) => {
5757
const { name, type, selectedCount } = payload
@@ -180,7 +180,7 @@ export const subscribeToContextMenu = () => {
180180
}
181181
)
182182

183-
ipcMain.handle<ContextMenuPayload, ContextMenuResponse>(
183+
ipcMain.handle<ContextMenuRequest, ContextMenuResponse>(
184184
'context-menu:library',
185185
async (event, payload) => {
186186
const { name, type, data } = payload

src/main/services/ipc/notifications.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import type { NotificationPayload } from '@shared/types/main'
1+
import type { NotificationRequest } from '@shared/types/main'
22
import { ipcMain, Notification } from 'electron'
33

44
export const subscribeToNotification = () => {
55
if (!Notification.isSupported()) return
66

7-
ipcMain.handle<NotificationPayload>('main:notification', (event, payload) => {
7+
ipcMain.handle<NotificationRequest>('main:notification', (event, payload) => {
88
return new Promise(resolve => {
99
const { body } = payload
1010
const notification = new Notification({

src/renderer/components/preferences/Storage.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const folderStore = useFolderStore()
4545
const storagePath = ref(store.preferences.get('storagePath'))
4646
4747
const onClickMove = async () => {
48-
const path = await ipc.invoke<string>('main:open-dialog', {})
48+
const path = await ipc.invoke<any, string>('main:open-dialog', {})
4949
5050
if (!path) return
5151
@@ -64,7 +64,7 @@ const onClickMove = async () => {
6464
}
6565
6666
const onClickOpen = async () => {
67-
const path = await ipc.invoke<string>('main:open-dialog', {})
67+
const path = await ipc.invoke<any, string>('main:open-dialog', {})
6868
const isExist = db.isExist(path)
6969
7070
if (isExist) {
@@ -81,7 +81,7 @@ const onClickOpen = async () => {
8181
}
8282
8383
const onClickMigrate = async () => {
84-
const state = await ipc.invoke<boolean, MessageBoxRequest>(
84+
const state = await ipc.invoke<MessageBoxRequest, boolean>(
8585
'main:open-message-box',
8686
{
8787
message: 'Are you sure you want to migrate from v1',
@@ -94,7 +94,7 @@ const onClickMigrate = async () => {
9494
if (!state) return
9595
9696
try {
97-
const path = await ipc.invoke<string>('main:open-dialog', {})
97+
const path = await ipc.invoke<any, string>('main:open-dialog', {})
9898
await db.migrate(path)
9999
ipc.invoke('main:restart-api', {})
100100
ipc.invoke('main:notification', {

src/renderer/components/sidebar/SidebarListItem.vue

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import AngleRight from '~icons/unicons/angle-right'
3232
import { onClickOutside } from '@vueuse/core'
3333
import { ipc, track } from '@/electron'
3434
import type {
35-
ContextMenuPayload,
35+
ContextMenuRequest,
3636
ContextMenuResponse,
3737
ContextMenuType
3838
} from '@shared/types/main'
@@ -70,8 +70,8 @@ const itemRef = ref()
7070
const onClickContextMenu = async () => {
7171
if (props.isFolder) {
7272
const { action, type, data } = await ipc.invoke<
73-
ContextMenuResponse,
74-
ContextMenuPayload
73+
ContextMenuRequest,
74+
ContextMenuResponse
7575
>('context-menu:library', {
7676
name: props.model?.name,
7777
type: 'folder',
@@ -96,10 +96,10 @@ const onClickContextMenu = async () => {
9696
9797
if (props.alias) {
9898
const { action, type, data } = await ipc.invoke<
99-
ContextMenuResponse,
100-
ContextMenuPayload
99+
ContextMenuRequest,
100+
ContextMenuResponse
101101
>('context-menu:library', {
102-
name: props.name,
102+
name2: props.name,
103103
type: 'trash',
104104
data: {}
105105
})
@@ -117,8 +117,8 @@ const onClickContextMenu = async () => {
117117
118118
if (props.isTag) {
119119
const { action, type, data } = await ipc.invoke<
120-
ContextMenuResponse,
121-
ContextMenuPayload
120+
ContextMenuRequest,
121+
ContextMenuResponse
122122
>('context-menu:library', {
123123
name: props.name,
124124
type: 'tag',

src/renderer/components/snippets/SnippetHeader.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import { ipc, track } from '@/electron'
3838
import { useSnippetStore } from '@/store/snippets'
3939
import { useClipboard, useDebounceFn } from '@vueuse/core'
4040
import { computed, ref } from 'vue'
41-
import type { NotificationPayload } from '@shared/types/main'
41+
import type { NotificationRequest } from '@shared/types/main'
4242
import { useAppStore } from '@/store/app'
4343
4444
const snippetStore = useSnippetStore()
@@ -66,7 +66,7 @@ const onAddNewFragment = () => {
6666
const onCopySnippet = () => {
6767
const { copy } = useClipboard({ source: snippetStore.currentContent })
6868
copy()
69-
ipc.invoke<any, NotificationPayload>('main:notification', {
69+
ipc.invoke<any, NotificationRequest>('main:notification', {
7070
body: 'Snippet copied'
7171
})
7272
track('snippets/copy')

src/renderer/components/snippets/SnippetListItem.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import { ipc, track } from '@/electron'
3636
import { useFolderStore } from '@/store/folders'
3737
import { useSnippetStore } from '@/store/snippets'
3838
import type {
39-
ContextMenuPayload,
39+
ContextMenuRequest,
4040
ContextMenuResponse
4141
} from '@shared/types/main'
4242
import { onClickOutside } from '@vueuse/core'
@@ -116,8 +116,8 @@ const onClickContextMenu = async () => {
116116
})
117117
118118
const { action, data, type } = await ipc.invoke<
119-
ContextMenuResponse,
120-
ContextMenuPayload
119+
ContextMenuRequest,
120+
ContextMenuResponse
121121
>('context-menu:snippet', {
122122
name: props.name,
123123
type: folderStore.selectedAlias ?? 'folder',

src/renderer/components/snippets/SnippetsFragmentsInput.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { useSnippetStore } from '@/store/snippets'
2727
import { onClickOutside, useDebounceFn } from '@vueuse/core'
2828
import { ipc, track } from '@/electron'
2929
import type {
30-
ContextMenuPayload,
30+
ContextMenuRequest,
3131
ContextMenuResponse
3232
} from '@shared/types/main'
3333
@@ -59,7 +59,7 @@ onClickOutside(inputRef, async () => {
5959
})
6060
6161
const onClickContext = async () => {
62-
const { action } = await ipc.invoke<ContextMenuResponse, ContextMenuPayload>(
62+
const { action } = await ipc.invoke<ContextMenuRequest, ContextMenuResponse>(
6363
'context-menu:snippet-fragment',
6464
{
6565
name: props.name,

src/renderer/store/snippets.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ export const useSnippetStore = defineStore('snippets', {
7676
if (folder) i.folder = folder
7777
return i
7878
})
79+
80+
this.all.sort((a, b) => (a.createdAt > b.createdAt ? -1 : 1))
7981
},
8082
async getSnippetsByFolderIds (ids: string[]) {
8183
const snippets: SnippetWithFolder[] = []

src/shared/types/main/index.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export type MainMenuChannel = CombineWith<MainMenuAction, 'main-menu'>
4646
export type MainChannel = CombineWith<MainAction, 'main'>
4747

4848
export type Channel = ContextMenuChannel | MainMenuChannel | MainChannel
49-
export interface ContextMenuPayload {
49+
export interface ContextMenuRequest {
5050
name?: string
5151
type: ContextMenuType
5252
data?: any
@@ -59,7 +59,7 @@ export interface ContextMenuResponse {
5959
data: any
6060
}
6161

62-
export interface NotificationPayload {
62+
export interface NotificationRequest {
6363
body: string
6464
}
6565

@@ -89,7 +89,7 @@ interface StoreProperties<T> {
8989

9090
export interface ElectronBridge {
9191
ipc: {
92-
invoke<T, U = any>(channel: Channel, payload: U): Promise<T>
92+
invoke<T, U = any>(channel: Channel, payload: T): Promise<U>
9393
on(channel: Channel, cb: EventCallback): void
9494
once(channel: Channel, cb: EventCallback): void
9595
}

0 commit comments

Comments
 (0)