post_status_form.vue 11.9 KB
Newer Older
lain's avatar
lain committed
1
<template>
HJ's avatar
eslint  
HJ committed
2 3 4
  <div
    ref="root"
    class="post-status-form"
5
  >
HJ's avatar
HJ committed
6 7 8 9 10 11 12 13 14 15
    <form
      autocomplete="off"
      @submit.prevent="postStatus(newStatus)"
    >
      <div class="form-group">
        <i18n
          v-if="!$store.state.users.currentUser.locked && newStatus.visibility == 'private'"
          path="post_status.account_not_locked_warning"
          tag="p"
          class="visibility-notice"
16
        >
HJ's avatar
HJ committed
17 18 19 20 21 22 23
          <router-link :to="{ name: 'user-settings' }">
            {{ $t('post_status.account_not_locked_warning_link') }}
          </router-link>
        </i18n>
        <p
          v-if="!hideScopeNotice && newStatus.visibility === 'public'"
          class="visibility-notice notice-dismissible"
24
        >
HJ's avatar
HJ committed
25 26 27 28 29 30 31 32 33 34 35
          <span>{{ $t('post_status.scope_notice.public') }}</span>
          <a
            class="button-icon dismiss"
            @click.prevent="dismissScopeNotice()"
          >
            <i class="icon-cancel" />
          </a>
        </p>
        <p
          v-else-if="!hideScopeNotice && newStatus.visibility === 'unlisted'"
          class="visibility-notice notice-dismissible"
36
        >
HJ's avatar
HJ committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
          <span>{{ $t('post_status.scope_notice.unlisted') }}</span>
          <a
            class="button-icon dismiss"
            @click.prevent="dismissScopeNotice()"
          >
            <i class="icon-cancel" />
          </a>
        </p>
        <p
          v-else-if="!hideScopeNotice && newStatus.visibility === 'private' && $store.state.users.currentUser.locked"
          class="visibility-notice notice-dismissible"
        >
          <span>{{ $t('post_status.scope_notice.private') }}</span>
          <a
            class="button-icon dismiss"
            @click.prevent="dismissScopeNotice()"
          >
            <i class="icon-cancel" />
          </a>
        </p>
57
        <p
HJ's avatar
HJ committed
58 59
          v-else-if="newStatus.visibility === 'direct'"
          class="visibility-notice"
60
        >
HJ's avatar
HJ committed
61 62
          <span v-if="safeDMEnabled">{{ $t('post_status.direct_warning_to_first_only') }}</span>
          <span v-else>{{ $t('post_status.direct_warning_to_all') }}</span>
63
        </p>
HJ's avatar
HJ committed
64 65 66
        <EmojiInput
          v-if="newStatus.spoilerText || alwaysShowSubject"
          v-model="newStatus.spoilerText"
HJ's avatar
HJ committed
67
          enable-emoji-picker
HJ's avatar
HJ committed
68 69 70 71 72 73 74 75 76 77 78 79
          :suggest="emojiSuggestor"
          class="form-control"
        >
          <input

            v-model="newStatus.spoilerText"
            type="text"
            :placeholder="$t('post_status.content_warning')"
            class="form-post-subject"
          >
        </EmojiInput>
        <EmojiInput
80
          ref="emoji-input"
HJ's avatar
HJ committed
81 82 83
          v-model="newStatus.status"
          :suggest="emojiUserSuggestor"
          class="form-control main-input"
HJ's avatar
HJ committed
84 85 86
          enable-emoji-picker
          hide-emoji-button
          enable-sticker-picker
87
          @input="onEmojiInputInput"
88 89
          @sticker-uploaded="addMediaFile"
          @sticker-upload-failed="uploadFailed"
HJ's avatar
HJ committed
90 91 92 93 94 95 96 97 98 99 100 101
        >
          <textarea
            ref="textarea"
            v-model="newStatus.status"
            :placeholder="$t('post_status.default')"
            rows="1"
            :disabled="posting"
            class="form-post-body"
            @keydown.meta.enter="postStatus(newStatus)"
            @keyup.ctrl.enter="postStatus(newStatus)"
            @drop="fileDrop"
            @dragover.prevent="fileDrag"
