Skip to content

Commit

Permalink
img preview before post submit
Browse files Browse the repository at this point in the history
  • Loading branch information
tempe-techie committed Mar 24, 2024
1 parent 3cd0901 commit efc2547
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
11 changes: 10 additions & 1 deletion components/chat/ChatFeed.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@
</div>

</div>

<div class="d-flex mt-2 row">
<img
v-for="(imgLink, index) in getAllImagesFromText(postText)"
:src="imgLink"
:key="index"
class="img-fluid img-thumbnail m-1 col-2"
/>
</div>
</div>
</div>

Expand Down Expand Up @@ -124,7 +133,7 @@ import SwitchChainButton from "~/components/SwitchChainButton.vue";
import TenorGifSearch from "~/components/tenor/TenorGifSearch.vue";
import TenorStickerSearch from "~/components/tenor/TenorStickerSearch.vue";
import FileUploadModal from "~/components/storage/FileUploadModal.vue";
import { getAllImagesFromText } from "~/utils/textUtils";
import EmojiPicker from '~/components/EmojiPicker.vue'
import 'emoji-mart-vue-fast/css/emoji-mart.css'
Expand Down
19 changes: 19 additions & 0 deletions utils/textUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,26 @@ export function findFirstUrl(text) {
return null;
}

export function getAllImagesFromText(text) {
if (!text) { return [] };

// find multiple image links in the text and return them as an array
let imageRegex = /(https?:\/\/.*\.(?:png|jpg|jpeg|gif|webp))/gi;
let imageLinks = text.match(imageRegex);

if (!imageLinks) {
imageRegex = /(http|https|ipfs):\/\/\S+\?.img/g;
imageLinks = text.match(imageRegex);
}

if (!imageLinks) { return [] };

return imageLinks;
}

export function getImageFromText(text) {
if (!text) { return null };

let imageRegex = /(https?:\/\/.*\.(?:png|jpg|jpeg|gif|webp))/i;
let imageLinks = text.match(imageRegex);

Expand Down

0 comments on commit efc2547

Please sign in to comment.