This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
outline/app/utils/routeHelpers.js
Tom Moor 8cbcb77486 Base model refactor (#810)
* Big upgrades

* WIP: Stash

* Stash, 30 flow errors left

* Downgrade mobx

* WIP

* When I understand the difference between class and instance methods

* 💚

* Fixes: File import
Model saving edge cases
pinning and starring docs
Collection editing
Upgrade mobx devtools

* Notification settings saving works

* Disabled settings

* Document mailer

* Working notifications

* Colletion created notification
Ensure not notified for own actions

* Tidy up

* Document updated event only for document creation
Add indexes
Notification setting on user creation

* Commentary

* Fixed: Notification setting on signup

* Fix document move / duplicate stale data
Add BaseModel.refresh method

* Fixes: Title in sidebar not updated after editing document

* 💚

* Improve / restore error handling
Better handle offline errors

* 👕
2018-12-04 22:24:30 -08:00

78 lines
1.9 KiB
JavaScript

// @flow
import Document from 'models/Document';
import Collection from 'models/Collection';
export function homeUrl(): string {
return '/dashboard';
}
export function starredUrl(): string {
return '/starred';
}
export function newCollectionUrl(): string {
return '/collections/new';
}
export function collectionUrl(collectionId: string): string {
return `/collections/${collectionId}`;
}
export function documentUrl(doc: Document): string {
return doc.url;
}
export function documentNewUrl(doc: Document): string {
const newUrl = `${doc.collection.url || ''}/new`;
if (doc.parentDocumentId) {
return `${newUrl}?parentDocument=${doc.parentDocumentId}`;
}
return newUrl;
}
export function documentEditUrl(doc: Document): string {
return `${doc.url}/edit`;
}
export function documentMoveUrl(doc: Document): string {
return `${doc.url}/move`;
}
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, newUrl: string): string {
// Update url to match the current one
const urlParts = oldUrl.trim().split('/');
const actions = urlParts.slice(3);
if (actions[0]) {
return [newUrl, actions].join('/');
}
return newUrl;
}
export function newDocumentUrl(collection: Collection): string {
return `${collection.url || ''}/new`;
}
export function searchUrl(query?: string): string {
if (query) return `/search/${encodeURIComponent(query)}`;
return `/search`;
}
export function notFoundUrl(): string {
return '/404';
}
export const matchDocumentSlug =
':documentSlug([0-9a-zA-Z-_~]*-[a-zA-z0-9]{10,15})';
export const matchDocumentEdit = `/doc/${matchDocumentSlug}/edit`;