forked from tldraw/tldraw
-
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.
Organize file paths. Should help us stay a bit more consistent when defining and using paths of our app. ### Change type - [ ] `bugfix` - [x] `improvement` - [ ] `feature` - [ ] `api` - [ ] `other` ### Release notes - Help with tla route / paths organization.
- Loading branch information
1 parent
0a5a334
commit 9be3b6f
Showing
9 changed files
with
69 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import { Navigate, Outlet } from 'react-router-dom' | ||
import { useMaybeApp } from '../hooks/useAppState' | ||
import { getRootPath } from '../utils/urls' | ||
|
||
export function Component() { | ||
const app = useMaybeApp() | ||
if (!app) { | ||
// todo: add a back-to location in the location state, redirect back to here after sign in | ||
return <Navigate to="/q" /> | ||
return <Navigate to={getRootPath()} /> | ||
} | ||
return <Outlet /> | ||
} |
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,11 +1,41 @@ | ||
export function getFilePath(fileId: string): string { | ||
return `/q/f/${fileId.split(':').pop()}` | ||
export const PREFIX = { | ||
tla: 'q', | ||
file: 'f', | ||
publish: 'p', | ||
} | ||
|
||
export function buildUrl({ pathname }: { pathname: string }): string { | ||
return `/${PREFIX.tla}${pathname}` | ||
} | ||
|
||
export function getRootPath() { | ||
return buildUrl({ pathname: '/' }) | ||
} | ||
|
||
export function getDebugPath() { | ||
return buildUrl({ pathname: '/debug' }) | ||
} | ||
|
||
export function getProfilePath() { | ||
return buildUrl({ pathname: '/profile' }) | ||
} | ||
|
||
export function getFilePath(fileId: string) { | ||
return buildUrl({ pathname: `/${PREFIX.file}/${fileId.split(':').pop()}` }) | ||
} | ||
|
||
export function getPublishPath(publishSlug: string) { | ||
return buildUrl({ pathname: `/${PREFIX.publish}/${publishSlug}` }) | ||
} | ||
|
||
function absoluteUrl(path: string) { | ||
return `${window.location.origin}${path}` | ||
} | ||
|
||
export function getShareableFileUrl(fileId: string): string { | ||
return `${window.location.origin}${getFilePath(fileId)}` | ||
return absoluteUrl(getFilePath(fileId)) | ||
} | ||
|
||
export function getShareablePublishUrl(publishSlug: string): string { | ||
return `${window.location.origin}/q/p/${publishSlug}` | ||
return absoluteUrl(getPublishPath(publishSlug)) | ||
} |