Skip to content
This repository was archived by the owner on Jun 24, 2021. It is now read-only.

Commit 0dc356f

Browse files
add livestream to workview
1 parent bdaa33a commit 0dc356f

4 files changed

Lines changed: 70 additions & 19 deletions

File tree

src/components/WorkView.vue

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
<template>
22
<div class="work-view my-3 my-sm-3 mx-sm-auto rounded-3 mx-3 shadow position-relative">
3-
<router-link rel="noreferrer noopener" target='_blank' to="/form">
4-
<button class="btn text-white position-absolute new-work-btn shadow fw-bolder fs-6 mx-2 my-2" type="button">+
5-
</button>
6-
</router-link>
7-
<h1 class="py-3 py-sm-3 my-0">
3+
<div class="position-absolute new-work-btn-area">
4+
<router-link rel="noreferrer noopener" target='_blank' to="/form">
5+
<button class="btn text-white position-relative shadow fw-bolder fs-6 mx-2 my-2" type="button">+
6+
</button>
7+
</router-link>
8+
<p class="user-select-none live">
9+
<span class="circle"/>
10+
Live
11+
</p>
12+
</div>
13+
<h1 class="py-4 py-sm-4 my-0">
814
<svg class="d-svg" viewBox="0 0 1 1">
915
<use xlink:href="#todo.svg"/>
1016
</svg>
@@ -14,7 +20,8 @@
1420
<div class="container py-3 px-3 mw-100">
1521
<CircleProgress v-if="processing" :msg="progressMsg"/>
1622
<div :class="{'wall__show':processing}" class="wall position-absolute"/>
17-
<div :class="{'invisible':processing}" class="row mw-100 position-relative mx-auto justify-content-center">
23+
<div :key="workViewKey" :class="{'invisible':processing}"
24+
class="row mw-100 position-relative mx-auto justify-content-center">
1825
<WorkCard v-for="(work, k) in works" :key="k"
1926
:subtitle="work.subtitle"
2027
:thumbnail="work.thumbnail"
@@ -37,7 +44,7 @@
3744
import {defineComponent, inject, onMounted, reactive, toRefs, defineAsyncComponent, nextTick} from 'vue';
3845
import '@/scss/components/work-view.scss'
3946
import {dbType, Work} from "@/firebase/type";
40-
import {getCurrentWorks} from "@/firebase/getWork";
47+
import {getCurrentWorks, liveSubscribe} from "@/firebase/getWork";
4148
import '@/svg/todo.svg'
4249
import '@/svg/add.svg'
4350
@@ -52,7 +59,8 @@ export default defineComponent({
5259
const data = reactive({
5360
processing: false,
5461
works: undefined as unknown as Array<Work>,
55-
progressMsg: ''
62+
progressMsg: '',
63+
workViewKey: 0
5664
})
5765
5866
const remove = async (uid: string) => {
@@ -72,22 +80,22 @@ export default defineComponent({
7280
7381
const checkIfNeedToShowEmptyCard = () => {
7482
const emptyCard = document.getElementById('empty-card') as HTMLDivElement
75-
if (data.works.length) {
76-
emptyCard.classList.add('d-none')
77-
} else {
78-
emptyCard.classList.remove('d-none')
79-
}
83+
emptyCard.classList.toggle('d-none', !!data.works.length)
8084
}
8185
8286
const displayWorks = async () => {
83-
data.processing = true
8487
data.works = await getCurrentWorks(store)
85-
checkIfNeedToShowEmptyCard()
86-
data.processing = false
88+
data.workViewKey++
89+
await nextTick(() => {
90+
checkIfNeedToShowEmptyCard()
91+
})
8792
}
8893
8994
onMounted(async () => {
95+
data.processing = true
9096
await displayWorks()
97+
liveSubscribe(store, displayWorks)
98+
data.processing = false
9199
})
92100
93101
return {

src/firebase/getWork.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,10 @@ export const getCurrentWorks = async (store: dbType): Promise<Array<Work>> => {
66
Object.assign({id: work.id}, work.data())
77
) as unknown as Array<Work>
88
}
9+
10+
// eslint-disable-next-line
11+
export const liveSubscribe = (store: dbType, callback: (() => any)): void => {
12+
store.collection('/works').onSnapshot(() => {
13+
callback()
14+
})
15+
}

src/firebase/type.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import firebase from "firebase";
33
export type firebaseType = firebase.app.App
44
export type dbType = firebase.firestore.Firestore
55
export type time = firebase.firestore.Timestamp
6+
export type querySnapshot = firebase.firestore.QuerySnapshot<firebase.firestore.DocumentData>
67

78
export interface WorkDocument {
89
title: string;

src/scss/components/work-view.scss

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,49 @@
66
min-height: 60vh;
77
width: 75vw;
88

9-
.new-work-btn {
9+
.new-work-btn-area {
1010
right: 0;
1111
background-color: #2c3e50;
1212
border-color: white;
13+
overflow: hidden;
14+
display: flex;
15+
flex-direction: column;
1316

14-
:hover {
17+
.live {
18+
.circle {
19+
display: inline-block;
20+
background: #f00;
21+
width: 10px;
22+
height: 10px;
23+
border-radius: 50%;
24+
animation-name: live;
25+
animation-duration: 3s;
26+
animation-iteration-count: infinite;
27+
28+
@keyframes live {
29+
0% {
30+
box-shadow: 0 0 0 .1px rgba(255, 0, 0, .9);
31+
}
32+
100% {
33+
box-shadow: 0 0 0 7px rgba(255, 0, 0, 0);
34+
}
35+
}
36+
}
37+
}
38+
39+
a {
40+
max-width: 100%;
41+
display: inline-block;
42+
43+
&:hover button {
44+
background-color: white;
45+
color: black !important;
46+
}
47+
}
48+
49+
button:hover {
1550
background-color: white;
16-
color: black;
51+
color: black !important;
1752
}
1853
}
1954

0 commit comments

Comments
 (0)