Compare commits

...

3 Commits

Author SHA1 Message Date
0523df45cf Quick reply 2025-11-29 23:59:36 +08:00
b295012340 🐛 Fix the auth middleware 2025-11-29 23:50:30 +08:00
2c395e36d3 🐛 Fix bugs 2025-11-29 23:43:00 +08:00
9 changed files with 147 additions and 70 deletions

View File

@@ -29,7 +29,7 @@
<audio <audio
v-else-if="itemType == 'audio'" v-else-if="itemType == 'audio'"
class="w-full h-auto" class="w-full"
:src="remoteSource" :src="remoteSource"
controls controls
/> />

View File

@@ -31,8 +31,7 @@
</n-carousel> </n-carousel>
</div> </div>
<!-- Mixed content: vertical scrollable --> <div v-else class="space-y-4 flex flex-col">
<div v-else class="space-y-4 max-h-96 overflow-y-auto">
<attachment-item <attachment-item
v-for="attachment in attachments" v-for="attachment in attachments"
:key="attachment.id" :key="attachment.id"

View File

@@ -1,5 +1,5 @@
<template> <template>
<div class="flex flex-col gap-2"> <div class="flex flex-col gap-3">
<pub-select v-model:value="publisher" /> <pub-select v-model:value="publisher" />
<n-input <n-input
v-model:value="content" v-model:value="content"
@@ -8,11 +8,11 @@
@keydown.meta.enter.exact="submit" @keydown.meta.enter.exact="submit"
@keydown.ctrl.enter.exact="submit" @keydown.ctrl.enter.exact="submit"
/> />
<div class="flex justify-between"> <div class="flex justify-end">
<n-button type="primary" :loading="submitting" @click="submit"> <n-button type="primary" :loading="submitting" @click="submit">
Post Post
<template #icon> <template #icon>
<span class="mdi mdi-send"></span> <n-icon :component="SendIcon" />
</template> </template>
</n-button> </n-button>
</div> </div>
@@ -20,8 +20,9 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref } from 'vue' import { SendIcon } from "lucide-vue-next"
import { useSolarNetwork } from '~/composables/useSolarNetwork' import { ref } from "vue"
import { useSolarNetwork } from "~/composables/useSolarNetwork"
// Interface for uploaded files in the editor // Interface for uploaded files in the editor
interface UploadedFile { interface UploadedFile {
@@ -30,10 +31,10 @@ interface UploadedFile {
type: string type: string
} }
const emits = defineEmits(['posted']) const emits = defineEmits(["posted"])
const publisher = ref<string | undefined>() const publisher = ref<string | undefined>()
const content = ref('') const content = ref("")
const fileList = ref<UploadedFile[]>([]) const fileList = ref<UploadedFile[]>([])
@@ -43,21 +44,21 @@ async function submit() {
submitting.value = true submitting.value = true
const api = useSolarNetwork() const api = useSolarNetwork()
await api(`/sphere/posts?pub=${publisher.value}`, { await api(`/sphere/posts?pub=${publisher.value}`, {
method: 'POST', method: "POST",
headers: { headers: {
'content-type': 'application/json', "content-type": "application/json"
}, },
body: JSON.stringify({ body: JSON.stringify({
content: content.value, content: content.value,
attachments: fileList.value attachments: fileList.value
.filter((e) => e.url != null) .filter((e) => e.url != null)
.map((e) => e.url!.split('/').reverse()[0]), .map((e) => e.url!.split("/").reverse()[0])
}), })
}) })
submitting.value = false submitting.value = false
content.value = '' content.value = ""
fileList.value = [] fileList.value = []
emits('posted') emits("posted")
} }
</script> </script>

View File