HJ's avatar
HJ committed
102
            @input="resize"
103
            @compositionupdate="resize"
HJ's avatar
HJ committed
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
            @paste="paste"
          />
          <p
            v-if="hasStatusLengthLimit"
            class="character-counter faint"
            :class="{ error: isOverLengthLimit }"
          >
            {{ charactersLeft }}
          </p>
        </EmojiInput>
        <div class="visibility-tray">
          <scope-selector
            :show-all="showAllScopes"
            :user-default="userDefaultScope"
            :original-scope="copyMessageScope"
            :initial-scope="newStatus.visibility"
            :on-scope-change="changeVis"
          />

          <div
            v-if="postFormats.length > 1"
            class="text-format"
          >
            <label
              for="post-content-type"
              class="select"
            >
              <select
                id="post-content-type"
                v-model="newStatus.contentType"
                class="form-control"
              >
                <option
                  v-for="postFormat in postFormats"
                  :key="postFormat"
                  :value="postFormat"
                >
                  {{ $t(`post_status.content_type["${postFormat}"]`) }}
                </option>
              </select>
              <i class="icon-down-open" />
            </label>
          </div>
147
          <div
HJ's avatar
HJ committed
148 149
            v-if="postFormats.length === 1 && postFormats[0] !== 'text/plain'"
            class="text-format"
150
          >
HJ's avatar
HJ committed
151 152 153
            <span class="only-format">
              {{ $t(`post_status.content_type["${postFormats[0]}"]`) }}
            </span>
154 155
          </div>
        </div>
lain's avatar
lain committed
156
      </div>
HJ's avatar
HJ committed
157 158 159 160 161 162 163 164 165 166
      <poll-form
        v-if="pollsAvailable"
        ref="pollForm"
        :visible="pollFormVisible"
        @update-poll="setPoll"
      />
      <div class="form-bottom">
        <div class="form-bottom-left">
          <media-upload
            ref="mediaUpload"
167
            class="media-upload-icon"
HJ's avatar
HJ committed
168 169 170 171 172
            :drop-files="dropFiles"
            @uploading="disableSubmit"
            @uploaded="addMediaFile"
            @upload-failed="uploadFailed"
          />
absturztaube's avatar
absturztaube committed
173
          <div
174
            class="emoji-icon"
absturztaube's avatar
absturztaube committed
175 176
          >
            <i
177 178
              :title="$t('emoji.add_emoji')"
              class="icon-smile btn btn-default"
179
              @click="showEmojiPicker"
absturztaube's avatar
absturztaube committed
180 181
            />
          </div>
HJ's avatar
HJ committed
182 183 184
          <div
            v-if="pollsAvailable"
            class="poll-icon"
185
            :class="{ selected: pollFormVisible }"
HJ's avatar
HJ committed
186 187 188 189 190 191 192
          >
            <i
              :title="$t('polls.add_poll')"
              class="icon-chart-bar btn btn-default"
              @click="togglePollForm"
            />
          </div>
193
        </div>
HJ's avatar
HJ committed
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
        <button
          v-if="posting"
          disabled
          class="btn btn-default"
        >
          {{ $t('post_status.posting') }}
        </button>
        <button
          v-else-if="isOverLengthLimit"
          disabled
          class="btn btn-default"
        >
          {{ $t('general.submit') }}
        </button>
        <button
          v-else
          :disabled="submitDisabled"
          type="submit"
          class="btn btn-default"
        >
          {{ $t('general.submit') }}
        </button>
lain's avatar
lain committed
216
      </div>
HJ's avatar
HJ committed
217 218 219 220
      <div
        v-if="error"
        class="alert error"
      >
221
        Error: {{ error }}
HJ's avatar
HJ committed
222 223 224 225
        <i
          class="button-icon icon-cancel"
          @click="clearError"
        />
226
      </div>
lain's avatar
lain committed
227
      <div class="attachments">
