compute fetchedAt in client

This commit is contained in:
hmacr committed 2025-04-10 18:07:57 +05:30
1 parent c327468e67
commit a02ebaabd2
7 files changed
+19 -50

No files matched your search

@@ -13,10 +13,7 @@ import {
Description,
} from "./Components";
type Props = Omit<
UnfurlResponse[UnfurlResourceType.Document],
"type" | "fetchedAt"
>;
type Props = Omit<UnfurlResponse[UnfurlResourceType.Document], "type">;
const HoverPreviewDocument = React.forwardRef(function _HoverPreviewDocument(
{ url, id, title, summary, lastActivityByViewer }: Props,
@@ -16,10 +16,7 @@ import {
Info,
} from "./Components";
type Props = Omit<
UnfurlResponse[UnfurlResourceType.Issue],
"type" | "fetchedAt"
>;
type Props = Omit<UnfurlResponse[UnfurlResourceType.Issue], "type">;
const HoverPreviewIssue = React.forwardRef(function _HoverPreviewIssue(
{ url, id, title, description, author, labels, state, createdAt }: Props,
@@ -4,10 +4,7 @@ import { Avatar, AvatarSize } from "~/components/Avatar";
import Flex from "~/components/Flex";
import { Preview, Title, Info, Card, CardContent } from "./Components";
type Props = Omit<
UnfurlResponse[UnfurlResourceType.Mention],
"type" | "fetchedAt"
>;
type Props = Omit<UnfurlResponse[UnfurlResourceType.Mention], "type">;
const HoverPreviewMention = React.forwardRef(function _HoverPreviewMention(
{ avatarUrl, name, lastActive, color, email }: Props,
@@ -15,7 +15,7 @@ import {
Info,
} from "./Components";
type Props = Omit<UnfurlResponse[UnfurlResourceType.PR], "type" | "fetchedAt">;
type Props = Omit<UnfurlResponse[UnfurlResourceType.PR], "type">;
const HoverPreviewPullRequest = React.forwardRef(
function _HoverPreviewPullRequest(
+1 -1
View File
@@ -70,7 +70,7 @@ class UnfurlsStore extends Store<Unfurl<any>> {
return this.add({
id: url,
type: data.type,
fetchedAt: data.fetchedAt,
fetchedAt: new Date().toISOString(),
data,
} as Unfurl<UnfurlType>);
} catch (err) {
+14 -26
View File
@@ -10,35 +10,23 @@ async function presentUnfurl(
data: Record<string, any>,
options?: { includeEmail: boolean }
) {
let unfurl: Omit<UnfurlResponse[keyof UnfurlResponse], "fetchedAt">;
switch (data.type) {
case UnfurlResourceType.Mention: {
unfurl = await presentMention(data, options);
break;
}
case UnfurlResourceType.Document: {
unfurl = presentDocument(data);
break;
}
case UnfurlResourceType.PR: {
unfurl = presentPR(data);
break;
}
case UnfurlResourceType.Issue: {
unfurl = presentIssue(data);
break;
}
case UnfurlResourceType.Mention:
return presentMention(data, options);
case UnfurlResourceType.Document:
return presentDocument(data);
case UnfurlResourceType.PR:
return presentPR(data);
case UnfurlResourceType.Issue:
return presentIssue(data);
default:
unfurl = presentOEmbed(data);
return presentOEmbed(data);
}
return { ...unfurl, fetchedAt: new Date() };
}
const presentOEmbed = (
data: Record<string, any>
): Omit<UnfurlResponse[UnfurlResourceType.OEmbed], "fetchedAt"> => ({
): UnfurlResponse[UnfurlResourceType.OEmbed] => ({
type: UnfurlResourceType.OEmbed,
url: data.url,
title: data.title,
@@ -49,7 +37,7 @@ const presentOEmbed = (
const presentMention = async (
data: Record<string, any>,
options?: { includeEmail: boolean }
): Promise<Omit<UnfurlResponse[UnfurlResourceType.Mention], "fetchedAt">> => {
): Promise<UnfurlResponse[UnfurlResourceType.Mention]> => {
const user: User = data.user;
const document: Document = data.document;
@@ -68,7 +56,7 @@ const presentMention = async (
const presentDocument = (
data: Record<string, any>
): Omit<UnfurlResponse[UnfurlResourceType.Document], "fetchedAt"> => {
): UnfurlResponse[UnfurlResourceType.Document] => {
const document: Document = data.document;
const viewer: User = data.viewer;
return {
@@ -83,7 +71,7 @@ const presentDocument = (
const presentPR = (
data: Record<string, any>
): Omit<UnfurlResponse[UnfurlResourceType.PR], "fetchedAt"> => ({
): UnfurlResponse[UnfurlResourceType.PR] => ({
url: data.html_url,
type: UnfurlResourceType.PR,
id: `#${data.number}`,
@@ -102,7 +90,7 @@ const presentPR = (
const presentIssue = (
data: Record<string, any>
): Omit<UnfurlResponse[UnfurlResourceType.Issue], "fetchedAt"> => ({
): UnfurlResponse[UnfurlResourceType.Issue] => ({
url: data.html_url,
type: UnfurlResourceType.Issue,
id: `#${data.number}`,
-10
View File
@@ -377,8 +377,6 @@ export type UnfurlResponse = {
description: string;
/** A URL to a thumbnail image representing the resource */
thumbnailUrl: string;
/** Unfurl fetched time */
fetchedAt: string;
};
[UnfurlResourceType.Mention]: {
/** The resource type */
@@ -393,8 +391,6 @@ export type UnfurlResponse = {
color: string;
/** Mentiond user's recent activity */
lastActive: string;
/** Unfurl fetched time */
fetchedAt: string;
};
[UnfurlResourceType.Document]: {
/** The resource type */
@@ -409,8 +405,6 @@ export type UnfurlResponse = {
summary: string;
/** Viewer's last activity on this document */
lastActivityByViewer: string;
/** Unfurl fetched time */
fetchedAt: string;
};
[UnfurlResourceType.Issue]: {
/** The resource type */
@@ -431,8 +425,6 @@ export type UnfurlResponse = {
state: { name: string; color: string };
/** Issue's creation time */
createdAt: string;
/** Unfurl fetched time */
fetchedAt: string;
};
[UnfurlResourceType.PR]: {
/** The resource type */
@@ -451,8 +443,6 @@ export type UnfurlResponse = {
state: { name: string; color: string };
/** Pull Request creation time */
createdAt: string;
/** Unfurl fetched time */
fetchedAt: string;
};
};