@@ -1,23 +1,78 @@
<template> <template>
<n-card title="Post your reply" size="small" embedded> <n-card title="Quick Reply" size="small" embedded>
<n-input <div class="flex flex-col gap-2 mb-1">
type="textarea" <pub-select v-model:value="publisher" />
placeholder="Talk about this post for a bit." <n-input
size="large" v-model:value="content"
:rows="5" type="textarea"
auto-grow placeholder="Talk about this post for a bit."
></n-input> size="large"
<div class="flex justify-end mt-3"> :rows="3"
<n-button type="primary"> auto-grow
<template #icon> @keydown.meta.enter.exact="submit"
<n-icon :component="SendIcon" /> @keydown.ctrl.enter.exact="submit"
>
<template #suffix>
<div class="flex items-end h-full py-3">
<n-button text :loading="submitting" @click="submit">
<template #icon>
<n-icon :component="SendIcon" />
</template>
</n-button>
</div>
</template> </template>
Send </n-input>
</n-button>
</div> </div>
</n-card> </n-card>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { SendIcon } from "lucide-vue-next" import { SendIcon } from "lucide-vue-next"
import { ref } from "vue"
import { useSolarNetwork } from "~/composables/useSolarNetwork"
// Interface for uploaded files in the editor
interface UploadedFile {
name: string
url: string
type: string
}
const props = defineProps<{
repliedPostId: string
}>()
const emits = defineEmits(["posted"])
const publisher = ref<string | undefined>()
const content = ref("")
const fileList = ref<UploadedFile[]>([])
const submitting = ref(false)
async function submit() {
if (!content.value.trim()) return
submitting.value = true
const api = useSolarNetwork()
await api(`/sphere/posts?pub=${publisher.value}`, {
method: "POST",
headers: {
"content-type": "application/json"
},
body: JSON.stringify({
content: content.value,
replied_post_id: props.repliedPostId,
attachments: fileList.value
.filter((e) => e.url != null)
.map((e) => e.url!.split("/").reverse()[0])
})
})
submitting.value = false
content.value = ""
fileList.value = []
emits("posted")
}
</script> </script>

View File

@@ -1,6 +1,11 @@
<template> <template>
<div class="replies-list"> <div class="replies-list">
<post-quick-reply v-if="!props.hideQuickReply" class="mb-4" /> <post-quick-reply
v-if="!props.hideQuickReply"
:replied-post-id="props.params.postId"
@posted="refresh"
class="mb-4"
/>
<!-- Error State --> <!-- Error State -->
<n-alert <n-alert

View File

@@ -1,65 +1,74 @@
<template> <template>
<n-select <n-config-provider :theme-overrides="{ common: { borderRadius: '8px' } }">
:options="pubStore.publishers" <n-select
label-field="nick" :options="pubStore.publishers"
value-field="name" label-field="nick"
:value="props.value" value-field="name"
@update:value="(v) => emits('update:value', v)" :value="props.value"
:render-label="renderLabel" @update:value="(v) => emits('update:value', v)"
:render-tag="renderTag" :render-label="renderLabel"
/> :render-tag="renderTag"
/>
</n-config-provider>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { usePubStore } from '~/stores/pub' import { usePubStore } from "~/stores/pub"
import { watch, h } from 'vue' import { watch, h } from "vue"
import type { SelectRenderLabel, SelectRenderTag } from 'naive-ui' import type { SelectRenderLabel, SelectRenderTag } from "naive-ui"
const pubStore = usePubStore() const pubStore = usePubStore()
const apiBase = useSolarNetworkUrl() const apiBase = useSolarNetworkUrl()
const props = defineProps<{ value: string | undefined }>() const props = defineProps<{ value: string | undefined }>()
const emits = defineEmits(['update:value']) const emits = defineEmits(["update:value"])
const renderLabel: SelectRenderLabel = (option) => { const renderLabel: SelectRenderLabel = (option) => {
return h('div', { class: 'flex items-center' }, [ const pubData = pubStore.publishers.filter((p) => p.id == option.id)[0]
return h("div", { class: "flex items-center" }, [
h(NAvatar, { h(NAvatar, {
src: option.picture ? `${apiBase.value}/drive/files/${option.picture.id}` : undefined, round: true,
size: 'small', src: pubData?.picture?.id
class: 'mr-2' ? `${apiBase}/drive/files/${pubData.picture!.id}`
: undefined,
size: "small",
class: "mr-2"
}), }),
h('div', null, [ h("div", null, [
h('div', null, option.nick as string), h("div", null, pubData!.nick),
h('div', { class: 'text-xs text-gray-500' }, `@${option.name as string}`) h("div", { class: "text-xs opacity-80" }, `@${pubData!.name as string}`)
]) ])
]) ])
} }
const renderTag: SelectRenderTag = ({ option }) => { const renderTag: SelectRenderTag = ({ option }) => {
const pubData = pubStore.publishers.filter((p) => p.id == option.id)[0]
return h( return h(
'div', "div",
{ {
class: 'flex items-center' class: "flex items-center"
}, },
[ [
h(NAvatar, { h(NAvatar, {
src: option.picture ? `${apiBase.value}/drive/files/${option.picture.id}` : undefined, round: true,
size: 'small', src: pubData?.picture?.id
class: 'mr-2' ? `${apiBase}/drive/files/${pubData.picture!.id}`
: undefined,
size: "small",
class: "mr-2"
}), }),
option.nick as string option.nick as string
] ]
) )
} }
watch( watch(
pubStore, pubStore,
(value) => { (value) => {
if (!props.value && value.publishers) { if (!props.value && value.publishers) {
emits('update:value', pubStore.publishers[0]?.name) emits("update:value", pubStore.publishers[0]?.name)
} }
}, },
{ deep: true, immediate: true }, { deep: true, immediate: true }
) )
</script> </script>

