-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Community optional default payload fetching (#491)
* WIP; * Added dynamic fetching of the payloads; * Extend header limits for the content header; * Added clear limits; Included on optimistic updates and ws updates;
1 parent
ca214b4
commit 3e5eeca
Showing
16 changed files
with
471 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
packages/common/common-app/src/helpers/richTextHelper.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import { expect, test } from 'vitest'; | ||
const longRichText: RichText = [ | ||
{ | ||
type: 'p', | ||
children: [ | ||
{ | ||
text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam aliquet arcu augue, a commodo enim volutpat ut.', | ||
}, | ||
], | ||
id: '1vjzm', | ||
}, | ||
{ | ||
type: 'p', | ||
children: [ | ||
{ | ||
text: 'In porta magna in massa tincidunt, nec accumsan sem posuere. Donec ultrices aliquam convallis. Etiam placerat ipsum sit amet laoreet ultrices. ', | ||
}, | ||
], | ||
id: 'tf68w', | ||
}, | ||
{ | ||
type: 'p', | ||
children: [ | ||
{ | ||
text: 'Etiam et leo turpis. Nulla convallis lectus enim, ac rutrum diam condimentum malesuada. ', | ||
}, | ||
], | ||
id: 'op2ev', | ||
}, | ||
{ | ||
type: 'p', | ||
children: [ | ||
{ | ||
text: 'Curabitur nec consequat velit. Curabitur ipsum justo, fermentum sed faucibus et, mattis ac ipsum.', | ||
}, | ||
], | ||
id: 'lk9dv', | ||
}, | ||
{ | ||
type: 'p', | ||
children: [ | ||
{ | ||
text: 'Pellentesque ultrices sem nec quam feugiat pharetra. Curabitur purus nisi, molestie sed iaculis a, vehicula ut tortor.', | ||
}, | ||
], | ||
id: 'q6ja1', | ||
}, | ||
{ | ||
type: 'p', | ||
children: [ | ||
{ | ||
text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam aliquet arcu augue, a commodo enim volutpat ut. Vivamus congue enim sit amet odio placerat porta. ', | ||
}, | ||
], | ||
id: 'fjmih', | ||
}, | ||
]; | ||
const regularRichText: RichText = [ | ||
{ | ||
type: 'p', | ||
children: [ | ||
{ | ||
text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam aliquet arcu augue, a commodo enim volutpat ut. Vivamus congue enim sit amet odio placerat porta. Mauris semper semper lobortis. Maecenas bibendum augue vel massa efficitur dignissim. Donec et mauris venenatis, consectetur arcu ac, iaculis mauris. Nulla non turpis in ligula', | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
import { getPlainTextFromRichText, ellipsisAtMaxCharOfRichText } from './richTextHelper'; | ||
import { RichText } from '@homebase-id/js-lib/core'; | ||
test('getPlainTextFromRichText', () => { | ||
expect(getPlainTextFromRichText(regularRichText)).toBe( | ||
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam aliquet arcu augue, a commodo enim volutpat ut. Vivamus congue enim sit amet odio placerat porta. Mauris semper semper lobortis. Maecenas bibendum augue vel massa efficitur dignissim. Donec et mauris venenatis, consectetur arcu ac, iaculis mauris. Nulla non turpis in ligula' | ||
); | ||
}); | ||
|
||
test('ellipsisAtMaxCharOfRichText', () => { | ||
expect(ellipsisAtMaxCharOfRichText(regularRichText, 10)).toStrictEqual([ | ||
{ | ||
type: 'p', | ||
children: [ | ||
{ | ||
text: 'Lorem ipsu...', | ||
}, | ||
], | ||
}, | ||
]); | ||
|
||
expect(ellipsisAtMaxCharOfRichText(longRichText, 100)).toStrictEqual([ | ||
{ | ||
type: 'p', | ||
children: [ | ||
{ | ||
text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam aliquet arcu augue, a commodo enim ...', | ||
}, | ||
], | ||
id: '1vjzm', | ||
}, | ||
]); | ||
|
||
expect(ellipsisAtMaxCharOfRichText(longRichText, 140)).toStrictEqual([ | ||
{ | ||
type: 'p', | ||
children: [ | ||
{ | ||
text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam aliquet arcu augue, a commodo enim volutpat ut.', | ||
}, | ||
], | ||
id: '1vjzm', | ||
}, | ||
{ | ||
type: 'p', | ||
children: [ | ||
{ | ||
text: 'In porta magna in massa tinc...', | ||
}, | ||
], | ||
id: 'tf68w', | ||
}, | ||
]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
packages/common/common-app/src/hooks/file/useContentFromPayload.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { useDotYouClientContext } from '../auth/useDotYouClientContext'; | ||
import { getPayloadAsJson, SystemFileType, TargetDrive } from '@homebase-id/js-lib/core'; | ||
import { getPayloadAsJsonOverPeer } from '@homebase-id/js-lib/peer'; | ||
|
||
export const useContentFromPayload = <T>(props?: { | ||
odinId?: string; | ||
targetDrive: TargetDrive; | ||
fileId: string | undefined; | ||
payloadKey: string | undefined; | ||
lastModified?: number; | ||
systemFileType?: SystemFileType; | ||
}) => { | ||
const { odinId, targetDrive, fileId, payloadKey, lastModified, systemFileType } = props || {}; | ||
const dotYouClient = useDotYouClientContext(); | ||
|
||
const fetchContentFromPayload = async ( | ||
odinId: string | undefined, | ||
targetDrive: TargetDrive, | ||
fileId: string, | ||
payloadKey: string, | ||
lastModified: number | undefined, | ||
systemFileType: SystemFileType | undefined | ||
) => { | ||
if (!odinId || odinId === dotYouClient.getHostIdentity()) { | ||
return await getPayloadAsJson<T>(dotYouClient, targetDrive, fileId, payloadKey, { | ||
lastModified, | ||
systemFileType, | ||
}); | ||
} | ||
return await getPayloadAsJsonOverPeer<T>( | ||
dotYouClient, | ||
odinId, | ||
targetDrive, | ||
fileId, | ||
payloadKey, | ||
{ | ||
lastModified, | ||
systemFileType, | ||
} | ||
); | ||
}; | ||
|
||
return useQuery({ | ||
queryKey: [ | ||
'payload-content', | ||
odinId, | ||
(targetDrive as TargetDrive)?.alias, | ||
fileId, | ||
payloadKey, | ||
lastModified, | ||
], | ||
queryFn: () => | ||
fetchContentFromPayload( | ||
odinId, | ||
targetDrive as TargetDrive, | ||
fileId as string, | ||
payloadKey as string, | ||
lastModified, | ||
systemFileType | ||
), | ||
enabled: !!targetDrive && !!fileId && !!payloadKey, | ||
staleTime: 1000 * 60 * 60 * 24 * 14, // 14 Days, the lastModified is used to invalidate the cache | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters