feat: inbox set read and unread
This commit is contained in:
parent
6da197c76b
commit
6da8bce04c
|
|
@ -106,12 +106,22 @@ export const useUnCollect = (entry: Nullable<CombinedEntryModel>) => {
|
|||
export const useRead = () =>
|
||||
useMutation({
|
||||
mutationFn: async (entry: Nullable<CombinedEntryModel>) =>
|
||||
entry && entryActions.markRead(entry.feeds.id, entry.entries.id, true),
|
||||
entry &&
|
||||
entryActions.markRead({
|
||||
feedId: entry.feeds.id,
|
||||
entryId: entry.entries.id,
|
||||
read: true,
|
||||
}),
|
||||
})
|
||||
export const useUnread = () =>
|
||||
useMutation({
|
||||
mutationFn: async (entry: Nullable<CombinedEntryModel>) =>
|
||||
entry && entryActions.markRead(entry.feeds.id, entry.entries.id, false),
|
||||
entry &&
|
||||
entryActions.markRead({
|
||||
feedId: entry.feeds.id,
|
||||
entryId: entry.entries.id,
|
||||
read: false,
|
||||
}),
|
||||
})
|
||||
|
||||
export const useEntryActions = ({
|
||||
|
|
|
|||
|
|
@ -235,7 +235,7 @@ export function batchMarkRead(ids: string[]) {
|
|||
|
||||
if (batchLikeIds.length > 0) {
|
||||
for (const [feedId, id] of batchLikeIds) {
|
||||
entryActions.markRead(feedId, id, true)
|
||||
entryActions.markRead({ feedId, entryId: id, read: true })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ function EntryColumnImpl() {
|
|||
const feedId = activeEntry?.feedId
|
||||
if (!feedId) return
|
||||
|
||||
entryActions.markRead(feedId, activeEntryId, true)
|
||||
entryActions.markRead({ feedId, entryId: activeEntryId, read: true })
|
||||
}, [activeEntry?.feedId, activeEntryId, isCollection, isPendingEntry])
|
||||
|
||||
const isInteracted = useRef(false)
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ export const EntryItemWrapper: FC<
|
|||
if (!document.hasFocus()) return
|
||||
if (asRead) return
|
||||
|
||||
entryActions.markRead(entry.feedId, entry.entries.id, true)
|
||||
entryActions.markRead({ feedId: entry.feedId, entryId: entry.entries.id, read: true })
|
||||
},
|
||||
233,
|
||||
{
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ export const EntryListHeader: FC<{
|
|||
|
||||
const unreadOnly = useGeneralSettingKey("unreadOnly")
|
||||
|
||||
const { feedId, entryId, view } = routerParams
|
||||
const { feedId, entryId, view, listId } = routerParams
|
||||
|
||||
const headerTitle = useFeedHeaderTitle()
|
||||
const os = getOS()
|
||||
|
|
@ -58,13 +58,13 @@ export const EntryListHeader: FC<{
|
|||
</div>
|
||||
</div>
|
||||
)
|
||||
const { mutateAsync: refreshFeed, isPending } = useRefreshFeedMutation(routerParams.feedId)
|
||||
const { mutateAsync: refreshFeed, isPending } = useRefreshFeedMutation(feedId)
|
||||
|
||||
const user = useWhoami()
|
||||
const isOnline = useIsOnline()
|
||||
|
||||
const feed = useFeedById(routerParams.feedId)
|
||||
const isList = feed?.type === "list"
|
||||
const feed = useFeedById(feedId)
|
||||
const isList = !!listId
|
||||
|
||||
const titleStyleBasedView = ["pl-12", "pl-7", "pl-7", "pl-7", "px-5", "pl-12"]
|
||||
|
||||
|
|
|
|||
|
|
@ -33,8 +33,13 @@ export const getFilteredFeedIds = (feedIds: string[], filter?: EntryFilter) => {
|
|||
}
|
||||
|
||||
const unread = create({
|
||||
fetcher: async (ids: [FeedId, EntryId][]) => {
|
||||
await apiClient.reads.$post({ json: { entryIds: ids.map((i) => i[1]) } })
|
||||
fetcher: async (ids: ([FeedId, EntryId, boolean] | [FeedId, EntryId])[]) => {
|
||||
await apiClient.reads.$post({
|
||||
json: {
|
||||
entryIds: ids.map((i) => i[1]),
|
||||
isInbox: ids[0][2],
|
||||
},
|
||||
})
|
||||
|
||||
return []
|
||||
},
|
||||
|
|
|
|||
|
|
@ -345,10 +345,11 @@ class EntryActions {
|
|||
}))
|
||||
}
|
||||
|
||||
async markRead(feedId: string, entryId: string, read: boolean) {
|
||||
const currentIsRead = get().flatMapEntries[entryId]?.read
|
||||
async markRead({ feedId, entryId, read }: { feedId: string; entryId: string; read: boolean }) {
|
||||
const entry = get().flatMapEntries[entryId]
|
||||
const isInbox = entry?.entries && "inboxHandle" in entry.entries
|
||||
|
||||
if (read && currentIsRead) {
|
||||
if (read && entry?.read) {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -362,11 +363,12 @@ class EntryActions {
|
|||
// Send api request
|
||||
async () => {
|
||||
if (read) {
|
||||
await internal_batchMarkRead([feedId, entryId])
|
||||
await internal_batchMarkRead([feedId, entryId, isInbox])
|
||||
} else {
|
||||
await apiClient.reads.$delete({
|
||||
json: {
|
||||
entryId,
|
||||
isInbox,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,6 @@
|
|||
import type { FeedViewType } from "~/lib/enum"
|
||||
import type { InboxModel } from "~/models"
|
||||
|
||||
import { useInboxStore } from "./store"
|
||||
|
||||
export const useInboxById = (inboxId: Nullable<string>): InboxModel | null =>
|
||||
useInboxStore((state) => (inboxId ? state.inboxes[inboxId] : null))
|
||||
|
||||
export const useInboxByView = (view: FeedViewType) => {
|
||||
return useInboxStore((state) => (view === 0 ? Object.values(state.inboxes) : []))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2213,6 +2213,22 @@ declare const inboxesEntries: drizzle_orm_pg_core.PgTableWithColumns<{
|
|||
baseColumn: never;
|
||||
generated: undefined;
|
||||
}, {}, {}>;
|
||||
read: drizzle_orm_pg_core.PgColumn<{
|
||||
name: "read";
|
||||
tableName: "inboxes_entries";
|
||||
dataType: "boolean";
|
||||
columnType: "PgBoolean";
|
||||
data: boolean;
|
||||
driverParam: boolean;
|
||||
notNull: false;
|
||||
hasDefault: false;
|
||||
isPrimaryKey: false;
|
||||
isAutoincrement: false;
|
||||
hasRuntimeDefault: false;
|
||||
enumValues: undefined;
|
||||
baseColumn: never;
|
||||
generated: undefined;
|
||||
}, {}, {}>;
|
||||
};
|
||||
dialect: "pg";
|
||||
}>;
|
||||
|
|
@ -2245,6 +2261,7 @@ declare const inboxesEntriesOpenAPISchema: z.ZodObject<z.objectUtil.extendShape<
|
|||
[key: string]: string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null;
|
||||
} | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | (string | number | boolean | any | any | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null)[] | null>>;
|
||||
inboxHandle: z.ZodString;
|
||||
read: z.ZodNullable<z.ZodBoolean>;
|
||||
}, "media" | "attachments" | "extra">, {
|
||||
attachments: z.ZodNullable<z.ZodOptional<z.ZodArray<z.ZodObject<{
|
||||
url: z.ZodString;
|
||||
|
|
@ -2327,6 +2344,7 @@ declare const inboxesEntriesOpenAPISchema: z.ZodObject<z.objectUtil.extendShape<
|
|||
authorAvatar: string | null;
|
||||
insertedAt: string;
|
||||
publishedAt: string;
|
||||
read: boolean | null;
|
||||
inboxHandle: string;
|
||||
media?: {
|
||||
type: "photo" | "video";
|
||||
|
|
@ -2363,6 +2381,7 @@ declare const inboxesEntriesOpenAPISchema: z.ZodObject<z.objectUtil.extendShape<
|
|||
authorAvatar: string | null;
|
||||
insertedAt: string;
|
||||
publishedAt: string;
|
||||
read: boolean | null;
|
||||
inboxHandle: string;
|
||||
media?: {
|
||||
type: "photo" | "video";
|
||||
|
|
@ -2415,6 +2434,7 @@ declare const inboxesEntriesInsertOpenAPISchema: z.ZodObject<z.objectUtil.extend
|
|||
authorAvatar: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
||||
insertedAt: z.ZodString;
|
||||
publishedAt: z.ZodString;
|
||||
read: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
||||
inboxHandle: z.ZodString;
|
||||
}, "id" | "media" | "attachments" | "extra" | "insertedAt" | "publishedAt" | "inboxHandle">, {
|
||||
attachments: z.ZodNullable<z.ZodOptional<z.ZodArray<z.ZodObject<{
|
||||
|
|
@ -2519,6 +2539,7 @@ declare const inboxesEntriesInsertOpenAPISchema: z.ZodObject<z.objectUtil.extend
|
|||
} | null | undefined;
|
||||
authorUrl?: string | null | undefined;
|
||||
authorAvatar?: string | null | undefined;
|
||||
read?: boolean | null | undefined;
|
||||
}, {
|
||||
guid: string;
|
||||
publishedAt: string;
|
||||
|
|
@ -2552,6 +2573,7 @@ declare const inboxesEntriesInsertOpenAPISchema: z.ZodObject<z.objectUtil.extend
|
|||
} | null | undefined;
|
||||
authorUrl?: string | null | undefined;
|
||||
authorAvatar?: string | null | undefined;
|
||||
read?: boolean | null | undefined;
|
||||
}>;
|
||||
declare const inboxesEntriesRelations: drizzle_orm.Relations<"inboxes_entries", {
|
||||
inboxes: drizzle_orm.One<"inboxes", true>;
|
||||
|
|
@ -4219,6 +4241,7 @@ declare const _routes: hono_hono_base.HonoBase<Env, {
|
|||
} | null | undefined;
|
||||
authorUrl?: string | null | undefined;
|
||||
authorAvatar?: string | null | undefined;
|
||||
read?: boolean | null | undefined;
|
||||
};
|
||||
};
|
||||
output: {
|
||||
|
|
@ -5018,6 +5041,7 @@ declare const _routes: hono_hono_base.HonoBase<Env, {
|
|||
input: {
|
||||
json: {
|
||||
entryIds: string[];
|
||||
isInbox?: boolean | undefined;
|
||||
};
|
||||
};
|
||||
output: {
|
||||
|
|
@ -5030,6 +5054,7 @@ declare const _routes: hono_hono_base.HonoBase<Env, {
|
|||
input: {
|
||||
json: {
|
||||
entryId: string;
|
||||
isInbox?: boolean | undefined;
|
||||
};
|
||||
};
|
||||
output: {
|
||||
|
|
@ -5365,6 +5390,7 @@ declare const _routes: hono_hono_base.HonoBase<Env, {
|
|||
authorAvatar: string | null;
|
||||
insertedAt: string;
|
||||
publishedAt: string;
|
||||
read: boolean | null;
|
||||
inboxHandle: string;
|
||||
media?: {
|
||||
type: "photo" | "video";
|
||||
|
|
@ -5448,6 +5474,7 @@ declare const _routes: hono_hono_base.HonoBase<Env, {
|
|||
authorAvatar: string | null;
|
||||
insertedAt: string;
|
||||
publishedAt: string;
|
||||
read: boolean | null;
|
||||
inboxHandle: string;
|
||||
media?: {
|
||||
type: "photo" | "video";
|
||||
|
|
|
|||
Loading…
Reference in New Issue