aboutsummaryrefslogtreecommitdiff
path: root/src/components/search/search.vue
blob: bd384ad3fcfdf222e9a988dbd0a1363accd70cc1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<template>
  <div class="Search panel panel-default">
    <div class="panel-heading">
      <div class="title">
        {{ $t('nav.search') }}
      </div>
    </div>
    <div class="panel-body search-input-container">
      <input
        ref="searchInput"
        v-model="searchTerm"
        class="input search-input"
        :placeholder="$t('nav.search')"
        @keyup.enter="newQuery(searchTerm)"
      >
      <button
        class="btn button-default search-button"
        type="submit"
        @click="newQuery(searchTerm)"
      >
        <FAIcon icon="search" />
      </button>
    </div>
    <div
      v-if="loading && statusesOffset == 0"
      class="panel-body text-center loading-icon"
    >
      <FAIcon
        icon="circle-notch"
        spin
        size="lg"
      />
    </div>
    <div v-else-if="loaded">
      <div class="search-nav-heading">
        <tab-switcher
          ref="tabSwitcher"
          :on-switch="onResultTabSwitch"
          :active-tab="currenResultTab"
        >
          <span
            key="statuses"
            :label="$t('user_card.statuses') + resultCount('visibleStatuses')"
          />
          <span
            key="people"
            :label="$t('search.people') + resultCount('users')"
          />
          <span
            key="hashtags"
            :label="$t('search.hashtags') + resultCount('hashtags')"
          />
        </tab-switcher>
      </div>
    </div>
    <div class="panel-body">
      <div v-if="currenResultTab === 'statuses'">
        <Status
          v-for="status in visibleStatuses"
          :key="status.id"
          :collapsable="false"
          :expandable="false"
          :compact="false"
          class="search-result"
          :statusoid="status"
          :no-heading="false"
        />
        <button
          v-if="!loading && loaded && lastStatusFetchCount > 0"
          class="more-statuses-button button-unstyled -link"
          @click.prevent="search(searchTerm, 'statuses')"
        >
          <div class="new-status-notification text-center">
            {{ $t('search.load_more') }}
          </div>
        </button>
        <div
          v-else-if="loading && statusesOffset > 0"
          class="text-center loading-icon"
        >
          <FAIcon
            icon="circle-notch"
            spin
            size="lg"
          />
        </div>
        <div
          v-if="(visibleStatuses.length === 0 || lastStatusFetchCount === 0) && !loading && loaded"
          class="search-result-heading"
        >
          <h4>
            {{ visibleStatuses.length === 0 ? $t('search.no_results') : $t('search.no_more_results') }}
          </h4>
        </div>
      </div>
      <div v-else-if="currenResultTab === 'people'">
        <div
          v-if="users.length === 0 && !loading && loaded"
          class="search-result-heading"
        >
          <h4>{{ $t('search.no_results') }}</h4>
        </div>
        <FollowCard
          v-for="user in users"
          :key="user.id"
          :user="user"
          class="list-item search-result"
        />
      </div>
      <div v-else-if="currenResultTab === 'hashtags'">
        <div
          v-if="hashtags.length === 0 && !loading && loaded"
          class="search-result-heading"
        >
          <h4>{{ $t('search.no_results') }}</h4>
        </div>
        <div
          v-for="hashtag in hashtags"
          :key="hashtag.url"
          class="status trend search-result"
        >
          <div class="hashtag">
            <router-link :to="{ name: 'tag-timeline', params: { tag: hashtag.name } }">
              #{{ hashtag.name }}
            </router-link>
            <div v-if="lastHistoryRecord(hashtag)">
              <span v-if="lastHistoryRecord(hashtag).accounts == 1">
                {{ $t('search.person_talking', { count: lastHistoryRecord(hashtag).accounts }) }}
              </span>
              <span v-else>
                {{ $t('search.people_talking', { count: lastHistoryRecord(hashtag).accounts }) }}
              </span>
            </div>
          </div>
          <div
            v-if="lastHistoryRecord(hashtag)"
            class="count"
          >
            {{ lastHistoryRecord(hashtag).uses }}
          </div>
        </div>
      </div>
    </div>
    <div class="search-result-footer text-center panel-footer faint" />
  </div>
</template>

<script src="./search.js"></script>

<style lang="scss">
.search-result-heading {
  color: var(--faint);
  padding: 0.75rem;
  text-align: center;
}

@media all and (max-width: 800px) {
  .search-nav-heading {
    .tab-switcher .tabs .tab-wrapper {
      display: block;
      justify-content: center;
      flex: 1 1 auto;
      text-align: center;
    }
  }
}

.search-result {
  box-sizing: border-box;
  border-bottom: 1px solid;
  border-color: var(--border);
}

.search-input-container {
  padding: 0.8rem;
  display: flex;
  justify-content: center;

  .search-input {
    width: 100%;
    line-height: 1.125rem;
    font-size: 1rem;
    padding: 0.5rem;
    box-sizing: border-box;
  }

  .search-button {
    margin-left: 0.5em;
  }
}

.loading-icon {
  padding: 1em;
}

.trend {
  display: flex;
  align-items: center;

  .hashtag {
    flex: 1 1 auto;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .count {
    flex: 0 0 auto;
    width: 2rem;
    font-size: 1.5rem;
    line-height: 2.25rem;
    font-weight: 500;
    text-align: center;
    color: var(--text);
  }
}

.more-statuses-button {
  height: 3.5em;
  line-height: 3.5em;
  width: 100%;
}

</style>