HJ's avatar
HJ committed
228 229
        <div
          v-for="file in newStatus.files"
HJ's avatar
HJ committed
230
          :key="file.url"
HJ's avatar
HJ committed
231 232
          class="media-upload-wrapper"
        >
lain's avatar
lain committed
233
          <i
HJ's avatar
HJ committed
234 235
            class="fa button-icon icon-cancel"
            @click="removeMediaFile(file)"
lain's avatar
lain committed
236
          />
237
          <div class="media-upload-container attachment">
HJ's avatar
HJ committed
238 239 240 241
            <img
              v-if="type(file) === 'image'"
              class="thumbnail media-upload"
              :src="file.url"
HJ's avatar
HJ committed
242
            >
HJ's avatar
HJ committed
243 244 245 246 247 248 249 250 251 252 253 254 255 256
            <video
              v-if="type(file) === 'video'"
              :src="file.url"
              controls
            />
            <audio
              v-if="type(file) === 'audio'"
              :src="file.url"
              controls
            />
            <a
              v-if="type(file) === 'unknown'"
              :href="file.url"
            >{{ file.url }}</a>
257
          </div>
lain's avatar
lain committed
258 259
        </div>
      </div>
HJ's avatar
HJ committed
260 261 262 263
      <div
        v-if="newStatus.files.length > 0"
        class="upload_settings"
      >
264 265 266
        <Checkbox v-model="newStatus.nsfw">
          {{ $t('post_status.attachments_sensitive') }}
        </Checkbox>
267
      </div>
lain's avatar
lain committed
268 269 270 271 272
    </form>
  </div>
</template>

<script src="./post_status_form.js"></script>
273 274

<style lang="scss">
275
@import '../../_variables.scss';
276

277
.tribute-container {
HJ's avatar
indents  
HJ committed
278 279 280 281 282 283 284 285 286 287 288 289 290 291
  ul {
    padding: 0px;
    li {
      display: flex;
      align-items: center;
    }
  }
  img {
    padding: 3px;
    width: 16px;
    height: 16px;
    border-radius: $fallback--avatarAltRadius;
    border-radius: var(--avatarAltRadius, $fallback--avatarAltRadius);
  }
292 293
}

294 295 296 297
.post-status-form {
  .visibility-tray {
    display: flex;
    justify-content: space-between;
298
    padding-top: 5px;
299 300 301
  }
}

