mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
feat: integrate trpc to app
This commit is contained in:
1 parent
529869671c
commit
55a41dd3b5
7 files changed
+50
-6
No files matched your search
@@ -20,6 +20,7 @@
|
|||||||
"@linux-odyssey/file-graph": "*",
|
"@linux-odyssey/file-graph": "*",
|
||||||
"@linux-odyssey/models": "*",
|
"@linux-odyssey/models": "*",
|
||||||
"@linux-odyssey/utils": "*",
|
"@linux-odyssey/utils": "*",
|
||||||
|
"@trpc/client": "^11.1.0",
|
||||||
"@types/dompurify": "^3.0.5",
|
"@types/dompurify": "^3.0.5",
|
||||||
"axios": "^1.6.0",
|
"axios": "^1.6.0",
|
||||||
"dompurify": "^3.0.6",
|
"dompurify": "^3.0.6",
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { onMounted } from 'vue'
|
|||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import { useToast } from 'vue-toastification'
|
import { useToast } from 'vue-toastification'
|
||||||
import { logout } from '../../utils/auth'
|
import { logout } from '../../utils/auth'
|
||||||
import { surveyUrl } from '../../config'
|
import { trpc } from '../../utils/trpc'
|
||||||
import { openBugReport } from '../../utils/formbricks'
|
import { openBugReport } from '../../utils/formbricks'
|
||||||
import useSession from '../../store/session'
|
import useSession from '../../store/session'
|
||||||
import useUserProfile from '../../store/userProfile'
|
import useUserProfile from '../../store/userProfile'
|
||||||
@@ -26,6 +26,11 @@ const handleLogout = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const openSurvey = async () => {
|
||||||
|
const surveyUrl = await trpc.links.surveyLink.query()
|
||||||
|
window.open(surveyUrl, '_blank')
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
try {
|
try {
|
||||||
await userStore.loadUserProfile()
|
await userStore.loadUserProfile()
|
||||||
@@ -61,18 +66,18 @@ onMounted(async () => {
|
|||||||
>
|
>
|
||||||
{{ userStore.username }}
|
{{ userStore.username }}
|
||||||
</p>
|
</p>
|
||||||
<a
|
<button
|
||||||
title="Survey"
|
title="Survey"
|
||||||
:href="surveyUrl"
|
|
||||||
target="_blank"
|
target="_blank"
|
||||||
class="md:h-5 md:w-5 px-1.5 w-auto"
|
class="md:h-5 md:w-5 px-1.5 w-auto"
|
||||||
|
@click="openSurvey"
|
||||||
>
|
>
|
||||||
<font-awesome-icon
|
<font-awesome-icon
|
||||||
:icon="['fas', 'file-invoice']"
|
:icon="['fas', 'file-invoice']"
|
||||||
class="text-text-primary inline"
|
class="text-text-primary inline"
|
||||||
/>
|
/>
|
||||||
<span class="text-text sm:hidden px-2">Survey</span>
|
<span class="text-text sm:hidden px-2">Survey</span>
|
||||||
</a>
|
</button>
|
||||||
<RouterLink
|
<RouterLink
|
||||||
title="LeaderBoard"
|
title="LeaderBoard"
|
||||||
to="/leaderboard"
|
to="/leaderboard"
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import { createTRPCClient, httpBatchLink } from '@trpc/client'
|
||||||
|
import type { AppRouter } from 'server/src/routers'
|
||||||
|
|
||||||
|
export const trpc = createTRPCClient<AppRouter>({
|
||||||
|
links: [
|
||||||
|
httpBatchLink({
|
||||||
|
url: '/trpc',
|
||||||
|
// You can pass any HTTP headers you wish here
|
||||||
|
// async headers() {
|
||||||
|
// return {
|
||||||
|
// authorization: getAuthCookie(),
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
})
|
||||||
@@ -6,6 +6,11 @@ export default defineConfig({
|
|||||||
plugins: [vue()],
|
plugins: [vue()],
|
||||||
server: {
|
server: {
|
||||||
proxy: {
|
proxy: {
|
||||||
|
'/trpc': {
|
||||||
|
target: process.env.API_TARGET || 'http://localhost:3000',
|
||||||
|
changeOrigin: false,
|
||||||
|
xfwd: true,
|
||||||
|
},
|
||||||
'/api': {
|
'/api': {
|
||||||
target: process.env.API_TARGET || 'http://localhost:3000',
|
target: process.env.API_TARGET || 'http://localhost:3000',
|
||||||
changeOrigin: false,
|
changeOrigin: false,
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import { router, publicProcedure } from '../trpc.js'
|
import { router, publicProcedure } from '../trpc.js'
|
||||||
|
import { linkRouter } from './linkRouter.js'
|
||||||
|
|
||||||
export const appRouter = router({
|
export const appRouter = router({
|
||||||
userList: publicProcedure.query(async (opts) => {
|
userList: publicProcedure.query(async (opts) => {
|
||||||
// Retrieve users from a datasource, this is an imaginary database
|
// Retrieve users from a datasource, this is an imaginary database
|
||||||
return opts.ctx
|
return opts.ctx
|
||||||
}),
|
}),
|
||||||
|
links: linkRouter,
|
||||||
})
|
})
|
||||||
// Export type router type signature,
|
|
||||||
// NOT the router itself.
|
|
||||||
export type AppRouter = typeof appRouter
|
export type AppRouter = typeof appRouter
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import config from '../config.js'
|
||||||
|
import { publicProcedure, router } from '../trpc.js'
|
||||||
|
|
||||||
|
export const linkRouter = router({
|
||||||
|
surveyLink: publicProcedure.query(() => {
|
||||||
|
return config.surveyUrl
|
||||||
|
}),
|
||||||
|
bugReportLink: publicProcedure.query(() => {
|
||||||
|
return config.bugReportUrl
|
||||||
|
}),
|
||||||
|
})
|
||||||
@@ -1711,6 +1711,11 @@
|
|||||||
lz-string "^1.5.0"
|
lz-string "^1.5.0"
|
||||||
pretty-format "^27.0.2"
|
pretty-format "^27.0.2"
|
||||||
|
|
||||||
|
"@trpc/client@^11.1.0":
|
||||||
|
version "11.1.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/@trpc/client/-/client-11.1.0.tgz#102ec1f14aa39c4caf5106c51f38a3d4bee293b0"
|
||||||
|
integrity sha512-Q3pL4p7AddxI/ZJTEFo1utKSdasDFjZPECIPsKDkthEt52k530JkYVltTdLkYFKrNWXKKBo8MN7NwchelczoRw==
|
||||||
|
|
||||||
"@trpc/server@^11.1.0":
|
"@trpc/server@^11.1.0":
|
||||||
version "11.1.0"
|
version "11.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/@trpc/server/-/server-11.1.0.tgz#8169fa8b944beddf65a95f376d4afea5732be254"
|
resolved "https://registry.yarnpkg.com/@trpc/server/-/server-11.1.0.tgz#8169fa8b944beddf65a95f376d4afea5732be254"
|
||||||
|
|||||||
Reference in new issue
Block a user