diff --git a/src/assets/images/reactions/light/incognito.webp b/src/assets/images/reactions/light/incognito.webp deleted file mode 100644 index 3e7ffec4e..000000000 Binary files a/src/assets/images/reactions/light/incognito.webp and /dev/null differ diff --git a/src/backend/comment.ts b/src/backend/comment.ts index 8b20087f8..541a62799 100644 --- a/src/backend/comment.ts +++ b/src/backend/comment.ts @@ -3,10 +3,11 @@ import ipfs from '@capsulesocial/ipfs-wrapper' import { nodeUrl } from './utilities/config' import libsodium from './utilities/keys' import { ISignedIPFSObject, uint8ArrayToHexString } from './utilities/helpers' +import { EmotionCategories, Emotions } from '@/config/config' export interface INewCommentData { content: string - emotion: string + emotion: Emotions timestamp: number parentCID: string authorID: string @@ -17,7 +18,7 @@ export interface ICommentData { _id: string timestamp: number parentCID: string - emotion: string + emotion: Emotions } export interface ICommentsStats { @@ -25,10 +26,15 @@ export interface ICommentsStats { positive: number neutral: number negative: number - faceStats: Record + faceStats: Record | null } -export function createComment(authorID: string, content: string, emotion: string, parentCID: string): INewCommentData { +export function createComment( + authorID: string, + content: string, + emotion: Emotions, + parentCID: string, +): INewCommentData { return { authorID, content, @@ -73,8 +79,8 @@ export async function getCommentsOfPost( parentCID: string, offset: number, limit: number, - emotion?: string, - emotionCategory?: `negative` | `neutral` | `positive`, + emotion?: Emotions, + emotionCategory?: EmotionCategories, ): Promise { const res = await axios.get(`${nodeUrl()}/content/${parentCID}/comments`, { params: { ...(emotion ? { emotion } : {}), ...(emotionCategory ? { emotionCategory } : {}), offset, limit }, diff --git a/src/components/post/Actions.vue b/src/components/post/Actions.vue index 565f9cc81..646f3a004 100644 --- a/src/components/post/Actions.vue +++ b/src/components/post/Actions.vue @@ -187,7 +187,7 @@ @click=" showEmotions = false selectedEmotionColor = `neutralLightest` - selectedEmotion = { label: ``, light: null, dark: null } + selectedEmotion = null " > @@ -223,7 +223,7 @@ : (selectedEmotionColor === `positive` || selectedEmotionColor === `neutral` || selectedEmotionColor === `negative`) && - selectedEmotion.label !== `` + selectedEmotion ? `border p-2 bg-` + selectedEmotionColor : `p-2 bg-lightBG dark:bg-darkBG` " @@ -236,7 +236,7 @@
@@ -323,7 +323,7 @@ :key="face.label" class="focus:outline-none outline-none rounded-lg border-2" :class=" - selectedEmotion.label === face.label ? `border-` + selectedEmotionColor : `border-transparent` + selectedEmotion?.label === face.label ? `border-` + selectedEmotionColor : `border-transparent` " style="transition: all 0.3s ease-in-out" @click="setEmotion($event, face)" @@ -337,7 +337,7 @@

feelingList: { negative: Set; positive: Set; neutral: Set } - activeEmotion: IFace - selectedEmotion: IFace + activeEmotion: IFaceWithoutDefault | null + selectedEmotion: IFaceWithoutDefault | null comments: ICommentData[] avatar: string comment: string - emotion: string + emotion: Emotions | null showEmotions: boolean filter: string showDropdown: boolean @@ -476,7 +476,7 @@ interface IData { userIsFollowed: boolean faceStats: FaceStat[] page: number - selectedEmotionColor: `positive` | `neutral` | `negative` | `neutralLightest` + selectedEmotionColor: EmotionCategories | `neutralLightest` sendingComment: boolean currentCommentsOffset: number commentsLimit: number @@ -525,13 +525,13 @@ export default Vue.extend({ data(): IData { return { faceGroupings, - feelingList: feelings, + feelingList: emotionCategories, avatar: ``, - activeEmotion: { label: ``, light: null, dark: null }, - selectedEmotion: { label: ``, light: null, dark: null }, + activeEmotion: null, + selectedEmotion: null, comment: ``, comments: [], - emotion: ``, + emotion: null, showEmotions: false, filter: ``, showDropdown: false, @@ -555,7 +555,7 @@ export default Vue.extend({ positive: 0, neutral: 0, negative: 0, - faceStats: {}, + faceStats: null, }, } }, @@ -608,7 +608,7 @@ export default Vue.extend({ continue } const f = faces[face] - stats[f.label] = { face: f, count: faceStats[face] } + stats[f.label] = { face: f, count: faceStats[face as Emotions] } } this.faceStats = sortBy(Object.values(stats), `count`) }, @@ -631,18 +631,18 @@ export default Vue.extend({ this.addScrollHandler() this.filterComments() }, - setEmotion(e: PointerEvent, r: { label: string; light: any; dark: any }) { + setEmotion(e: PointerEvent, r: IFaceWithoutDefault) { if (!e.target) { return } const target = e.target as HTMLElement target.scrollIntoView({ behavior: `smooth`, block: `center` }) this.selectedEmotion = r - if (feelings.positive.has(r.label)) { + if (emotionCategories.positive.has(r.label)) { this.selectedEmotionColor = `positive` return } - if (feelings.negative.has(r.label)) { + if (emotionCategories.negative.has(r.label)) { this.selectedEmotionColor = `negative` return } @@ -650,7 +650,7 @@ export default Vue.extend({ this.selectedEmotionColor = `neutral` }, confirmEmotion() { - if (this.selectedEmotion.label === ``) { + if (!this.selectedEmotion) { this.$toastWarning(`No face selected!`) return } @@ -658,7 +658,7 @@ export default Vue.extend({ this.showEmotions = false }, async sendComment() { - if (this.activeEmotion.label === ``) { + if (!this.activeEmotion) { this.$toastError(`You must select a reaction before posting`) return } @@ -679,9 +679,9 @@ export default Vue.extend({ const _id = await sendComment(c, `comment`) this.comments.unshift({ _id, ...c }) this.comment = `` - this.selectedEmotion = { label: ``, light: null, dark: null } - this.activeEmotion = { label: ``, light: null, dark: null } - this.emotion = `` + this.selectedEmotion = null + this.activeEmotion = null + this.emotion = null this.filter = `` this.selectedEmotionColor = `neutralLightest` this.updateCommentsStats() @@ -716,7 +716,7 @@ export default Vue.extend({ this.postCID, this.currentCommentsOffset, this.commentsLimit, - this.filter.charAt(0).toLowerCase() + this.filter.replace(/\s/g, ``).substring(1), + (this.filter.charAt(0).toLowerCase() + this.filter.replace(/\s/g, ``).substring(1)) as Emotions, ) } } catch (err) { @@ -732,11 +732,11 @@ export default Vue.extend({ } } }, - getStyle(emotionType: string): string { - if (feelings.positive.has(emotionType)) { + getStyle(emotionType: Emotions): string { + if (emotionCategories.positive.has(emotionType)) { return `positive` } - if (feelings.negative.has(emotionType)) { + if (emotionCategories.negative.has(emotionType)) { return `negative` } diff --git a/src/components/post/Comment.vue b/src/components/post/Comment.vue index 2342dc716..439c9554b 100644 --- a/src/components/post/Comment.vue +++ b/src/components/post/Comment.vue @@ -186,7 +186,7 @@ import More from '@/components/icons/More.vue' import BinIcon from '@/components/icons/Bin.vue' import { createDefaultProfile, getProfile, Profile } from '@/backend/profile' -import { feelings } from '@/config/config' +import { emotionCategories, Emotions } from '@/config/config' import { faces, IFace } from '@/config/faces' import { createComment, getComment, getCommentsOfPost, ICommentData, sendComment } from '@/backend/comment' import { getPhotoFromIPFS } from '@/backend/getPhoto' @@ -200,7 +200,7 @@ interface IData { avatar: string name: string emotion: IFace - emotionType: string + emotionType: Emotions | null content: string showLabel: boolean commentDeleted: boolean @@ -237,7 +237,7 @@ export default Vue.extend({ avatar: ``, name: ``, emotion: faces.default, - emotionType: ``, + emotionType: null, content: ``, showLabel: false, commentDeleted: false, @@ -296,9 +296,12 @@ export default Vue.extend({ } else if (prefix === `bg-`) { res = `background-color: ` } - if (feelings.positive.has(this.emotionType)) { + if (!this.emotionType) { + return (res += `#F0B785`) + } + if (emotionCategories.positive.has(this.emotionType)) { res += `#1F7DAD` - } else if (feelings.negative.has(this.emotionType)) { + } else if (emotionCategories.negative.has(this.emotionType)) { res += `#EE1F63` } else { res += `#F0B785` diff --git a/src/components/post/CommentFilter.vue b/src/components/post/CommentFilter.vue index d3229d75f..c73c981b1 100644 --- a/src/components/post/CommentFilter.vue +++ b/src/components/post/CommentFilter.vue @@ -75,13 +75,13 @@ import Vue from 'vue' import ChevronUp from '@/components/icons/ChevronUp.vue' import ChevronDown from '@/components/icons/ChevronDown.vue' -import { feelings } from '@/config/config' +import { emotionCategories, EmotionCategories } from '@/config/config' import { faces, IFace } from '@/config/faces' interface IData { reactionList: Record - feelingList: { positive: Set; negative: Set; neutral: Set } - feeling: `positive` | `negative` | `neutral` + feelingList: typeof emotionCategories + feeling: EmotionCategories showFilter: boolean } @@ -100,7 +100,7 @@ export default Vue.extend({ data(): IData { return { reactionList: faces, - feelingList: feelings, + feelingList: emotionCategories, feeling: `positive`, showFilter: false, } @@ -124,7 +124,7 @@ export default Vue.extend({ this.showFilter = true } }, - setCommentFilterFeeling(feeling: `positive` | `negative` | `neutral`) { + setCommentFilterFeeling(feeling: EmotionCategories) { this.feeling = feeling this.$emit(`clicked`, feeling) this.showFilter = true diff --git a/src/config/config.ts b/src/config/config.ts index 77725b9e8..7c69be0b0 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -1,70 +1,141 @@ -export const feelings = { - positive: new Set([ - `curious`, - `informed`, - `enlighten`, - `glad`, - `happy`, - `excited`, - `confident`, - `brave`, - `fearless`, - `enthusiastic`, - `lol`, - `guffaw`, - `intrigued`, - `interested`, - `committed`, - `proud`, - `admiration`, - `awe`, - `determined`, - `defiant`, - `on_it`, - ]), - negative: new Set([ - `distracted`, - `bored`, - `spiritless`, - `triggered`, - `shocked`, - `furious`, - `disgusted`, - `sick`, - `revolted`, - `suspicious`, - `incredulous`, - `skeptical`, - `hesitant`, - `fearful`, - `terrified`, - `aloof`, - `indifferent`, - `detached`, - `sad`, - `whine`, - `heartbroken`, - `cringe`, - `offended`, - `hateful`, - ]), - neutral: new Set([ - `empathy`, - `friendly`, - `lovely`, - `calm`, - `satisfied`, - `fulfilled`, - `mad`, - `hostile`, - `violent`, - `hush`, - `wild`, - `zzz`, - `regret`, - `spunky`, - `trippy`, - ]), +export type EmotionCategories = `positive` | `negative` | `neutral` + +export type Emotions = + | `curious` + | `informed` + | `enlighten` + | `glad` + | `happy` + | `excited` + | `confident` + | `brave` + | `fearless` + | `enthusiastic` + | `lol` + | `guffaw` + | `intrigued` + | `interested` + | `committed` + | `proud` + | `admiration` + | `awe` + | `determined` + | `defiant` + | `on_it` + | `distracted` + | `bored` + | `spiritless` + | `triggered` + | `shocked` + | `furious` + | `disgusted` + | `sick` + | `revolted` + | `suspicious` + | `incredulous` + | `skeptical` + | `hesitant` + | `fearful` + | `terrified` + | `aloof` + | `indifferent` + | `detached` + | `sad` + | `whine` + | `heartbroken` + | `cringe` + | `offended` + | `hateful` + | `empathy` + | `friendly` + | `lovely` + | `calm` + | `satisfied` + | `fulfilled` + | `mad` + | `hostile` + | `violent` + | `hush` + | `wild` + | `zzz` + | `regret` + | `spunky` + | `trippy` + | `no-emotion` + +const positiveEmotions: Array = [ + `curious`, + `informed`, + `enlighten`, + `glad`, + `happy`, + `excited`, + `confident`, + `brave`, + `fearless`, + `enthusiastic`, + `lol`, + `guffaw`, + `intrigued`, + `interested`, + `committed`, + `proud`, + `admiration`, + `awe`, + `determined`, + `defiant`, + `on_it`, +] + +const negativeEmotions: Array = [ + `distracted`, + `bored`, + `spiritless`, + `triggered`, + `shocked`, + `furious`, + `disgusted`, + `sick`, + `revolted`, + `suspicious`, + `incredulous`, + `skeptical`, + `hesitant`, + `fearful`, + `terrified`, + `aloof`, + `indifferent`, + `detached`, + `sad`, + `whine`, + `heartbroken`, + `cringe`, + `offended`, + `hateful`, +] + +const neutralEmotions: Array = [ + `empathy`, + `friendly`, + `lovely`, + `calm`, + `satisfied`, + `fulfilled`, + `mad`, + `hostile`, + `violent`, + `hush`, + `wild`, + `zzz`, + `regret`, + `spunky`, + `trippy`, +] + +export const emotionCategories: Record> = { + positive: new Set(positiveEmotions), + negative: new Set(negativeEmotions), + neutral: new Set(neutralEmotions), } export const categories = [ diff --git a/src/config/faces.ts b/src/config/faces.ts index cdf776bd4..bd5cb3e7f 100644 --- a/src/config/faces.ts +++ b/src/config/faces.ts @@ -1,10 +1,16 @@ +import { Emotions } from './config' + export interface IFace { - label: string + label: Exclude | `default` light: any dark: any } -export const faces: { [key: string]: IFace } = { +export interface IFaceWithoutDefault extends IFace { + label: Exclude +} + +export const faces: Record = { default: { label: `default`, light: require(`@/assets/images/reactions/light/confident.webp`), @@ -170,11 +176,6 @@ export const faces: { [key: string]: IFace } = { light: require(`@/assets/images/reactions/light/hush.webp`), dark: require(`@/assets/images/reactions/dark/hush.webp`), }, - incognito: { - label: `incognito`, - light: require(`@/assets/images/reactions/light/incognito.webp`), - dark: require(`@/assets/images/reactions/dark/incognito.webp`), - }, incredulous: { label: `incredulous`, light: require(`@/assets/images/reactions/light/incredulous.webp`), diff --git a/src/interfaces/Comment.ts b/src/interfaces/Comment.ts index 69e612412..389c54600 100644 --- a/src/interfaces/Comment.ts +++ b/src/interfaces/Comment.ts @@ -1,8 +1,9 @@ +import { Emotions } from '../config/config' export interface Comment { authorID: string authorAvatarCID: string content: string - emotion: string + emotion: Emotions timestamp: Date replies: any[] }