-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bookmark endpoints #96
Merged
lbguilherme
merged 6 commits into
sdkgen:master
from
kevinoliveira:feat/playground-favorite-endpoints
Oct 8, 2020
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
85490b1
bookmark endpoints
06848f3
prettier
a052c18
adding storage-factory as dependency to use localStorage safely
b09eda3
fix: playground prettier
79418a9
fix: playground prettier
315476f
Merge remote-tracking branch 'original/master' into feat/playground-f…
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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,21 @@ | ||
|
||
import * as React from "react"; | ||
import classnames from "classnames"; | ||
import s from "./section.scss"; | ||
|
||
interface TitleProps { | ||
title: string | ||
featured?: boolean; | ||
} | ||
|
||
export function Section(props: React.PropsWithChildren<TitleProps>) { | ||
|
||
const { title, featured, children } = props; | ||
|
||
return ( | ||
<div className={classnames(s.section, featured && s.featured)}> | ||
<div className={s.title}>{title}</div> | ||
<div className={s.childrenWrapper}>{children}</div> | ||
</div> | ||
); | ||
} |
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,38 @@ | ||
@import "shared-colors"; | ||
|
||
.section { | ||
&.featured { | ||
.title { | ||
color: $red-dark-1; | ||
|
||
&::after { | ||
background: $red-dark-1; | ||
} | ||
} | ||
} | ||
|
||
.title { | ||
color: $c8; | ||
font-weight: bold; | ||
text-transform: capitalize; | ||
|
||
display: flex; | ||
align-items: flex-start; | ||
text-align: left; | ||
|
||
line-height: 25px; | ||
|
||
&::after { | ||
content: ""; | ||
margin: auto; | ||
height: 2px; | ||
background: $lightgray; | ||
flex-grow: 1; | ||
min-width: 25px; | ||
margin-left: 12px; | ||
} | ||
} | ||
.childrenWrapper { | ||
margin: 20px 0px 40px 0px; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
playground/src/helpers/localStorage/bookmarkedEndpoints.ts
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 { safeLocalStorage } from "./safeLocalStorage"; | ||
|
||
const BOOKMARK_LOCALSTORAGE_KEY = "bookmarked_endpoints"; | ||
|
||
export function persistEndpointBookmarkStatus(name: string, status: boolean) { | ||
const currentBookmaked = getLocalStorageBookmarks(); | ||
if (status) { | ||
// bookmark | ||
setLocalStorageBookmarks([...currentBookmaked, name]); | ||
} else { | ||
// unbookmark | ||
setLocalStorageBookmarks(currentBookmaked.filter((n) => n !== name)); | ||
} | ||
} | ||
|
||
export function getLocalStorageBookmarks(): string[] { | ||
const content = safeLocalStorage.getItem(BOOKMARK_LOCALSTORAGE_KEY); | ||
if (content) { | ||
return JSON.parse(content); | ||
} else { | ||
return []; | ||
} | ||
} | ||
|
||
export function setLocalStorageBookmarks(names: string[]) { | ||
safeLocalStorage.setItem(BOOKMARK_LOCALSTORAGE_KEY, JSON.stringify(names)); | ||
} | ||
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,3 @@ | ||
import { storageFactory } from "storage-factory"; | ||
|
||
export const safeLocalStorage = storageFactory(() => localStorage); |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will have some issues with browsers limiting local storage, such as lack of space of Safari's icognito mode. Better check that localStorage is actually working and guard it with a try catch, falling back to memory: https://michalzalecki.com/why-using-localStorage-directly-is-a-bad-idea/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
solved