diff --git a/.github/workflows/notifications.yml b/.github/workflows/notifications.yml index 68aeed7f..e8603387 100644 --- a/.github/workflows/notifications.yml +++ b/.github/workflows/notifications.yml @@ -1,93 +1,93 @@ -# send notifications to telegram group on commits, releases, issues -name: notifications +# # send notifications to telegram group on commits, releases, issues +# name: notifications -on: - pull_request: - branches: - - master - push: - branches: - - master - release: - types: [published] - issues: - types: [opened] +# on: +# pull_request: +# branches: +# - master +# push: +# branches: +# - master +# release: +# types: [published] +# issues: +# types: [opened] -jobs: - push: - if: ${{ github.event_name == 'push' }} - runs-on: ubuntu-latest - strategy: - matrix: - commit: ${{ github.event.commits }} - steps: - # - name: debug - # env: - # DEBUG: ${{ toJSON(matrix.commit) }} - # run: echo "$DEBUG" +# jobs: +# push: +# if: ${{ github.event_name == 'push' }} +# runs-on: ubuntu-latest +# strategy: +# matrix: +# commit: ${{ github.event.commits }} +# steps: +# # - name: debug +# # env: +# # DEBUG: ${{ toJSON(matrix.commit) }} +# # run: echo "$DEBUG" - # write message to file - - run: echo "${{ matrix.commit.message }}" >> message.txt - - run: echo "" >> message.txt - - run: echo "by ${{ matrix.commit.author.username }}" >> message.txt - - run: echo "${{ matrix.commit.url }}" >> message.txt - - run: date -d "${{ matrix.commit.timestamp }}" +"%d/%m/%y at %H:%M" >> message.txt +# # write message to file +# - run: echo "${{ matrix.commit.message }}" >> message.txt +# - run: echo "" >> message.txt +# - run: echo "by ${{ matrix.commit.author.username }}" >> message.txt +# - run: echo "${{ matrix.commit.url }}" >> message.txt +# - run: date -d "${{ matrix.commit.timestamp }}" +"%d/%m/%y at %H:%M" >> message.txt - # send message, @plebbit telegram chat id is -1001665335693 - - name: "telegram notification" - uses: appleboy/telegram-action@master - with: - to: -1001665335693 - token: ${{ secrets.TELEGRAM_TOKEN }} - # commit links don't show anything useful in preview - disable_web_page_preview: true - format: html - message_file: message.txt +# # send message, @plebbit telegram chat id is -1001665335693 +# - name: "telegram notification" +# uses: appleboy/telegram-action@master +# with: +# to: -1001665335693 +# token: ${{ secrets.TELEGRAM_TOKEN }} +# # commit links don't show anything useful in preview +# disable_web_page_preview: true +# format: html +# message_file: message.txt - release: - if: ${{ github.event_name == 'release' }} - runs-on: ubuntu-latest - steps: - # - name: debug - # env: - # DEBUG: ${{ toJSON(github) }} - # run: echo "$DEBUG" +# release: +# if: ${{ github.event_name == 'release' }} +# runs-on: ubuntu-latest +# steps: +# # - name: debug +# # env: +# # DEBUG: ${{ toJSON(github) }} +# # run: echo "$DEBUG" - # write message to file - - run: echo "${{ github.event.repository.name }} ${{ github.event.release.name }}" >> message.txt - - run: echo "" >> message.txt - - run: echo "${{ github.event.release.body }}" >> message.txt - - run: echo "${{ github.event.release.html_url }}" >> message.txt +# # write message to file +# - run: echo "${{ github.event.repository.name }} ${{ github.event.release.name }}" >> message.txt +# - run: echo "" >> message.txt +# - run: echo "${{ github.event.release.body }}" >> message.txt +# - run: echo "${{ github.event.release.html_url }}" >> message.txt - # send message, @plebbit telegram chat id is -1001665335693 - - name: "telegram notification" - uses: appleboy/telegram-action@master - with: - to: -1001665335693 - token: ${{ secrets.TELEGRAM_TOKEN }} - format: html - message_file: message.txt +# # send message, @plebbit telegram chat id is -1001665335693 +# - name: "telegram notification" +# uses: appleboy/telegram-action@master +# with: +# to: -1001665335693 +# token: ${{ secrets.TELEGRAM_TOKEN }} +# format: html +# message_file: message.txt - issue: - if: ${{ github.event_name == 'issues' }} - runs-on: ubuntu-latest - steps: - # - name: debug - # env: - # DEBUG: ${{ toJSON(github) }} - # run: echo "$DEBUG" +# issue: +# if: ${{ github.event_name == 'issues' }} +# runs-on: ubuntu-latest +# steps: +# # - name: debug +# # env: +# # DEBUG: ${{ toJSON(github) }} +# # run: echo "$DEBUG" - # write message to file - - run: echo "${{ github.event.issue.title }}" >> message.txt - - run: echo "" >> message.txt - - run: echo "by ${{ github.event.issue.user.login }}" >> message.txt - - run: echo "${{ github.event.issue.html_url }}" >> message.txt +# # write message to file +# - run: echo "${{ github.event.issue.title }}" >> message.txt +# - run: echo "" >> message.txt +# - run: echo "by ${{ github.event.issue.user.login }}" >> message.txt +# - run: echo "${{ github.event.issue.html_url }}" >> message.txt - # send message, @plebbit telegram chat id is -1001665335693 - - name: "telegram notification" - uses: appleboy/telegram-action@master - with: - to: -1001665335693 - token: ${{ secrets.TELEGRAM_TOKEN }} - format: html - message_file: message.txt +# # send message, @plebbit telegram chat id is -1001665335693 +# - name: "telegram notification" +# uses: appleboy/telegram-action@master +# with: +# to: -1001665335693 +# token: ${{ secrets.TELEGRAM_TOKEN }} +# format: html +# message_file: message.txt diff --git a/public/translations/ar/default.json b/public/translations/ar/default.json index 8bd34974..3269ec10 100644 --- a/public/translations/ar/default.json +++ b/public/translations/ar/default.json @@ -273,5 +273,6 @@ "failed_edit": "فشل التعديل", "copy_full_address": "<1>نسخ العنوان الكامل", "node_stats": "إحصائيات العقدة", - "version": "الإصدار" + "version": "الإصدار", + "edit_reason": "سبب التعديل" } \ No newline at end of file diff --git a/public/translations/bn/default.json b/public/translations/bn/default.json index a9f716e9..646e1cf2 100644 --- a/public/translations/bn/default.json +++ b/public/translations/bn/default.json @@ -273,5 +273,6 @@ "failed_edit": "ব্যর্থ সম্পাদনা", "copy_full_address": "<1>অনুলিপি সম্পূর্ণ ঠিকানা", "node_stats": "নোড পরিসংখ্যান", - "version": "সংস্করণ" + "version": "সংস্করণ", + "edit_reason": "সম্পাদনার কারণ" } \ No newline at end of file diff --git a/public/translations/cs/default.json b/public/translations/cs/default.json index 3c938365..7abd3465 100644 --- a/public/translations/cs/default.json +++ b/public/translations/cs/default.json @@ -273,5 +273,6 @@ "failed_edit": "neúspěšná úprava", "copy_full_address": "<1>kopírovat plnou adresu", "node_stats": "statistiky uzlu", - "version": "verze" + "version": "verze", + "edit_reason": "důvod úpravy" } \ No newline at end of file diff --git a/public/translations/da/default.json b/public/translations/da/default.json index 34aa503f..d13b0f06 100644 --- a/public/translations/da/default.json +++ b/public/translations/da/default.json @@ -273,5 +273,6 @@ "failed_edit": "mislykket redigering", "copy_full_address": "<1>kopiér fuld adresse", "node_stats": "nodestatistikker", - "version": "version" + "version": "version", + "edit_reason": "redigeringsgrund" } \ No newline at end of file diff --git a/public/translations/de/default.json b/public/translations/de/default.json index 51bbe974..202940d6 100644 --- a/public/translations/de/default.json +++ b/public/translations/de/default.json @@ -273,5 +273,6 @@ "failed_edit": "fehlgeschlagene Bearbeitung", "copy_full_address": "<1>Kopieren Sie die vollständige Adresse", "node_stats": "Knotenstatistiken", - "version": "Version" + "version": "Version", + "edit_reason": "Bearbeitungsgrund" } \ No newline at end of file diff --git a/public/translations/el/default.json b/public/translations/el/default.json index 66dc8ff1..3e6f33b1 100644 --- a/public/translations/el/default.json +++ b/public/translations/el/default.json @@ -273,5 +273,6 @@ "failed_edit": "αποτυχημένη επεξεργασία", "copy_full_address": "<1>αντιγραφή πλήρους διεύθυνσης", "node_stats": "στατιστικές κόμβων", - "version": "έκδοση" + "version": "έκδοση", + "edit_reason": "λόγος επεξεργασίας" } \ No newline at end of file diff --git a/public/translations/en/default.json b/public/translations/en/default.json index d42c2fb5..9a859810 100644 --- a/public/translations/en/default.json +++ b/public/translations/en/default.json @@ -273,5 +273,6 @@ "failed_edit": "failed edit", "copy_full_address": "<1>copy full address", "node_stats": "node stats", - "version": "version" + "version": "version", + "edit_reason": "edit reason" } \ No newline at end of file diff --git a/public/translations/es/default.json b/public/translations/es/default.json index 26ba779d..fd7230ad 100644 --- a/public/translations/es/default.json +++ b/public/translations/es/default.json @@ -273,5 +273,6 @@ "failed_edit": "edición fallida", "copy_full_address": "<1>copiar la dirección completa", "node_stats": "estadísticas del nodo", - "version": "versión" + "version": "versión", + "edit_reason": "motivo de la edición" } \ No newline at end of file diff --git a/public/translations/fa/default.json b/public/translations/fa/default.json index 83903a45..a86bbcc9 100644 --- a/public/translations/fa/default.json +++ b/public/translations/fa/default.json @@ -273,5 +273,6 @@ "failed_edit": "ویرایش ناموفق", "copy_full_address": "<1>کپی آدرس کامل", "node_stats": "آمار گره", - "version": "نسخه" + "version": "نسخه", + "edit_reason": "دلیل ویرایش" } \ No newline at end of file diff --git a/public/translations/fi/default.json b/public/translations/fi/default.json index 5c23154a..bccff295 100644 --- a/public/translations/fi/default.json +++ b/public/translations/fi/default.json @@ -273,5 +273,6 @@ "failed_edit": "epäonnistunut muokkaus", "copy_full_address": "<1>kopioi koko osoite", "node_stats": "solmustatistiikka", - "version": "versio" + "version": "versio", + "edit_reason": "muokkaussyy" } \ No newline at end of file diff --git a/public/translations/fil/default.json b/public/translations/fil/default.json index 3be8e87f..0cc8c448 100644 --- a/public/translations/fil/default.json +++ b/public/translations/fil/default.json @@ -273,5 +273,6 @@ "failed_edit": "nakabigong edit", "copy_full_address": "<1>kopyahin ang buong address", "node_stats": "stats ng node", - "version": "bersyon" + "version": "bersyon", + "edit_reason": "dahilan ng pag-edit" } \ No newline at end of file diff --git a/public/translations/fr/default.json b/public/translations/fr/default.json index 54be0dde..b9ec7fc9 100644 --- a/public/translations/fr/default.json +++ b/public/translations/fr/default.json @@ -273,5 +273,6 @@ "failed_edit": "modification échouée", "copy_full_address": "<1>copier l'adresse complète", "node_stats": "statistiques du nœud", - "version": "version" + "version": "version", + "edit_reason": "motif de la modification" } \ No newline at end of file diff --git a/public/translations/he/default.json b/public/translations/he/default.json index 725d9d19..172bf1bf 100644 --- a/public/translations/he/default.json +++ b/public/translations/he/default.json @@ -273,5 +273,6 @@ "failed_edit": "עריכה נכשלה", "copy_full_address": "<1>העתק כתובת מלאה", "node_stats": "סטטיסטיקות הצומת", - "version": "גרסה" + "version": "גרסה", + "edit_reason": "סיבת העריכה" } \ No newline at end of file diff --git a/public/translations/hi/default.json b/public/translations/hi/default.json index 254e8d0d..b789522f 100644 --- a/public/translations/hi/default.json +++ b/public/translations/hi/default.json @@ -273,5 +273,6 @@ "failed_edit": "विफल संपादन", "copy_full_address": "<1>कॉपी पूरा पता", "node_stats": "नोड आंकड़े", - "version": "संस्करण" + "version": "संस्करण", + "edit_reason": "संपादन का कारण" } \ No newline at end of file diff --git a/public/translations/hu/default.json b/public/translations/hu/default.json index 1a91efab..d12c5b3e 100644 --- a/public/translations/hu/default.json +++ b/public/translations/hu/default.json @@ -273,5 +273,6 @@ "failed_edit": "sikertelen szerkesztés", "copy_full_address": "<1>másol teljes cím", "node_stats": "csomópont statisztikák", - "version": "verzió" + "version": "verzió", + "edit_reason": "szerkesztés okának" } \ No newline at end of file diff --git a/public/translations/id/default.json b/public/translations/id/default.json index f53d6389..ec9c5423 100644 --- a/public/translations/id/default.json +++ b/public/translations/id/default.json @@ -273,5 +273,6 @@ "failed_edit": "edit gagal", "copy_full_address": "<1>salin alamat lengkap", "node_stats": "statistik node", - "version": "versi" + "version": "versi", + "edit_reason": "alasan sunting" } \ No newline at end of file diff --git a/public/translations/it/default.json b/public/translations/it/default.json index 8dc19a4a..6bb22470 100644 --- a/public/translations/it/default.json +++ b/public/translations/it/default.json @@ -256,7 +256,7 @@ "settings_saved": "Impostazioni salvate per p/{{subplebbitAddress}}", "mod_edit": "modifica dei moderatori", "continue_thread": "continua questa discussione", - "mod_reason": "motivo di moderazione", + "mod_reason": "motivo della moderazione", "double_confirm": "Sei davvero sicuro? Questa azione è irreversibile.", "crypto_address_not_yours": "L'indirizzo cripto appartiene a un altro account.", "crypto_address_yours": "L'indirizzo cripto appartiene a questo account.", @@ -273,5 +273,6 @@ "failed_edit": "modifica fallita", "copy_full_address": "<1>copia l'indirizzo completo", "node_stats": "statistiche del nodo", - "version": "versione" + "version": "versione", + "edit_reason": "motivo della modifica" } \ No newline at end of file diff --git a/public/translations/ja/default.json b/public/translations/ja/default.json index ae4772c5..2ebb1355 100644 --- a/public/translations/ja/default.json +++ b/public/translations/ja/default.json @@ -273,5 +273,6 @@ "failed_edit": "失敗した編集", "copy_full_address": "<1>コピー完全な住所", "node_stats": "ノードの統計", - "version": "バージョン" + "version": "バージョン", + "edit_reason": "編集理由" } \ No newline at end of file diff --git a/public/translations/ko/default.json b/public/translations/ko/default.json index e28db937..c06db856 100644 --- a/public/translations/ko/default.json +++ b/public/translations/ko/default.json @@ -273,5 +273,6 @@ "failed_edit": "실패한 편집", "copy_full_address": "<1>복사 전체 주소", "node_stats": "노드 통계", - "version": "버전" + "version": "버전", + "edit_reason": "편집 이유" } \ No newline at end of file diff --git a/public/translations/mr/default.json b/public/translations/mr/default.json index 493df105..383f0561 100644 --- a/public/translations/mr/default.json +++ b/public/translations/mr/default.json @@ -273,5 +273,6 @@ "failed_edit": "अयशस्वी संपादन", "copy_full_address": "<1>कॉपी पूर्ण पत्ता", "node_stats": "नोड स्टॅट्स", - "version": "आवृत्ती" + "version": "आवृत्ती", + "edit_reason": "संपादनाचे कारण" } \ No newline at end of file diff --git a/public/translations/nl/default.json b/public/translations/nl/default.json index ea54c3de..b51f2066 100644 --- a/public/translations/nl/default.json +++ b/public/translations/nl/default.json @@ -273,5 +273,6 @@ "failed_edit": "mislukte bewerking", "copy_full_address": "<1>kopieer het volledige adres", "node_stats": "knoopstatistieken", - "version": "versie" + "version": "versie", + "edit_reason": "reden van bewerking" } \ No newline at end of file diff --git a/public/translations/no/default.json b/public/translations/no/default.json index 2ad5b966..de73f759 100644 --- a/public/translations/no/default.json +++ b/public/translations/no/default.json @@ -273,5 +273,6 @@ "failed_edit": "mislykket redigering", "copy_full_address": "<1>kopier full adresse", "node_stats": "nodestatistikk", - "version": "versjon" + "version": "versjon", + "edit_reason": "redigeringsgrunn" } \ No newline at end of file diff --git a/public/translations/pl/default.json b/public/translations/pl/default.json index 3eae77b4..f28f55b5 100644 --- a/public/translations/pl/default.json +++ b/public/translations/pl/default.json @@ -273,5 +273,6 @@ "failed_edit": "nieudana edycja", "copy_full_address": "<1>skopiuj pełny adres", "node_stats": "statystyki węzła", - "version": "wersja" + "version": "wersja", + "edit_reason": "powód edycji" } \ No newline at end of file diff --git a/public/translations/pt/default.json b/public/translations/pt/default.json index cb7e5bc4..f2809cdd 100644 --- a/public/translations/pt/default.json +++ b/public/translations/pt/default.json @@ -273,5 +273,6 @@ "failed_edit": "edição falhada", "copy_full_address": "<1>copiar endereço completo", "node_stats": "estatísticas do nó", - "version": "versão" + "version": "versão", + "edit_reason": "motivo da edição" } \ No newline at end of file diff --git a/public/translations/ro/default.json b/public/translations/ro/default.json index cad68b21..420bc525 100644 --- a/public/translations/ro/default.json +++ b/public/translations/ro/default.json @@ -273,5 +273,6 @@ "failed_edit": "editare eșuată", "copy_full_address": "<1>copiază adresa completă", "node_stats": "statistici de nod", - "version": "versiune" + "version": "versiune", + "edit_reason": "motivul editării" } \ No newline at end of file diff --git a/public/translations/ru/default.json b/public/translations/ru/default.json index 8e4d5ea2..cfbeac42 100644 --- a/public/translations/ru/default.json +++ b/public/translations/ru/default.json @@ -273,5 +273,6 @@ "failed_edit": "не удалось отредактировать", "copy_full_address": "<1>скопировать полный адрес", "node_stats": "статистика узла", - "version": "версия" + "version": "версия", + "edit_reason": "причина редактирования" } \ No newline at end of file diff --git a/public/translations/sq/default.json b/public/translations/sq/default.json index 243e7dbc..2e9ec413 100644 --- a/public/translations/sq/default.json +++ b/public/translations/sq/default.json @@ -273,5 +273,6 @@ "failed_edit": "ndryshimi i dështuar", "copy_full_address": "<1>kopjo adresën e plotë", "node_stats": "statistikat e nyjes", - "version": "versioni" + "version": "versioni", + "edit_reason": "arsyeja e ndryshimit" } \ No newline at end of file diff --git a/public/translations/sv/default.json b/public/translations/sv/default.json index 74bdcb7f..4707b337 100644 --- a/public/translations/sv/default.json +++ b/public/translations/sv/default.json @@ -273,5 +273,6 @@ "failed_edit": "misslyckad redigering", "copy_full_address": "<1>kopiera fullständig adress", "node_stats": "nodstatistik", - "version": "version" + "version": "version", + "edit_reason": "redigeringsorsak" } \ No newline at end of file diff --git a/public/translations/te/default.json b/public/translations/te/default.json index 6212fa73..602c71c1 100644 --- a/public/translations/te/default.json +++ b/public/translations/te/default.json @@ -273,5 +273,6 @@ "failed_edit": "విఫలమైన సవరించడం", "copy_full_address": "<1>నకలు పూర్తి చిరునామా", "node_stats": "నోడ్ స్టాటిస్టిక్స్", - "version": "వెర్షన్" + "version": "వెర్షన్", + "edit_reason": "సవరించడం యొక్క కారణం" } \ No newline at end of file diff --git a/public/translations/th/default.json b/public/translations/th/default.json index bc728494..adc1769b 100644 --- a/public/translations/th/default.json +++ b/public/translations/th/default.json @@ -273,5 +273,6 @@ "failed_edit": "การแก้ไขล้มเหลว", "copy_full_address": "<1>คัดลอก ที่อยู่เต็ม", "node_stats": "สถิติของโหนด", - "version": "เวอร์ชัน" + "version": "เวอร์ชัน", + "edit_reason": "เหตุผลในการแก้ไข" } \ No newline at end of file diff --git a/public/translations/tr/default.json b/public/translations/tr/default.json index 1d12a7a0..090ec635 100644 --- a/public/translations/tr/default.json +++ b/public/translations/tr/default.json @@ -273,5 +273,6 @@ "failed_edit": "başarısız düzenleme", "copy_full_address": "<1>kopyala tam adres", "node_stats": "düğüm istatistikleri", - "version": "sürüm" + "version": "sürüm", + "edit_reason": "düzenleme nedeni" } \ No newline at end of file diff --git a/public/translations/uk/default.json b/public/translations/uk/default.json index ba064395..908ad28a 100644 --- a/public/translations/uk/default.json +++ b/public/translations/uk/default.json @@ -273,5 +273,6 @@ "failed_edit": "невдале редагування", "copy_full_address": "<1>скопіювати повну адресу", "node_stats": "статистика вузла", - "version": "версія" + "version": "версія", + "edit_reason": "причина редагування" } \ No newline at end of file diff --git a/public/translations/ur/default.json b/public/translations/ur/default.json index 7308383b..67230942 100644 --- a/public/translations/ur/default.json +++ b/public/translations/ur/default.json @@ -273,5 +273,6 @@ "failed_edit": "ناکام ترتیبات", "copy_full_address": "<1>کاپی مکمل پتہ", "node_stats": "نوڈ اشاریہ", - "version": "ورژن" + "version": "ورژن", + "edit_reason": "ترتیب دینے کا سبب" } \ No newline at end of file diff --git a/public/translations/vi/default.json b/public/translations/vi/default.json index 333aee94..713953ed 100644 --- a/public/translations/vi/default.json +++ b/public/translations/vi/default.json @@ -273,5 +273,6 @@ "failed_edit": "chỉnh sửa thất bại", "copy_full_address": "<1>sao chép địa chỉ đầy đủ", "node_stats": "thống kê nút", - "version": "phiên bản" + "version": "phiên bản", + "edit_reason": "lý do chỉnh sửa" } \ No newline at end of file diff --git a/public/translations/zh/default.json b/public/translations/zh/default.json index 17cb1fa9..2d05a1a1 100644 --- a/public/translations/zh/default.json +++ b/public/translations/zh/default.json @@ -273,5 +273,6 @@ "failed_edit": "编辑失败", "copy_full_address": "<1>复制完整地址", "node_stats": "节点统计", - "version": "版本" + "version": "版本", + "edit_reason": "编辑原因" } \ No newline at end of file diff --git a/src/components/challenge-modal/challenge-modal.tsx b/src/components/challenge-modal/challenge-modal.tsx index 2f0f9fee..8a931e91 100644 --- a/src/components/challenge-modal/challenge-modal.tsx +++ b/src/components/challenge-modal/challenge-modal.tsx @@ -58,7 +58,9 @@ const Challenge = ({ challenge, closeModal }: ChallengeProps) => {
{t('challenge_from', { subplebbit: shortSubplebbitAddress || subplebbitAddress })}
{publicationType === 'vote' && votePreview + ' '} - {parentCid ? t('challenge_for_reply', { parentAddress, publicationContent }) : t('challenge_for_post', { publicationContent })} + {parentCid + ? t('challenge_for_reply', { parentAddress, publicationContent, interpolation: { escapeValue: false } }) + : t('challenge_for_post', { publicationContent, interpolation: { escapeValue: false } })}
{isTextChallenge &&
{challenges[currentChallengeIndex]?.challenge}
} diff --git a/src/components/edit-form/edit-form.tsx b/src/components/edit-form/edit-form.tsx index 7ffa2f40..ff3c2307 100644 --- a/src/components/edit-form/edit-form.tsx +++ b/src/components/edit-form/edit-form.tsx @@ -1,39 +1,84 @@ import { useEffect, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { PublishCommentEditOptions, useComment, usePublishCommentEdit } from '@plebbit/plebbit-react-hooks'; +import { PublishCommentEditOptions, usePublishCommentEdit } from '@plebbit/plebbit-react-hooks'; import { FormattingHelpTable } from '../reply-form'; import styles from '../reply-form/reply-form.module.css'; import { alertChallengeVerificationFailed } from '../../lib/utils/challenge-utils'; import challengesStore from '../../hooks/use-challenges'; +import { create } from 'zustand'; + +type EditStoreState = { + commentCid: string | undefined; + content: string | undefined; + reason: string | undefined; + spoiler: boolean | undefined; + subplebbitAddress: string | undefined; + publishCommentEditOptions: PublishCommentEditOptions; + setEditStore: (data: Partial) => void; + resetEditStore: () => void; +}; const { addChallenge } = challengesStore.getState(); +const useEditStore = create((set) => ({ + commentCid: undefined, + content: undefined, + reason: undefined, + spoiler: undefined, + subplebbitAddress: undefined, + publishCommentEditOptions: {}, + setEditStore: ({ commentCid, content, reason, spoiler, subplebbitAddress }) => + set((state) => { + const nextState = { ...state }; + if (commentCid !== undefined) nextState.commentCid = commentCid; + if (content !== undefined) nextState.content = content; + if (reason !== undefined) nextState.reason = reason; + if (spoiler !== undefined) nextState.spoiler = spoiler; + if (subplebbitAddress !== undefined) nextState.subplebbitAddress = subplebbitAddress; + + nextState.publishCommentEditOptions = { + ...nextState, + onChallenge: (...args: any) => addChallenge(args), + onChallengeVerification: alertChallengeVerificationFailed, + onError: (error: Error) => { + console.error(error); + let errorMessage = error.message; + alert(errorMessage); + }, + }; + return nextState; + }), + resetEditStore: () => + set({ commentCid: undefined, content: undefined, reason: undefined, spoiler: undefined, subplebbitAddress: undefined, publishCommentEditOptions: {} }), +})); + interface EditFormProps { commentCid: string; content: string; hideEditForm?: () => void; + spoiler?: boolean; subplebbitAddress: string; } -const EditForm = ({ commentCid, content, hideEditForm, subplebbitAddress }: EditFormProps) => { +const EditForm = ({ commentCid, content, hideEditForm, spoiler = false, subplebbitAddress }: EditFormProps) => { const { t } = useTranslation(); - const textRef = useRef(null); + const [showOptions, setShowOptions] = useState(false); const [showFormattingHelp, setShowFormattingHelp] = useState(false); - const [text, setText] = useState(content); + const spoilerClass = showOptions ? styles.spoilerVisible : styles.spoilerHidden; + + const textRef = useRef(null); + + const { setEditStore, resetEditStore, publishCommentEditOptions } = useEditStore(); - const comment = useComment({ commentCid }); + // initial values + useEffect(() => { + setEditStore({ commentCid, content, spoiler, subplebbitAddress }); + return () => { + // cleanup + resetEditStore(); + }; + }, [commentCid, content, spoiler, subplebbitAddress, resetEditStore, setEditStore]); - const publishCommentEditOptions: PublishCommentEditOptions = { - commentCid, - content: text, - subplebbitAddress, - onChallenge: (...args: any) => addChallenge([...args, comment]), - onChallengeVerification: alertChallengeVerificationFailed, - onError: (error: Error) => { - console.warn(error); - alert(error.message); - }, - }; const { publishCommentEdit } = usePublishCommentEdit(publishCommentEditOptions); useEffect(() => { @@ -45,29 +90,50 @@ const EditForm = ({ commentCid, content, hideEditForm, subplebbitAddress }: Edit return (
-