HJ's avatar
HJ committed
302
.post-status-form {
HJ's avatar
indents  
HJ committed
303 304
  .form-bottom {
    display: flex;
HJ's avatar
HJ committed
305
    justify-content: space-between;
HJ's avatar
indents  
HJ committed
306 307 308
    padding: 0.5em;
    height: 32px;

309 310 311 312
    button {
      width: 10em;
    }

HJ's avatar
indents  
HJ committed
313 314 315 316 317 318 319
    p {
      margin: 0.35em;
      padding: 0.35em;
      display: flex;
    }
  }

lain's avatar
lain committed
320 321 322
  .form-bottom-left {
    display: flex;
    flex: 1;
323 324
    padding-right: 7px;
    margin-right: 7px;
HJ's avatar
HJ committed
325
    max-width: 10em;
lain's avatar
lain committed
326 327
  }

328 329 330 331 332 333 334
  .text-format {
    .only-format {
      color: $fallback--faint;
      color: var(--faint, $fallback--faint);
    }
  }

335
  .media-upload-icon, .poll-icon, .emoji-icon {
lain's avatar
lain committed
336 337 338
    font-size: 26px;
    flex: 1;

339 340 341
    i {
      display: block;
      width: 100%;
lain's avatar
lain committed
342
    }
343 344 345 346 347 348 349 350 351 352 353 354 355 356

    &.selected, &:hover {
      // needs to be specific to override icon default color
      i, label {
        color: $fallback--lightText;
        color: var(--lightText, $fallback--lightText);
      }
    }
  }

  // Order is not necessary but a good indicator
  .media-upload-icon {
    order: 1;
    text-align: left;
lain's avatar
lain committed
357 358
  }

359
  .emoji-icon {
360 361 362 363 364 365 366
    order: 2;
    text-align: center;
  }

  .poll-icon {
    order: 3;
    text-align: right;
absturztaube's avatar
absturztaube committed
367 368
  }

lain's avatar
lain committed
369 370 371
  .icon-chart-bar {
    cursor: pointer;
  }
372

HJ's avatar
indents  
HJ committed
373 374 375 376
  .error {
    text-align: center;
  }

377 378 379 380 381 382 383 384 385 386 387 388 389 390
  .media-upload-wrapper {
    flex: 0 0 auto;
    max-width: 100%;
    min-width: 50px;
    margin-right: .2em;
    margin-bottom: .5em;

    .icon-cancel {
      display: inline-block;
      position: static;
      margin: 0;
      padding-bottom: 0;
      margin-left: $fallback--attachmentRadius;
      margin-left: var(--attachmentRadius, $fallback--attachmentRadius);
HJ's avatar
HJ committed
391
      background-color: $fallback--fg;
HJ's avatar
fixes  
HJ committed
392
      background-color: var(--btn, $fallback--fg);
393 394 395 396 397
      border-bottom-left-radius: 0;
      border-bottom-right-radius: 0;
    }
  }

398 399 400 401 402 403 404
  .status-input-wrapper {
    display: flex;
    position: relative;
    width: 100%;
    flex-direction: column;
  }

HJ's avatar
indents  
HJ committed
405 406 407 408
  .attachments {
    padding: 0 0.5em;

    .attachment {
409
      margin: 0;
HJ's avatar
indents  
HJ committed
410
      position: relative;
411
      flex: 0 0 auto;
412 413
      border: 1px solid $fallback--border;
      border: 1px solid var(--border, $fallback--border);
414 415 416 417 418 419 420 421 422 423 424 425 426
      text-align: center;

      audio {
        min-width: 300px;
        flex: 1 0 auto;
      }

      a {
        display: block;
        text-align: left;
        line-height: 1.2;
        padding: .5em;
      }
HJ's avatar
indents  
HJ committed
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
    }

    i {
      position: absolute;
      margin: 10px;
      padding: 5px;
      background: rgba(230,230,230,0.6);
      border-radius: $fallback--attachmentRadius;
      border-radius: var(--attachmentRadius, $fallback--attachmentRadius);
      font-weight: bold;
    }
  }

  .btn {
    cursor: pointer;
  }

  .btn[disabled] {
    cursor: not-allowed;
  }

  form {
    display: flex;
    flex-direction: column;
    padding: 0.6em;
  }

  .form-group {
    display: flex;
    flex-direction: column;
457
    padding: 0.25em 0.5em 0.5em;
HJ's avatar
indents  
HJ committed
458 459 460
    line-height:24px;
  }

Astra's avatar
Astra committed
461 462 463 464 465 466 467 468
  form textarea.form-cw {
    line-height:16px;
    resize: none;
    overflow: hidden;
    transition: min-height 200ms 100ms;
    min-height: 1px;
  }

469
  .form-post-body {
470 471
    height: 16px; // Only affects the empty-height
    line-height: 16px;
HJ's avatar
indents  
HJ committed
472 473 474
    resize: none;
    overflow: hidden;
    transition: min-height 200ms 100ms;
475
    padding-bottom: 1.75em;
HJ's avatar
indents  
HJ committed
476 477 478 479
    min-height: 1px;
    box-sizing: content-box;
  }

480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
  .main-input {
    position: relative;
  }

  .character-counter {
    position: absolute;
    bottom: 0;
    right: 0;
    padding: 0;
    margin: 0 0.5em;

    &.error {
      color: $fallback--cRed;
      color: var(--cRed, $fallback--cRed);
    }
  }

HJ's avatar
indents  
HJ committed
497 498 499 500 501 502 503 504 505 506 507 508
  .btn {
    cursor: pointer;
  }

  .btn[disabled] {
    cursor: not-allowed;
  }

  .icon-cancel {
    cursor: pointer;
    z-index: 4;
  }
509
}
510
</style>