Skip to content

Commit 0c355ef

Browse files
committed
feat: implement thread creation with slugify
1 parent d1a483a commit 0c355ef

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/views/Threads.vue

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@
214214
<pagination v-if="threadData.data?.board" :page="threadData.data.page" :limit="threadData.data.limit" :count="threadData.data.board.thread_count"></pagination>
215215
</div>
216216
<set-moderators-modal v-if="threadData.data?.board" :board="threadData.data.board" :show="showSetModerators" @close="showSetModerators = false"></set-moderators-modal>
217-
<editor :showEditor="showEditor" @close="showEditor = false" threadEditorMode="true" :thread="{ title: '' }" />
217+
<editor v-if="threadData.data?.board" :showEditor="showEditor" @close="showEditor = false" threadEditorMode="true" :thread="{ title: '', board_id: threadData?.data?.board.id }" :createAction="createThread" />
218218
</template>
219219

220220
<script>
@@ -231,6 +231,7 @@ import { PreferencesStore, localStoragePrefs } from '@/composables/stores/prefs'
231231
import { processThreads } from '@/composables/utils/boardUtils'
232232
import BanStore from '@/composables/stores/ban'
233233
import Editor from '@/components/layout/Editor.vue'
234+
import slugify from 'slugify'
234235
235236
export default {
236237
name: 'Threads',
@@ -345,6 +346,16 @@ export default {
345346
return v.threadData.data?.write_access && v.permissionUtils.hasPermission('threads.create.allow')
346347
}
347348
349+
const createThread = thread => {
350+
// slugify title
351+
let slug = slugify(slugify(thread.title, { remove: /[*'"~!@)(+.:]/g, lower: true }))
352+
// Handles slugs of foreign languages, these will get a random hash for their slug
353+
if (slug === '') slug = Math.random().toString(36).substring(6)
354+
thread.slug = slug
355+
return threadsApi.create(thread)
356+
.then(getThreads)
357+
.then(data => v.threadData.data = data)
358+
}
348359
/* Internal Data */
349360
const $route = useRoute()
350361
const $router = useRouter()

0 commit comments

Comments
 (0)