-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
143 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import ClubhouseController from "clubhouse/controllers/clubhouse-controller"; | ||
import {tracked} from '@glimmer/tracking'; | ||
import {action} from '@ember/object'; | ||
|
||
export default class BookmarkController extends ClubhouseController { | ||
@tracked isLoading = false; | ||
@tracked haveError = null; | ||
@tracked notFound = false; | ||
@tracked content = null; | ||
@tracked updatedAt; | ||
|
||
@tracked countdown; | ||
|
||
@tracked now; | ||
|
||
refreshTime = 0; | ||
|
||
async loadDocument() { | ||
this.isLoading = true; | ||
this.haveError = null; | ||
try { | ||
const {content, updated_at, refresh_time} = await this.ajax.request(`bookmark/${this.bookmarkId}`); | ||
this.content = content; | ||
this.updatedAt = updated_at; | ||
this.refreshTime = refresh_time * 60; | ||
this.countdown = refresh_time * 60; | ||
} catch (e) { | ||
this.haveError = e.message; | ||
if (e.status !== 404) { | ||
this.refreshTime = 1; | ||
} | ||
} finally { | ||
this.isLoading = false; | ||
} | ||
} | ||
|
||
setupTick() { | ||
this.timeoutId = setInterval(() => this.tick(), 1000); | ||
} | ||
|
||
cancelTick() { | ||
if (this.timeoutId) { | ||
clearTimeout(this.timeoutId); | ||
this.timeoutId = null; | ||
} | ||
} | ||
|
||
tick() { | ||
this.now = new Date(); | ||
if (this.refreshTime > 0) { | ||
this.refreshTime--; | ||
this.countdown = this.refreshTime; | ||
if (!this.refreshTime) { | ||
this.loadDocument(); | ||
} | ||
} | ||
} | ||
|
||
@action | ||
formatTimeLeft() { | ||
const duration = this.countdown; | ||
let minutes = Math.floor(duration / 60); | ||
let seconds = Math.floor(duration % 60); | ||
|
||
if (minutes) { | ||
minutes = Math.floor((duration + 59) / 60); | ||
return `${minutes} minute${minutes !== 1 ? 's' :''}`; | ||
} else { | ||
return `${seconds} second${seconds !== 1 ? 's' :''}`; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import ClubhouseRoute from "clubhouse/routes/clubhouse-route"; | ||
|
||
export default class BookmarkRoute extends ClubhouseRoute { | ||
authRequired = false; | ||
|
||
model({bookmark_id}) { | ||
return bookmark_id; | ||
} | ||
|
||
setupController(controller, bookmarkId) { | ||
controller.content = null; | ||
controller.bookmarkId = bookmarkId; | ||
controller.refreshTime = 0; | ||
controller.countdown = 0; | ||
controller.notFound = false; | ||
controller.setupTick(); | ||
controller.loadDocument(); | ||
this.session.showingBookmark = true; | ||
} | ||
|
||
resetController(controller, isExiting) { | ||
if (isExiting) { | ||
controller.cancelTick(); | ||
this.session.showingBookmark = false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<main> | ||
<div class="d-flex flex-column flex-md-row justify-content-between text-muted text-small px-2"> | ||
<div> | ||
{{#unless this.notFound}} | ||
{{#if this.isLoading}} | ||
<SpinIcon/> | ||
Refreshing page | ||
{{else if this.refreshTime}} | ||
Page refresh in | ||
{{this.formatTimeLeft}} | ||
{{/if}} | ||
{{/unless}} | ||
</div> | ||
{{#if this.content}} | ||
<div> | ||
Document updated {{dayjs-format this.updatedAt "dddd, MMM DD @ HH:mm"}} | ||
</div> | ||
{{/if}} | ||
<div> | ||
Current time {{dayjs-format this.now "ddd, MMM DD @ HH:mm"}} | ||
</div> | ||
</div> | ||
<div class="p-2 mt-3"> | ||
{{#if this.notFound}} | ||
<div class="fs-3 fw-bold"> | ||
Bookmark document was not found. | ||
</div> | ||
{{else if this.content}} | ||
{{!template-lint-disable no-triple-curlies}} | ||
{{{this.content}}} | ||
{{else if this.isLoading}} | ||
<LoadingDialog/> | ||
{{/if}} | ||
</div> | ||
</main> |