/
effects.js
88 lines (75 loc) · 1.77 KB
/
effects.js
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
import {
toHttps
} from './utils'
import {
process
} from 'uniqid';
const loadFont = ({
action,
error,
font,
index
}, dispatch) => {
const fontFace = new FontFace(
font.family,
`url(${toHttps(font.files.regular)})`, {
weight: 'normal',
style: 'normal'
});
fontFace.load().then(function (font) {
document.fonts.add(font);
dispatch(action, {
font,
index
})
}).catch(function (msg) {
console.log(msg)
dispatch(error, msg)
});
}
export const LoadFontEffect = (props) => ({
effect: loadFont,
...props
})
const uniqId = (props, dispatch) => {
if (props.token) {
console.log("using params: ", props.token)
dispatch(props.action, props.token)
} else {
console.log("generating uniqid")
const p = process("#")
window.location = window.location + p
dispatch(props.action, p)
}
}
export const UniqIdEffect = (props) => ({
effect: uniqId,
...props
})
const readParams = (props, dispatch) => {
console.log("URL: ", window.location.hash)
dispatch(props.action, {
token: window.location.hash
})
}
export const TokenEffect = (props) => ({
effect: readParams,
...props
})
const copyLink = (props, dispatch) => {
console.log("Copying link")
document.getElementById("loc").select()
document.execCommand('copy');
var popup = document.getElementById("myPopup");
popup.classList.toggle("visible");
setTimeout(
() => {
popup.classList.toggle("visible")
popup.classList.toggle("hidden");
}, 5000)
dispatch(props.action)
}
export const CopyLink = (props) => ({
effect: copyLink,
...props
})