|
1 | 1 | import { queryClient } from '~/providers/root/react-query-provider'
|
| 2 | +import React from 'react' |
2 | 3 | import { produce } from 'immer'
|
3 | 4 | import type {
|
4 | 5 | NoteModel,
|
5 | 6 | PaginateResult,
|
6 | 7 | PostModel,
|
| 8 | + RecentlyModel, |
7 | 9 | SayModel,
|
8 | 10 | } from '@mx-space/api-client'
|
9 | 11 | import type { InfiniteData } from '@tanstack/react-query'
|
10 | 12 | import type { AppRouterInstance } from 'next/dist/shared/lib/app-router-context'
|
11 | 13 |
|
12 | 14 | import { sayQueryKey } from '~/app/says/query'
|
| 15 | +import { QUERY_KEY as ThinkingQueryKey } from '~/app/thinking/constants' |
13 | 16 | import { setOnlineCount } from '~/atoms'
|
14 | 17 | import { setActivityMediaInfo, setActivityProcessName } from '~/atoms/activity'
|
| 18 | +import { |
| 19 | + FaSolidFeatherAlt, |
| 20 | + IcTwotoneSignpost, |
| 21 | + MdiLightbulbOn20, |
| 22 | +} from '~/components/icons/menu-collection' |
15 | 23 | import { isDev } from '~/lib/env'
|
16 | 24 | import { routeBuilder, Routes } from '~/lib/route-builder'
|
17 | 25 | import { toast } from '~/lib/toast'
|
@@ -95,7 +103,53 @@ export const eventHandler = (
|
95 | 103 | break
|
96 | 104 | }
|
97 | 105 |
|
98 |
| - // TODO create event |
| 106 | + case EventTypes.NOTE_CREATE: { |
| 107 | + const { title, nid } = data as NoteModel |
| 108 | + |
| 109 | + toast.success('有新的内容发布了:' + `「${title}」`, { |
| 110 | + onClick: () => { |
| 111 | + window.peek(`/notes/${nid}`) |
| 112 | + }, |
| 113 | + iconElement: React.createElement(FaSolidFeatherAlt), |
| 114 | + autoClose: false, |
| 115 | + }) |
| 116 | + |
| 117 | + break |
| 118 | + } |
| 119 | + |
| 120 | + case EventTypes.POST_CREATE: { |
| 121 | + const { title, category, slug } = data as PostModel |
| 122 | + toast.success('有新的内容发布了:' + `「${title}」`, { |
| 123 | + onClick: () => { |
| 124 | + window.peek(`/posts/${category.slug}/${slug}`) |
| 125 | + }, |
| 126 | + iconElement: React.createElement(IcTwotoneSignpost), |
| 127 | + }) |
| 128 | + |
| 129 | + break |
| 130 | + } |
| 131 | + |
| 132 | + case EventTypes.RECENTLY_CREATE: { |
| 133 | + if (location.pathname === routeBuilder(Routes.Thinking, {})) { |
| 134 | + queryClient.setQueryData<InfiniteData<RecentlyModel[]>>( |
| 135 | + ThinkingQueryKey, |
| 136 | + (prev) => { |
| 137 | + return produce(prev, (draft) => { |
| 138 | + draft?.pages[0].unshift(data as RecentlyModel) |
| 139 | + }) |
| 140 | + }, |
| 141 | + ) |
| 142 | + } else { |
| 143 | + toast.success(`写下一点小思考:\n${(data as RecentlyModel).content}`, { |
| 144 | + autoClose: 10000, |
| 145 | + iconElement: React.createElement(MdiLightbulbOn20), |
| 146 | + onClick: () => { |
| 147 | + router.push(routeBuilder(Routes.Thinking, {})) |
| 148 | + }, |
| 149 | + }) |
| 150 | + } |
| 151 | + break |
| 152 | + } |
99 | 153 |
|
100 | 154 | case EventTypes.SAY_CREATE: {
|
101 | 155 | if (location.pathname === routeBuilder(Routes.Says, {})) {
|
|
0 commit comments