-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🏷️ fix: Address Statefulness Issues for Bookmarks (#3590)
* refactor: optimize tag methods, remove rebuild * refactor(tags): add lean db operations, fix updateTagsForConversation, remove rebuild button, only send convoId once * refactor: Update BookmarkMenu to use Constants.NEW_CONVO constant for comparison * style: Update BookmarkMenu styles and constants, use theming * refactor: move tags query from package to client workspace * refactor: optimize ConversationTag document creation and update logic * style: Update BookmarkMenuItems to use theming * refactor: JSDocs + try/catch for conversation tags API routes * refactor: Update BookmarkNav theming classes and new data provider location * fix: statefulness of conversation bookmarks - move non-mutation hook to hooks/Conversation - remove use of deprecated global convo - update convo infinite data as well as current convo state upon successful tag add * refactor: Update BookmarkMenu styles and constants, use theming * refactor: Add lean option to ConversationTag deletion query * fix(BookmarkTable): position order rendering esp. when new tag is created * refactor: Update useBookmarkSucess to useBookmarkSuccess for consistency * refactor: Update ConversationTag creation logic to increment count only if addToConversation is true * style: theming
- Loading branch information
1 parent
6ea2628
commit 016ed86
Showing
28 changed files
with
607 additions
and
521 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,88 @@ | ||
const express = require('express'); | ||
|
||
const { | ||
getConversationTags, | ||
updateConversationTag, | ||
createConversationTag, | ||
deleteConversationTag, | ||
rebuildConversationTags, | ||
} = require('~/models/ConversationTag'); | ||
const requireJwtAuth = require('~/server/middleware/requireJwtAuth'); | ||
const router = express.Router(); | ||
router.use(requireJwtAuth); | ||
|
||
/** | ||
* GET / | ||
* Retrieves all conversation tags for the authenticated user. | ||
* @param {Object} req - Express request object | ||
* @param {Object} res - Express response object | ||
*/ | ||
router.get('/', async (req, res) => { | ||
const tags = await getConversationTags(req.user.id); | ||
|
||
if (tags) { | ||
res.status(200).json(tags); | ||
} else { | ||
res.status(404).end(); | ||
try { | ||
const tags = await getConversationTags(req.user.id); | ||
if (tags) { | ||
res.status(200).json(tags); | ||
} else { | ||
res.status(404).end(); | ||
} | ||
} catch (error) { | ||
console.error('Error getting conversation tags:', error); | ||
res.status(500).json({ error: 'Internal server error' }); | ||
} | ||
}); | ||
|
||
/** | ||
* POST / | ||
* Creates a new conversation tag for the authenticated user. | ||
* @param {Object} req - Express request object | ||
* @param {Object} res - Express response object | ||
*/ | ||
router.post('/', async (req, res) => { | ||
const tag = await createConversationTag(req.user.id, req.body); | ||
res.status(200).json(tag); | ||
}); | ||
|
||
router.post('/rebuild', async (req, res) => { | ||
const tag = await rebuildConversationTags(req.user.id); | ||
res.status(200).json(tag); | ||
try { | ||
const tag = await createConversationTag(req.user.id, req.body); | ||
res.status(200).json(tag); | ||
} catch (error) { | ||
console.error('Error creating conversation tag:', error); | ||
res.status(500).json({ error: 'Internal server error' }); | ||
} | ||
}); | ||
|
||
/** | ||
* PUT /:tag | ||
* Updates an existing conversation tag for the authenticated user. | ||
* @param {Object} req - Express request object | ||
* @param {Object} res - Express response object | ||
*/ | ||
router.put('/:tag', async (req, res) => { | ||
const tag = await updateConversationTag(req.user.id, req.params.tag, req.body); | ||
res.status(200).json(tag); | ||
try { | ||
const tag = await updateConversationTag(req.user.id, req.params.tag, req.body); | ||
if (tag) { | ||
res.status(200).json(tag); | ||
} else { | ||
res.status(404).json({ error: 'Tag not found' }); | ||
} | ||
} catch (error) { | ||
console.error('Error updating conversation tag:', error); | ||
res.status(500).json({ error: 'Internal server error' }); | ||
} | ||
}); | ||
|
||
/** | ||
* DELETE /:tag | ||
* Deletes a conversation tag for the authenticated user. | ||
* @param {Object} req - Express request object | ||
* @param {Object} res - Express response object | ||
*/ | ||
router.delete('/:tag', async (req, res) => { | ||
const tag = await deleteConversationTag(req.user.id, req.params.tag); | ||
res.status(200).json(tag); | ||
try { | ||
const tag = await deleteConversationTag(req.user.id, req.params.tag); | ||
if (tag) { | ||
res.status(200).json(tag); | ||
} else { | ||
res.status(404).json({ error: 'Tag not found' }); | ||
} | ||
} catch (error) { | ||
console.error('Error deleting conversation tag:', error); | ||
res.status(500).json({ error: 'Internal server error' }); | ||
} | ||
}); | ||
|
||
module.exports = router; |
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
Oops, something went wrong.