* Comment model * Framework, model, policy, presenter, api endpoint etc * Iteration, first pass of UI * fixes, refactors * Comment commands * comment socket support * typing indicators * comment component, styling * wip * right sidebar resize * fix: CMD+Enter submit * Add usePersistedState fix: Main page scrolling on comment highlight * drafts * Typing indicator * refactor * policies * Click thread to highlight Improve comment timestamps * padding * Comment menu v1 * Change comments to use editor * Basic comment editing * fix: Hide commenting button when disabled at team level * Enable opening sidebar without mark * Move selected comment to location state * Add comment delete confirmation * Add comment count to document meta * fix: Comment sidebar togglable Add copy link to comment * stash * Restore History changes * Refactor right sidebar to allow for comment animation * Update to new router best practices * stash * Various improvements * stash * Handle click outside * Fix incorrect placeholder in input fix: Input box appearing on other sessions erroneously * stash * fix: Don't leave orphaned child comments * styling * stash * Enable comment toggling again * Edit styling, merge conflicts * fix: Cannot navigate from insights to comments * Remove draft comment mark on click outside * Fix: Empty comment sidebar, tsc * Remove public toggle * fix: All comments are recessed fix: Comments should not be printed * fix: Associated mark should be removed on comment delete * Revert unused changes * Empty state, basic RTL support * Create dont toggle comment mark * Make it feel more snappy * Highlight active comment in text * fix animation * RTL support * Add reply CTA * Translations
152 lines
3.4 KiB
TypeScript
152 lines
3.4 KiB
TypeScript
import queryString from "query-string";
|
|
import Collection from "~/models/Collection";
|
|
import Comment from "~/models/Comment";
|
|
import Document from "~/models/Document";
|
|
import env from "~/env";
|
|
|
|
export function homePath(): string {
|
|
return "/home";
|
|
}
|
|
|
|
export function draftsPath(): string {
|
|
return "/drafts";
|
|
}
|
|
|
|
export function templatesPath(): string {
|
|
return "/templates";
|
|
}
|
|
|
|
export function archivePath(): string {
|
|
return "/archive";
|
|
}
|
|
|
|
export function trashPath(): string {
|
|
return "/trash";
|
|
}
|
|
|
|
export function settingsPath(): string {
|
|
return "/settings";
|
|
}
|
|
|
|
export function organizationSettingsPath(): string {
|
|
return "/settings/details";
|
|
}
|
|
|
|
export function profileSettingsPath(): string {
|
|
return "/settings";
|
|
}
|
|
|
|
export function accountPreferencesPath(): string {
|
|
return "/settings/preferences";
|
|
}
|
|
|
|
export function groupSettingsPath(): string {
|
|
return "/settings/groups";
|
|
}
|
|
|
|
export function commentPath(document: Document, comment: Comment): string {
|
|
return `${documentUrl(document)}?commentId=${comment.id}`;
|
|
}
|
|
|
|
export function collectionUrl(url: string, section?: string): string {
|
|
if (section) {
|
|
return `${url}/${section}`;
|
|
}
|
|
return url;
|
|
}
|
|
|
|
export function updateCollectionUrl(
|
|
oldUrl: string,
|
|
collection: Collection
|
|
): string {
|
|
// Update url to match the current one
|
|
return oldUrl.replace(
|
|
new RegExp("/collection/[0-9a-zA-Z-_~]*"),
|
|
collection.url
|
|
);
|
|
}
|
|
|
|
export function documentUrl(doc: Document): string {
|
|
return doc.url;
|
|
}
|
|
|
|
export function editDocumentUrl(doc: Document): string {
|
|
return `${doc.url}/edit`;
|
|
}
|
|
|
|
export function documentInsightsUrl(doc: Document): string {
|
|
return `${doc.url}/insights`;
|
|
}
|
|
|
|
export function documentHistoryUrl(doc: Document, revisionId?: string): string {
|
|
let base = `${doc.url}/history`;
|
|
if (revisionId) {
|
|
base += `/${revisionId}`;
|
|
}
|
|
return base;
|
|
}
|
|
|
|
/**
|
|
* Replace full url's document part with the new one in case
|
|
* the document slug has been updated
|
|
*/
|
|
export function updateDocumentUrl(oldUrl: string, document: Document): string {
|
|
// Update url to match the current one
|
|
return oldUrl.replace(
|
|
new RegExp("/doc/([0-9a-zA-Z-_~]*-[a-zA-z0-9]{10,15})"),
|
|
document.url
|
|
);
|
|
}
|
|
|
|
export function newDocumentPath(
|
|
collectionId?: string,
|
|
params: {
|
|
parentDocumentId?: string;
|
|
templateId?: string;
|
|
template?: boolean;
|
|
} = {}
|
|
): string {
|
|
return collectionId
|
|
? `/collection/${collectionId}/new?${queryString.stringify(params)}`
|
|
: `/doc/new`;
|
|
}
|
|
|
|
export function searchPath(
|
|
query?: string,
|
|
params: {
|
|
collectionId?: string;
|
|
ref?: string;
|
|
} = {}
|
|
): string {
|
|
let search = queryString.stringify(params);
|
|
let route = "/search";
|
|
|
|
if (query) {
|
|
route += `/${encodeURIComponent(query.replace(/%/g, "%25"))}`;
|
|
}
|
|
|
|
search = search ? `?${search}` : "";
|
|
return `${route}${search}`;
|
|
}
|
|
|
|
export function sharedDocumentPath(shareId: string, docPath?: string) {
|
|
return docPath ? `/s/${shareId}${docPath}` : `/s/${shareId}`;
|
|
}
|
|
|
|
export function notFoundUrl(): string {
|
|
return "/404";
|
|
}
|
|
|
|
export function urlify(path: string): string {
|
|
return `${env.URL}${path}`;
|
|
}
|
|
|
|
export const matchDocumentSlug =
|
|
":documentSlug([0-9a-zA-Z-_~]*-[a-zA-z0-9]{10,15})";
|
|
|
|
export const matchDocumentEdit = `/doc/${matchDocumentSlug}/edit`;
|
|
|
|
export const matchDocumentHistory = `/doc/${matchDocumentSlug}/history/:revisionId?`;
|
|
|
|
export const matchDocumentInsights = `/doc/${matchDocumentSlug}/insights`;
|