Skip to content

Commit 8a4ee0c

Browse files
committedSep 19, 2020
feat: возможность закрыть снекбар и отображение в нем эмодзей
1 parent 23bc637 commit 8a4ee0c

File tree

5 files changed

+60
-13
lines changed

5 files changed

+60
-13
lines changed
 

Diff for: ‎src/components/ContextMenus/ContextMenuWrapper.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export default {
8383
.context_menu_wrap {
8484
position: absolute;
8585
top: 0;
86-
z-index: 3;
86+
z-index: 4;
8787
width: 100%;
8888
height: 100%;
8989
visibility: hidden;

Diff for: ‎src/components/SnackbarsWrapper.vue

+29-8
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,22 @@
88
:color="snackbar.color || 'var(--icon-blue)'"
99
width="24"
1010
height="24"
11+
class="snackbar_icon"
1112
/>
1213

13-
{{ snackbar.text }}
14+
<div>
15+
<VKText mention="attachment">{{ snackbar.text }}</VKText>
16+
</div>
17+
18+
<Icon
19+
v-if="snackbar.closable"
20+
name="close"
21+
color="var(--icon-dark-gray)"
22+
width="14"
23+
height="14"
24+
class="snackbar_close_icon"
25+
@click="snackbar.close"
26+
/>
1427
</div>
1528
</Transition>
1629
</div>
@@ -20,10 +33,12 @@
2033
import { snackbarsState } from 'js/snackbars';
2134
2235
import Icon from './UI/Icon.vue';
36+
import VKText from './UI/VKText.vue';
2337
2438
export default {
2539
components: {
26-
Icon
40+
Icon,
41+
VKText
2742
},
2843
2944
setup() {
@@ -39,7 +54,7 @@ export default {
3954
4055
.snackbar-enter-from, .snackbar-leave-to {
4156
opacity: 0;
42-
transform: translateY(10px);
57+
transform: translateY(15px);
4358
}
4459
4560
.snackbars {
@@ -52,26 +67,32 @@ export default {
5267
width: 100%;
5368
height: 100%;
5469
pointer-events: none;
55-
padding-bottom: 20px;
70+
padding-bottom: 25px;
5671
}
5772
5873
.snackbar {
5974
display: flex;
6075
align-items: center;
61-
position: relative;
76+
text-align: center;
6277
padding: 5px 12px;
63-
margin-top: 10px;
6478
max-width: 80%;
6579
min-height: 45px;
66-
max-height: 200px;
80+
pointer-events: auto;
6781
background: var(--background);
6882
border: 1px solid var(--separator-dark);
6983
border-radius: 10px;
7084
box-shadow: 0 0 20px 0 rgba(0, 0, 0, .24),
7185
0 0 2px 0 rgba(0, 0, 0, .08);
7286
}
7387
74-
.snackbar svg {
88+
.snackbar_icon {
89+
flex: none;
7590
margin-right: 10px;
7691
}
92+
93+
.snackbar_close_icon {
94+
flex: none;
95+
margin-left: 10px;
96+
cursor: pointer;
97+
}
7798
</style>

Diff for: ‎src/components/messages/chat/Keyboard.vue

+5-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ export default {
120120
121121
switch (data.action.type) {
122122
case 'show_snackbar':
123-
addSnackbar({ text: data.action.text });
123+
addSnackbar({
124+
text: data.action.text,
125+
duration: 8000,
126+
closable: true
127+
});
124128
break;
125129
126130
case 'open_link':

Diff for: ‎src/js/snackbars.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { reactive } from 'vue';
2-
import { timer } from './utils';
2+
import { timer, createCallablePromise } from './utils';
33

44
const snackbars = [];
55
let id = 0;
@@ -12,9 +12,15 @@ let inWork = false;
1212

1313
async function execute() {
1414
const data = snackbars.shift();
15+
const closePromise = createCallablePromise();
1516

17+
data.close = closePromise.resolve;
1618
snackbarsState.snackbar = data;
17-
await timer(data.timeout || 2000);
19+
20+
await Promise.race([
21+
timer(data.duration || 2000),
22+
closePromise
23+
]);
1824

1925
if (snackbars.length) {
2026
execute();
@@ -29,7 +35,8 @@ interface Data {
2935
text: string
3036
icon?: string // название svg иконки
3137
color?: string // цвет иконки (по умолчанию 'var(--icon-blue)')
32-
timeout?: number // время отображения снекбара в мс (по умолчанию 2000)
38+
duration?: number // время отображения снекбара в мс (по умолчанию 2000)
39+
closable?: boolean // добавлять ли иконку закрытия снекбара (по умолчанию false)
3340
}
3441
*/
3542
export function addSnackbar(data) {

Diff for: ‎src/js/utils.js

+15
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,21 @@ export function moveArrItem(arr, from, to) {
205205
return arr;
206206
}
207207

208+
export function createCallablePromise() {
209+
let resolve;
210+
let reject;
211+
212+
const promise = new Promise((res, rej) => {
213+
resolve = res;
214+
reject = rej;
215+
});
216+
217+
promise.resolve = resolve;
218+
promise.reject = reject;
219+
220+
return promise;
221+
}
222+
208223
// 125 -> 125
209224
// 12.732 -> 12K
210225
// 5.324.267 -> 5M

0 commit comments

Comments
 (0)