Commit 36eeb6c1 authored by ι™ˆεΈ…'s avatar ι™ˆεΈ…

localStorage -> sessionStorage

parent cb3c382b
{
"extends": ["stylelint-config-standard", "stylelint-config-prettier"],
"rules": {
"selector-pseudo-class-no-unknown": null,
"shorthand-property-no-redundant-values": null,
"at-rule-empty-line-before": null,
"at-rule-name-space-after": null,
"comment-empty-line-before": null,
"declaration-bang-space-before": null,
"declaration-empty-line-before": null,
"function-comma-newline-after": null,
"function-name-case": null,
"function-parentheses-newline-inside": null,
"function-max-empty-lines": null,
"function-whitespace-after": null,
"number-leading-zero": null,
"number-no-trailing-zeros": null,
"rule-empty-line-before": null,
"selector-combinator-space-after": null,
"selector-descendant-combinator-no-non-space": null,
"selector-list-comma-newline-after": null,
"selector-pseudo-element-colon-notation": null,
"unit-no-unknown": null,
"no-descending-specificity": null,
"value-list-max-empty-lines": null,
"no-missing-end-of-source-newline": null
}
}
...@@ -148,9 +148,9 @@ export default class Center extends PureComponent { ...@@ -148,9 +148,9 @@ export default class Center extends PureComponent {
<Divider dashed /> <Divider dashed />
<div className={styles.tags}> <div className={styles.tags}>
<div className={styles.tagsTitle}>ζ ‡η­Ύ</div> <div className={styles.tagsTitle}>ζ ‡η­Ύ</div>
{currentUser.tags {currentUser.tags.concat(newTags).map(item => (
.concat(newTags) <Tag key={item.key}>{item.label}</Tag>
.map(item => <Tag key={item.key}>{item.label}</Tag>)} ))}
{inputVisible && ( {inputVisible && (
<Input <Input
ref={this.saveInputRef} ref={this.saveInputRef}
......
...@@ -19,7 +19,7 @@ const codeMessage = { ...@@ -19,7 +19,7 @@ const codeMessage = {
503: 'ζœεŠ‘δΈε―η”¨οΌŒζœεŠ‘ε™¨ζš‚ζ—ΆθΏ‡θ½½ζˆ–η»΄ζŠ€γ€‚', 503: 'ζœεŠ‘δΈε―η”¨οΌŒζœεŠ‘ε™¨ζš‚ζ—ΆθΏ‡θ½½ζˆ–η»΄ζŠ€γ€‚',
504: '网关袅既。', 504: '网关袅既。',
}; };
function checkStatus(response) { const checkStatus = response => {
if (response.status >= 200 && response.status < 300) { if (response.status >= 200 && response.status < 300) {
return response; return response;
} }
...@@ -32,7 +32,26 @@ function checkStatus(response) { ...@@ -32,7 +32,26 @@ function checkStatus(response) {
error.name = response.status; error.name = response.status;
error.response = response; error.response = response;
throw error; throw error;
} };
const cachedSave = (response, hashcode) => {
/**
* Clone a response data and store it in sessionStorage
* Does not support data other than json, Cache only json
*/
let contentType = response.headers.get('Content-Type');
if (contentType && contentType.match(/application\/json/i)) {
// All data is saved as text
response
.clone()
.text()
.then(content => {
sessionStorage.setItem(hashcode, content);
sessionStorage.setItem(hashcode + ':timestamp', Date.now());
});
}
return response;
};
/** /**
* Requests a URL, returning a promise. * Requests a URL, returning a promise.
...@@ -47,7 +66,7 @@ export default function request(url, options = {}) { ...@@ -47,7 +66,7 @@ export default function request(url, options = {}) {
* Produce fingerprints based on url and parameters * Produce fingerprints based on url and parameters
* Maybe url has the same parameters * Maybe url has the same parameters
*/ */
const fingerprint = url + options.body ? JSON.stringify(options.body) : ''; const fingerprint = url + (options.body ? JSON.stringify(options.body) : '');
const hashcode = hash const hashcode = hash
.sha256() .sha256()
.update(fingerprint) .update(fingerprint)
...@@ -77,8 +96,8 @@ export default function request(url, options = {}) { ...@@ -77,8 +96,8 @@ export default function request(url, options = {}) {
}; };
} }
} }
let cached = localStorage.getItem(hashcode); let cached = sessionStorage.getItem(hashcode);
let whenCached = localStorage.getItem(hashcode + ':timestamp'); let whenCached = sessionStorage.getItem(hashcode + ':timestamp');
const expirys = options.expirys || 60; const expirys = options.expirys || 60;
if (cached !== null && whenCached !== null && expirys !== false) { if (cached !== null && whenCached !== null && expirys !== false) {
let age = (Date.now() - whenCached) / 1000; let age = (Date.now() - whenCached) / 1000;
...@@ -86,30 +105,13 @@ export default function request(url, options = {}) { ...@@ -86,30 +105,13 @@ export default function request(url, options = {}) {
let response = new Response(new Blob([cached])); let response = new Response(new Blob([cached]));
return response.json(); return response.json();
} else { } else {
localStorage.removeItem(hashcode); sessionStorage.removeItem(hashcode);
localStorage.removeItem(hashcode + ':timestamp'); sessionStorage.removeItem(hashcode + ':timestamp');
} }
} }
return fetch(url, newOptions) return fetch(url, newOptions)
.then(checkStatus) .then(checkStatus)
.then(response => { .then(cachedSave)
/**
* Clone a response data and store it in localStorage
* Does not support data other than json, Cache only json
*/
let contentType = response.headers.get('Content-Type');
if (contentType && contentType.match(/application\/json/i)) {
// All data is saved as text
response
.clone()
.text()
.then(content => {
localStorage.setItem(hashcode, content);
localStorage.setItem(hashcode + ':timestamp', Date.now());
});
}
return response;
})
.then(response => { .then(response => {
// DELETE and 204 do not return data by default // DELETE and 204 do not return data by default
// using .json will report an error. // using .json will report an error.
......
export default {
extends: ['stylelint-config-standard', 'stylelint-config-prettier'],
rules: {
'selector-pseudo-class-no-unknown': null,
'shorthand-property-no-redundant-values': null,
'at-rule-empty-line-before': null,
'at-rule-name-space-after': null,
'comment-empty-line-before': null,
'declaration-bang-space-before': null,
'declaration-empty-line-before': null,
'function-comma-newline-after': null,
'function-name-case': null,
'function-parentheses-newline-inside': null,
'function-max-empty-lines': null,
'function-whitespace-after': null,
'number-leading-zero': null,
'number-no-trailing-zeros': null,
'rule-empty-line-before': null,
'selector-combinator-space-after': null,
'selector-descendant-combinator-no-non-space': null,
'selector-list-comma-newline-after': null,
'selector-pseudo-element-colon-notation': null,
'unit-no-unknown': null,
'no-descending-specificity': null,
'value-list-max-empty-lines': null,
'no-missing-end-of-source-newline': null,
},
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment