-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.coffee
79 lines (65 loc) · 2.64 KB
/
client.coffee
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
# This client-side CoffeeScript is compiled
# by express browserify middleware using the
# coffeeify transform
application = require './application.coffee'
qs = require 'querystringify'
queryString = qs.parse window.location.search
IndexTemplate = require "./templates/pages/index"
CategoryPage = require "./presenters/category-page"
Search = require "./presenters/search"
errorPageTemplate = require "./templates/pages/error-page"
normalizedRoute = route.replace(/^\/|\/$/g, "")
console.log "normalizedRoute is #{normalizedRoute}"
console.log "query strings are", queryString
console.log "application is", application
console.log "🌈 isSignedIn", application.user.isSignedIn()
# client-side routing:
Promise.resolve()
.then ->
if document.location.hash.startsWith "#!/"
document.location = "https://glitch.com/edit/" + document.location.hash
return
.then ->
if normalizedRoute.startsWith "login/"
application.login normalizedRoute.substring("login/".length), queryString.code
.then ->
history.replaceState null, null, "#{baseUrl}/"
normalizedRoute = ""
.then ->
index = IndexTemplate application
errorPage = errorPageTemplate application
application.user.getUserRecentProjects()
if normalizedRoute is "index.html"
normalizedRoute = ""
if normalizedRoute is ""
document.body.appendChild index
else if application.isCategoryUrl(normalizedRoute)
console.log 'hi'
category = application.getCategoryFromUrl normalizedRoute
categoryPage = CategoryPage(application, category).template()
document.body.appendChild categoryPage
document.title = category.name
else if application.isProjectUrl(normalizedRoute)
projectDomain = application.removeFirstCharacter normalizedRoute
document.body.appendChild index
application.overlay.showProjectOverlayForProject projectDomain
# else if application.isUserProfileUrl(normalizedRoute)
# document.body.append '🙋 hello im a @profile page'
else if application.isSearchUrl(normalizedRoute, queryString)
application.searchQuery queryString.q
searchPage = Search(application).template()
document.body.appendChild searchPage
document.title = queryString.q
else
document.body.appendChild errorPage
document.title = "👻 Page not found"
# document.addEventListener "keydown", (event) ->
# application.closeAllPopOvers event
# application.tracking.init event
document.addEventListener "click", (event) ->
globalclick event
document.addEventListener "touchstart", (event) ->
globalclick event
globalclick = (event) ->
unless $(event.target).closest('.pop-over, .opens-pop-over, .overlay').length
application.closeAllPopOvers()