Skip to content

Commit

Permalink
feat: Link @/#
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtextrem committed Apr 5, 2020
1 parent 885779d commit 7c9ac56
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 52 deletions.
70 changes: 32 additions & 38 deletions src/components/Utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
*
*/
export function logAndReturn(e) {
console.warn(e)
return e
Expand All @@ -18,11 +21,7 @@ export class XHR {
}

static fetch(url, options) {
return window
.fetch(url, options)
.then(XHR.checkStatus)
.then(XHR.parseJSON)
.catch(logAndReturn)
return window.fetch(url, options).then(XHR.checkStatus).then(XHR.parseJSON).catch(logAndReturn)
}
}

Expand Down Expand Up @@ -53,26 +52,18 @@ class Storage {

set(key, value) {
return this.promise((resolve, reject) =>
chrome.storage[this.STORAGE].set({ [key]: value }, data =>
Storage.check(data, resolve, reject)
)
chrome.storage[this.STORAGE].set({ [key]: value }, data => Storage.check(data, resolve, reject))
)
}

get(key, defaultValue) {
return this.promise((resolve, reject) =>
chrome.storage[this.STORAGE].get({ [key]: defaultValue }, data =>
Storage.check(data[key], resolve, reject)
)
chrome.storage[this.STORAGE].get({ [key]: defaultValue }, data => Storage.check(data[key], resolve, reject))
)
}

remove(key) {
return this.promise((resolve, reject) =>
chrome.storage[this.STORAGE].remove(key, data =>
Storage.check(data, resolve, reject)
)
)
return this.promise((resolve, reject) => chrome.storage[this.STORAGE].remove(key, data => Storage.check(data, resolve, reject)))
}

static check(data, resolve, reject) {
Expand All @@ -94,11 +85,7 @@ export class Chrome {
index = search.indexOf('tabid')
if (index !== -1) {
console.log('sending req', action, additional)
chrome.tabs.sendMessage(
+search[index + 1],
{ action, ...additional },
null
)
chrome.tabs.sendMessage(+search[index + 1], { action, ...additional }, null)
return true
}
return false
Expand All @@ -112,11 +99,17 @@ export class Chrome {
export const i18n = Chrome.i18n

//const regex = /-fr[atx]\d-\d/
/**
*
*/
export function updateCDN(url) {
return url
// return url.replace(regex, '-frt3-1') // 10.08.2017
}

/**
*
*/
export function shallowDiffers(a, b) {
for (const key in a) if (a[key] !== b[key]) return true
for (const key in b) if (!(key in a)) return true
Expand All @@ -136,24 +129,23 @@ self.addEventListener('message', event => {
})
`

/**
*
*/
export function documentReady() {
return new Promise((resolve, reject) => {
if (
document.readyState === 'interactive' ||
document.readyState === 'complete'
)
resolve()
if (document.readyState === 'interactive' || document.readyState === 'complete') resolve()
else document.addEventListener('DOMContentLoaded', resolve)
})
}

let workerBlob
/**
*
*/
export async function getWorkerBlob() {
await documentReady() // creating a blob is synchronous and takes around 120ms on a powerful machine
if (workerBlob === undefined)
workerBlob = URL.createObjectURL(
new Blob([webWorkerScript], { type: 'application/javascript' })
)
if (workerBlob === undefined) workerBlob = URL.createObjectURL(new Blob([webWorkerScript], { type: 'application/javascript' }))
return workerBlob
}

Expand All @@ -164,14 +156,8 @@ const formReducer = (data, element) => {
else if (type === 'checkbox')
// option
data[element.name] = element.checked
else if (type.indexOf('select') !== -1)
data[element.name] = [].reduce.call(element.options, formReducer, [])
else if (
type === 'button' ||
element.name.indexOf('_add') !== -1 ||
type === 'submit'
)
undefined
else if (type.indexOf('select') !== -1) data[element.name] = [].reduce.call(element.options, formReducer, [])
else if (type === 'button' || element.name.indexOf('_add') !== -1 || type === 'submit') undefined
else if (type === 'number') data[element.name] = +element.value
else data[element.name] = element.value // number, text, etc

Expand Down Expand Up @@ -222,3 +208,11 @@ export function debounce(fn, delay) {
inDebounce = setTimeout(() => fn.apply(this, args), delay)
}
}

/**
*
*/
export function markAtsAndHashtags(text) {
const ats = text.replace(/(\s)@([\w-]+)/g, '$1<a href="/$2/">@$2</a>')
return ats.replace(/(\s)#([\w-]+)/g, '$1<a href="/explore/tags/$2/">@$2</a>')
}
5 changes: 3 additions & 2 deletions src/components/feed/Comments.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Heart from './Heart'
import PropTypes from 'prop-types'
import { Component, h } from 'preact'
import { markAtsAndHashtags } from '../Utils'

const Comments = props => (
<div class="ige_post-comments mb-8">
Expand All @@ -9,10 +10,10 @@ const Comments = props => (
return (
<div class="d-block p-relative">
<div class="d-block mr-1em">
<a class="" title={username} href={'/' + username + '/'}>
<a class="ige_username" title={username} href={'/' + username + '/'}>
{username}
</a>
<span class="pl-2 ige_text">{v.node.text}</span>
<span class="pl-2 ige_text">{markAtsAndHashtags(v.node.text)}</span>
</div>
{/*<button type="button" class="ige_button">
<Heart width={12} height={12} fill="#8e8e8e" active={v.node.viewer_has_liked} />
Expand Down
5 changes: 3 additions & 2 deletions src/components/feed/Post.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import PostMedia from './PostMedia' // @todo: when handleEvent works again, remo
import Save from './Save'
import bind from 'autobind-decorator'
import { Fragment, h } from 'preact'
import { markAtsAndHashtags } from '../Utils'

export default class Post extends FetchComponent {
state = {
Expand Down Expand Up @@ -174,10 +175,10 @@ export default class Post extends FetchComponent {
<div class="ige_post-content px-12">
{text !== undefined ? (
<div class="ige_post-text d-block">
<a class="" title={owner.username} href={'/' + owner.username + '/'}>
<a class="ige_username" title={owner.username} href={'/' + owner.username + '/'}>
{owner.username}
</a>
<span class="pl-2 ige_text">{text}</span>
<span class="pl-2 ige_text">{markAtsAndHashtags(text)}</span>
</div>
) : null}
<Comments data={comments} />
Expand Down
47 changes: 37 additions & 10 deletions src/components/feed/feed.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
--boxWidth: 23vw;
--boxMarginRight: 10px;
--primary: white;
--navHeight: 54px;
}

#ige_feed {
position: fixed;
top: 7vh;
top: var(--navHeight);
bottom: 0;
right: 3vw;
left: 9px;
Expand All @@ -17,6 +18,8 @@
}

.ige_virtual {
padding-top: 10px;

overflow-y: scroll;
max-height: 100%;
height: 100%;
Expand Down Expand Up @@ -48,6 +51,29 @@
background-color: red;
}

.sentinel {
position: absolute;
pointer-events: none;
height: 1000px;
width: 100%;
visibility: hidden;
bottom: 0;
z-index: 9999;
}
.sentinel-start {
position: absolute;
pointer-events: none;
height: 1000px;
width: 100%;
visibility: hidden;
top: 0;
z-index: 9999;
}
.sentinel-start.disabled,
.sentinel.disabled {
display: none;
}

.sentinel-top {
top: 0;
}
Expand All @@ -65,7 +91,7 @@
width: var(--boxWidth);
min-width: var(--boxWidth);
max-width: var(--boxWidth);
max-height: 70rem;
max-height: calc(70vh - var(--navHeight));
margin-right: var(--boxMarginRight);
margin-bottom: 10px;
contain: layout style;
Expand All @@ -81,7 +107,7 @@
display: grid;
grid-template-rows: 53px auto 40px 1fr 45px;

height: auto; /* 100% */
height: auto;
}

.ige_textarea {
Expand Down Expand Up @@ -215,11 +241,6 @@
overflow-y: auto;
}

.ige_post-content a {
color: rgba(var(--anchor-color, 38, 38, 38), 1);
font-weight: 600;
}

.ige_post-text {
overflow-wrap: break-word;
max-width: 100%;
Expand Down Expand Up @@ -252,15 +273,15 @@
}

.ige_username {
color: rgba(var(--anchor-color, 38, 38, 38), 1);
color: rgba(var(--anchor-color, 38, 38, 38), 1) !important;
font-weight: 600;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}

.ige_location {
color: rgba(var(--anchor-color, 38, 38, 38), 1);
color: rgba(var(--anchor-color, 38, 38, 38), 1) !important;
line-height: 15px;
font-size: 12px;
overflow: hidden;
Expand Down Expand Up @@ -480,6 +501,12 @@
}
}

@keyframes fadeIn {
100% {
opacity: 1;
}
}

.ige_add_comment {
display: flex;
flex-grow: 1;
Expand Down

0 comments on commit 7c9ac56

Please sign in to comment.