View File

@@ -20,7 +20,8 @@ export const useSolarNetwork = () => {
console.log(`[useSolarNetwork] onRequest for ${request} on ${side}`) console.log(`[useSolarNetwork] onRequest for ${request} on ${side}`)
if (devToken) { if (devToken) {
options.headers = new Headers(options.headers) console.log("[useSolarNetwork] Using dev token...")
options.headers.delete("Cookie")
options.headers.set("Authorization", `Bearer ${devToken}`) options.headers.set("Authorization", `Bearer ${devToken}`)
} }

View File

@@ -1,7 +1,7 @@
<template> <template>
<div class="container mx-auto px-5"> <div class="container mx-auto px-5">
<div class="layout"> <div class="layout">
<div class="main"> <div class="main pt-4">
<n-infinite-scroll <n-infinite-scroll
style="overflow: auto" style="overflow: auto"
:distance="0" :distance="0"
@@ -37,7 +37,7 @@
</div> </div>
</n-infinite-scroll> </n-infinite-scroll>
</div> </div>
<div class="sidebar flex flex-col gap-3"> <div class="sidebar flex flex-col gap-3 pt-4">
<div v-if="!userStore.isAuthenticated"> <div v-if="!userStore.isAuthenticated">
<n-card> <n-card>
<h2 class="card-title">About</h2> <h2 class="card-title">About</h2>
@@ -54,11 +54,9 @@
</p> </p>
</n-card> </n-card>
</div> </div>
<div v-else class="card w-full bg-base-100 shadow-xl"> <n-card v-else class="w-full">
<div class="card-body"> <post-editor @posted="refreshActivities" />
<post-editor @posted="refreshActivities" /> </n-card>
</div>
</div>
<sidebar-footer class="max-lg:hidden" /> <sidebar-footer class="max-lg:hidden" />
</div> </div>
</div> </div>
@@ -180,7 +178,7 @@ async function refreshActivities() {
@media (min-width: 1280px) { @media (min-width: 1280px) {
.sidebar { .sidebar {
position: sticky; position: sticky;
top: calc(68px + 8px); top: calc(64px);
} }
} }
</style> </style>

View File

@@ -5,7 +5,17 @@ export default defineNuxtPlugin(() => {
console.log(`[AUTH PLUGIN] Running on ${side}`) console.log(`[AUTH PLUGIN] Running on ${side}`)
const userStore = useUserStore() const userStore = useUserStore()
// Prevent fetching if it's already in progress // Fix hydration mismatch: if isLoading is true on client, it's likely a stale state
// from SSR where the fetch didn't complete before the response was sent.
// Reset it to allow the client to fetch properly.
if (import.meta.client && userStore.isLoading) {
console.log(
`[AUTH PLUGIN] Detected stale isLoading state on ${side}. Resetting to allow fetch.`
)
userStore.isLoading = false
}
// Prevent fetching if it's already in progress (server-side only now)
if (userStore.isLoading) { if (userStore.isLoading) {
console.log( console.log(
`[AUTH PLUGIN] User fetch already in progress on ${side}. Skipping.` `[AUTH PLUGIN] User fetch already in progress on ${side}. Skipping.`
@@ -21,4 +31,3 @@ export default defineNuxtPlugin(() => {
userStore.fetchUser() userStore.fetchUser()
} }
}) })