-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: - add short link for record - add short link for level
- Loading branch information
Showing
3 changed files
with
68 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
export default defineNuxtComponent({ | ||
async setup() { | ||
const route = useRoute() | ||
const id = decompressLevelId(route.params.id.toString()) | ||
|
||
let levelId = id.toString() | ||
|
||
try { | ||
const level = await $fetch<{ uid: string }>( | ||
useServiceUrl(`/levels/${id}`), | ||
) | ||
if (level?.uid) { | ||
levelId = level.uid | ||
} | ||
} | ||
catch (error) { | ||
console.error(error) | ||
} | ||
await navigateTo({ | ||
name: 'levels-id', | ||
params: { id: levelId }, | ||
}) | ||
}, | ||
render() { | ||
return null // This component doesn't render anything | ||
}, | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export default defineNuxtComponent({ | ||
async setup() { | ||
const route = useRoute() | ||
const uid = route.params.uid.toString() | ||
const { chartId, recordId } = decompressRecordId(uid) | ||
await navigateTo({ | ||
name: 'records-chartId-id', | ||
params: { chartId, id: recordId }, | ||
}) | ||
}, | ||
render() { | ||
return null // This component doesn't render anything | ||
}, | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
export function compressRecordId(chartId: number, recordId: number) { | ||
const base36Num1 = chartId.toString(36) | ||
const base36Num2 = recordId.toString(36) | ||
|
||
return `${base36Num1}-${base36Num2}` | ||
} | ||
|
||
export function decompressRecordId(compressedId: string) { | ||
const [base36Num1, base36Num2] = compressedId.split('-') | ||
const chartId = Number.parseInt(base36Num1, 36) | ||
const recordId = Number.parseInt(base36Num2, 36) | ||
|
||
return { chartId, recordId } | ||
} | ||
|
||
export function compressLevelId(levelId: number) { | ||
const base36Num = levelId.toString(36) | ||
|
||
return base36Num | ||
} | ||
|
||
export function decompressLevelId(compressedId: string) { | ||
const base36Num = compressedId | ||
const id = Number.parseInt(base36Num, 36) | ||
|
||
return id | ||
} |