Skip to content

Commit

Permalink
Add Autocomplete for hashtags + mentions
Browse files Browse the repository at this point in the history
  • Loading branch information
dansup committed Mar 2, 2021
1 parent 77e1115 commit de514f7
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 55 deletions.
43 changes: 40 additions & 3 deletions resources/assets/js/components/ComposeModal.vue
Expand Up @@ -295,7 +295,9 @@
<div class="media-body">
<div class="form-group">
<label class="font-weight-bold text-muted small d-none">Caption</label>
<textarea class="form-control border-0 rounded-0 no-focus" rows="3" placeholder="Write a caption..." style="" v-model="composeText" v-on:keyup="composeTextLength = composeText.length"></textarea>
<vue-tribute :options="tributeSettings">
<textarea class="form-control border-0 rounded-0 no-focus" rows="3" placeholder="Write a caption..." style="" v-model="composeText" v-on:keyup="composeTextLength = composeText.length"></textarea>
</vue-tribute>
<p class="help-text small text-right text-muted mb-0">{{composeTextLength}}/{{config.uploader.max_caption_length}}</p>
</div>
</div>
Expand Down Expand Up @@ -647,11 +649,14 @@ import VueCropper from 'vue-cropperjs';
import 'cropperjs/dist/cropper.css';
import Autocomplete from '@trevoreyre/autocomplete-vue'
import '@trevoreyre/autocomplete-vue/dist/style.css'
import VueTribute from 'vue-tribute'
export default {
components: {
VueCropper,
Autocomplete
Autocomplete,
VueTribute
},
data() {
Expand Down Expand Up @@ -707,7 +712,39 @@ export default {
cameraRollMedia: [],
taggedUsernames: [],
taggedPeopleSearch: null,
textMode: false
textMode: false,
tributeSettings: {
collection: [
{
trigger: '@',
menuShowMinLength: 2,
values: (function (text, cb) {
let url = '/api/compose/v0/search/mention';
axios.get(url, { params: { q: text }})
.then(res => {
cb(res.data);
})
.catch(err => {
console.log(err);
})
})
},
{
trigger: '#',
menuShowMinLength: 2,
values: (function (text, cb) {
let url = '/api/compose/v0/search/hashtag';
axios.get(url, { params: { q: text }})
.then(res => {
cb(res.data);
})
.catch(err => {
console.log(err);
})
})
}
]
}
}
},
Expand Down
45 changes: 43 additions & 2 deletions resources/assets/js/components/PostComponent.vue
Expand Up @@ -643,8 +643,10 @@
size="md"
body-class="p-2 rounded">
<div>
<textarea class="form-control" rows="4" style="border: none; font-size: 18px; resize: none; white-space: pre-wrap;outline: none;" placeholder="Reply here ..." v-model="replyText">
</textarea>
<vue-tribute :options="tributeSettings">
<textarea class="form-control" rows="4" style="border: none; font-size: 18px; resize: none; white-space: pre-wrap;outline: none;" placeholder="Reply here ..." v-model="replyText">
</textarea>
</vue-tribute>

<div class="border-top border-bottom my-2">
<ul class="nav align-items-center emoji-reactions" style="overflow-x: scroll;flex-wrap: unset;">
Expand Down Expand Up @@ -757,10 +759,12 @@
</style>

<script>
import VueTribute from 'vue-tribute'
pixelfed.postComponent = {};
export default {
props: [
'status-id',
'status-username',
Expand All @@ -771,6 +775,11 @@ export default {
'status-profile-id',
'profile-layout'
],
components: {
VueTribute
},
data() {
return {
config: window.App.config,
Expand Down Expand Up @@ -817,6 +826,38 @@ export default {
profileMorePosts: [],
replySending: false,
reactionBarLoading: true,
tributeSettings: {
collection: [
{
trigger: '@',
menuShowMinLength: 2,
values: (function (text, cb) {
let url = '/api/compose/v0/search/mention';
axios.get(url, { params: { q: text }})
.then(res => {
cb(res.data);
})
.catch(err => {
console.log(err);
})
})
},
{
trigger: '#',
menuShowMinLength: 2,
values: (function (text, cb) {
let url = '/api/compose/v0/search/hashtag';
axios.get(url, { params: { q: text }})
.then(res => {
cb(res.data);
})
.catch(err => {
console.log(err);
})
})
}
]
}
}
},
watch: {
Expand Down
49 changes: 0 additions & 49 deletions resources/assets/js/components/Timeline.vue
Expand Up @@ -2224,52 +2224,3 @@
box-shadow: none;
}
</style>
<style type="text/css">
.tribute-container {
position: absolute;
top: 0;
left: 0;
height: auto;
max-height: 300px;
min-width: 120px;
max-width: 100vw;
overflow: auto;
display: block;
z-index: 999999;
border: 1px solid #ccc;
border-radius: 4px;
box-shadow: 0 1px 4px rgba(#000, 0.13);
}
.tribute-container ul {
margin: 0;
margin-top: 2px;
padding: 0;
list-style: none;
background: #fff;
border-radius: 4px;
border: 1px solid rgba(#000, 0.13);
background-clip: padding-box;
overflow: hidden;
}
.tribute-container li {
color: #000;
padding: 5px 15px;
cursor: pointer;
font-size: 14px;
overflow-x: hidden !important;
}
.tribute-container li.highlight,
.tribute-container li:hover {
background: #2c78bf;
color: #fff;
}
.tribute-container li span {
font-weight: bold;
}
.tribute-container li.no-match {
cursor: default;
}
.tribute-container .menu-highlighted {
font-weight: bold;
}
</style>
56 changes: 55 additions & 1 deletion resources/assets/sass/custom.scss
Expand Up @@ -594,4 +594,58 @@ details summary::-webkit-details-marker {
width: 100%;
height: 100%;
}
}
}

.tribute-container {
position: absolute;
top: 0;
left: 0;
height: auto;
max-height: 300px;
min-width: 120px;
max-width: 100vw;
overflow: auto;
display: block;
z-index: 999999;
border: 1px solid #ccc;
border-radius: 4px;
box-shadow: 0 1px 4px rgba(#000, 0.13);
}

.tribute-container ul {
margin: 0;
margin-top: 2px;
padding: 0;
list-style: none;
background: #fff;
border-radius: 4px;
border: 1px solid rgba(#000, 0.13);
background-clip: padding-box;
overflow: hidden;
}

.tribute-container li {
color: #000;
padding: 5px 15px;
cursor: pointer;
font-size: 14px;
overflow-x: hidden !important;
}

.tribute-container li.highlight,
.tribute-container li:hover {
background: #2c78bf;
color: #fff;
}

.tribute-container li span {
font-weight: bold;
}

.tribute-container li.no-match {
cursor: default;
}

.tribute-container .menu-highlighted {
font-weight: bold;
}

0 comments on commit de514f7

Please sign in to comment.