mirror of
https://github.com/PrimalHQ/primal-web-app.git
synced 2024-10-01 17:31:13 +00:00
Remove line braks before media in a note
This commit is contained in:
parent
26a7ee66dd
commit
72974bdbd7
@ -189,6 +189,19 @@ const ParsedNote: Component<{
|
|||||||
meta?: Record<string, any>,
|
meta?: Record<string, any>,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const removeLinebreaks = () => {
|
||||||
|
if (lastSignificantContent === 'LB') {
|
||||||
|
const lastIndex = content.length - 1;
|
||||||
|
const lastGroup = content[lastIndex];
|
||||||
|
|
||||||
|
setContent(lastIndex, () => ({
|
||||||
|
type: lastGroup.type,
|
||||||
|
tokens: [],
|
||||||
|
meta: lastGroup.meta,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const [content, setContent] = createStore<NoteContent[]>([]);
|
const [content, setContent] = createStore<NoteContent[]>([]);
|
||||||
|
|
||||||
const updateContent = (contentArray: NoteContent[], type: string, token: string, meta?: Record<string, any>) => {
|
const updateContent = (contentArray: NoteContent[], type: string, token: string, meta?: Record<string, any>) => {
|
||||||
@ -248,66 +261,77 @@ const ParsedNote: Component<{
|
|||||||
|
|
||||||
if (!props.ignoreMedia) {
|
if (!props.ignoreMedia) {
|
||||||
if (isImage(token)) {
|
if (isImage(token)) {
|
||||||
|
removeLinebreaks();
|
||||||
lastSignificantContent = 'image';
|
lastSignificantContent = 'image';
|
||||||
updateContent(content, 'image', token);
|
updateContent(content, 'image', token);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isMp4Video(token)) {
|
if (isMp4Video(token)) {
|
||||||
|
removeLinebreaks();
|
||||||
lastSignificantContent = 'video';
|
lastSignificantContent = 'video';
|
||||||
updateContent(content, 'video', token, { videoType: 'video/mp4'});
|
updateContent(content, 'video', token, { videoType: 'video/mp4'});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isOggVideo(token)) {
|
if (isOggVideo(token)) {
|
||||||
|
removeLinebreaks();
|
||||||
lastSignificantContent = 'video';
|
lastSignificantContent = 'video';
|
||||||
updateContent(content, 'video', token, { videoType: 'video/ogg'});
|
updateContent(content, 'video', token, { videoType: 'video/ogg'});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isWebmVideo(token)) {
|
if (isWebmVideo(token)) {
|
||||||
|
removeLinebreaks();
|
||||||
lastSignificantContent = 'video';
|
lastSignificantContent = 'video';
|
||||||
updateContent(content, 'video', token, { videoType: 'video/webm'});
|
updateContent(content, 'video', token, { videoType: 'video/webm'});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isYouTube(token)) {
|
if (isYouTube(token)) {
|
||||||
|
removeLinebreaks();
|
||||||
lastSignificantContent = 'youtube';
|
lastSignificantContent = 'youtube';
|
||||||
updateContent(content, 'youtube', token);
|
updateContent(content, 'youtube', token);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSpotify(token)) {
|
if (isSpotify(token)) {
|
||||||
|
removeLinebreaks();
|
||||||
lastSignificantContent = 'spotify';
|
lastSignificantContent = 'spotify';
|
||||||
updateContent(content, 'spotify', token);
|
updateContent(content, 'spotify', token);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isTwitch(token)) {
|
if (isTwitch(token)) {
|
||||||
|
removeLinebreaks();
|
||||||
lastSignificantContent = 'twitch';
|
lastSignificantContent = 'twitch';
|
||||||
updateContent(content, 'twitch', token);
|
updateContent(content, 'twitch', token);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isMixCloud(token)) {
|
if (isMixCloud(token)) {
|
||||||
|
removeLinebreaks();
|
||||||
lastSignificantContent = 'mixcloud';
|
lastSignificantContent = 'mixcloud';
|
||||||
updateContent(content, 'mixcloud', token);
|
updateContent(content, 'mixcloud', token);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSoundCloud(token)) {
|
if (isSoundCloud(token)) {
|
||||||
|
removeLinebreaks();
|
||||||
lastSignificantContent = 'soundcloud';
|
lastSignificantContent = 'soundcloud';
|
||||||
updateContent(content, 'soundcloud', token);
|
updateContent(content, 'soundcloud', token);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isAppleMusic(token)) {
|
if (isAppleMusic(token)) {
|
||||||
|
removeLinebreaks();
|
||||||
lastSignificantContent = 'applemusic';
|
lastSignificantContent = 'applemusic';
|
||||||
updateContent(content, 'applemusic', token);
|
updateContent(content, 'applemusic', token);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isWavelake(token)) {
|
if (isWavelake(token)) {
|
||||||
|
removeLinebreaks();
|
||||||
lastSignificantContent = 'wavelake';
|
lastSignificantContent = 'wavelake';
|
||||||
updateContent(content, 'wavelake', token);
|
updateContent(content, 'wavelake', token);
|
||||||
return;
|
return;
|
||||||
@ -320,24 +344,14 @@ const ParsedNote: Component<{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
removeLinebreaks();
|
||||||
lastSignificantContent = 'link';
|
lastSignificantContent = 'link';
|
||||||
updateContent(content, 'link', token);
|
updateContent(content, 'link', token);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isNoteMention(token)) {
|
if (isNoteMention(token)) {
|
||||||
if (lastSignificantContent === 'LB') {
|
removeLinebreaks();
|
||||||
const lastIndex = content.length - 1;
|
|
||||||
const lastGroup = content[lastIndex];
|
|
||||||
|
|
||||||
|
|
||||||
setContent(lastIndex, () => ({
|
|
||||||
type: lastGroup.type,
|
|
||||||
tokens: lastGroup.tokens.slice(0, Math.min(1, lastGroup.tokens.length)),
|
|
||||||
meta: lastGroup.meta,
|
|
||||||
}));
|
|
||||||
|
|
||||||
}
|
|
||||||
lastSignificantContent = 'notemention';
|
lastSignificantContent = 'notemention';
|
||||||
updateContent(content, 'notemention', token);
|
updateContent(content, 'notemention', token);
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user