Skip to content

Commit 320433e

Browse files
committed
feat: Add sharing notes to help transcript and improve shared item UX
- Add system notes to help transcript when items are shared between users - Display 'Shared by [user] on [date]' in recipient's help panel - Make system notes clickable to load the shared task - Show user icon indicator for items received via sharing - Clear taskId on share and regenerate when recipient loads item - Style system notes with subtle gray background - Exclude current user from share dialog selection
1 parent 5f8ab89 commit 320433e

3 files changed

Lines changed: 39 additions & 10 deletions

File tree

src/components/HelpPanel.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,9 +1304,10 @@ export const HelpPanel = ({
13041304

13051305
// Function to prepare messages for display
13061306
const prepareMessagesForDisplay = () => {
1307-
// Find all user messages in chronological order (oldest to newest)
1307+
// Find all user and system messages in chronological order (oldest to newest)
1308+
// Include both user messages and system messages (e.g., sharing notes)
13081309
const userMessages = help
1309-
.filter(item => item.type === 'user')
1310+
.filter(item => item.type === 'user' || item.role === 'system')
13101311
.map((msg, idx) => ({
13111312
...msg,
13121313
index: help.indexOf(msg)
@@ -2044,7 +2045,7 @@ export const HelpPanel = ({
20442045
</button>
20452046

20462047
<div
2047-
className={`bg-blue-100 rounded-lg p-3 overflow-hidden ${isPending ? 'border-2 border-blue-300' : ''} ${message.taskId && message.taskId === taskId ? 'border-2 border-blue-500' : ''} ${message.taskId && onLoadTaskFromHelp ? 'cursor-pointer hover:bg-blue-200 transition-colors' : ''}`}
2048+
className={`${message.role === 'system' ? 'bg-gray-100' : 'bg-blue-100'} rounded-lg p-3 overflow-hidden ${isPending ? 'border-2 border-blue-300' : ''} ${message.role !== 'system' && message.taskId && message.taskId === taskId ? 'border-2 border-blue-500' : ''} ${message.taskId && onLoadTaskFromHelp ? `cursor-pointer ${message.role === 'system' ? 'hover:bg-gray-200' : 'hover:bg-blue-200'} transition-colors` : ''}`}
20482049
onClick={() => {
20492050
if (message.taskId && onLoadTaskFromHelp) {
20502051
onLoadTaskFromHelp(message.taskId);
@@ -2117,7 +2118,7 @@ export const HelpPanel = ({
21172118
}
21182119
}}
21192120
>
2120-
{message.user}
2121+
{message.role === 'system' ? message.content : message.user}
21212122
</ReactMarkdown>
21222123
</div>
21232124
</div>

src/components/ItemsNav.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,8 @@ export default function ItemsNav({ items, selectedItemId, onSelectItem, onUpdate
256256
>
257257
<span className="truncate">{item.name}</span>
258258
{/* Show icon if item was shared with the user */}
259-
{item.name.includes('(from ') && (
260-
<UserIcon className="h-3 w-3 ml-1 text-gray-400 flex-shrink-0" title="Shared with you" />
259+
{item.sharedFrom && (
260+
<UserIcon className="h-3 w-3 ml-1 text-gray-400 flex-shrink-0" title={`Shared from ${item.sharedFrom}`} />
261261
)}
262262
</button>
263263
{ item.id === showId &&

src/pages/api/resolvers.ts

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -525,18 +525,22 @@ export async function getItems({ auth, lang, mark }) {
525525
// Get the sharedWith list for this item
526526
const sharedWith = sharedItemsData[doc.id]?.sharedWith || [];
527527

528-
items.push({
528+
const item = {
529529
id: doc.id,
530-
...data,
530+
name: data.name,
531531
taskId, // Include the potentially new taskId
532+
lang: data.lang,
532533
mark: data.mark || 1, // Default to mark 1 if not set
533534
help: help || "[]",
534535
code: code || "",
535536
isPublic: data.isPublic || false,
536537
created: String(data.created),
537538
updated: data.updated ? String(data.updated) : String(data.created),
538539
sharedWith: sharedWith,
539-
});
540+
sharedFrom: data.sharedFrom || null, // Include sharedFrom field if present
541+
};
542+
543+
items.push(item);
540544
}
541545
return items;
542546
} catch (error) {
@@ -611,11 +615,35 @@ export async function shareItem({ auth, itemId, targetUserId }) {
611615
const newItemId = targetItemRef.id;
612616
const timestamp = Date.now();
613617

618+
// Add a note to the help transcript about where the item was shared from
619+
let updatedHelp = itemData.help || "[]";
620+
try {
621+
const helpArray = JSON.parse(updatedHelp);
622+
// Add a note at the end of the help transcript (since display is reversed)
623+
helpArray.push({
624+
role: "system",
625+
content: `Shared by ${auth.uid} on ${new Date(timestamp).toISOString().split('T')[0]}`,
626+
timestamp: timestamp,
627+
taskId: itemData.taskId // Include the original task ID for clickability
628+
});
629+
updatedHelp = JSON.stringify(helpArray);
630+
} catch (error) {
631+
// If help is not valid JSON, create a new array with the note
632+
updatedHelp = JSON.stringify([{
633+
role: "system",
634+
content: `Shared by ${auth.uid} on ${new Date(timestamp).toISOString().split('T')[0]}`,
635+
timestamp: timestamp,
636+
taskId: itemData.taskId // Include the original task ID for clickability
637+
}]);
638+
}
639+
614640
const sharedItem = {
615641
...itemData,
616642
id: newItemId,
617643
taskId: null, // Clear the task ID - it will be created when the user loads the item
618-
name: `${itemData.name} (from ${auth.uid})`,
644+
name: itemData.name,
645+
help: updatedHelp,
646+
sharedFrom: auth.uid, // Track who shared this item
619647
created: timestamp,
620648
updated: timestamp,
621649
// Don't copy the isPublic flag - let the recipient decide

0 commit comments

Comments
 (0)