Skip to content

Instantly share code, notes, and snippets.

View ermineaweb's full-sized avatar

Romain ermineaweb

View GitHub Profile
@ermineaweb
ermineaweb / ANSI.md
Last active January 24, 2024 20:47 — forked from fnky/ANSI.md
ANSI Escape Codes

ANSI Escape Sequences

Standard escape codes are prefixed with Escape:

  • Ctrl-Key: ^[
  • Octal: \033
  • Unicode: \u001b
  • Hexadecimal: \x1B
  • Decimal: 27
function Users({ users }) {
const [bookmarksOnly, setBookmarksOnly] = useState(false);
const [usersState, setUsersState] = useState(users);
const [bookmarks, toggleBookmark] = useBookmarks();
const changeBookMarksOnly = (e) => {
setBookmarksOnly(e.target.checked);
};
useEffect(() => {
{usersState.map((user) => {
const isBookmarked = bookmarks.includes(user.id);
return (
<div key={user.id} className={`user ${isBookmarked ? "bookmarked" : ""}`}>
<div>{user.username}</div>
<button onClick={toggleBookmark(user.id)}>
{isBookmarked ? "Remove from bookmarks" : "Add to bookmarks"}
</button>
</div>
);
function useBookmarks() {
const [bookmarks, setBookmarks] = useState(() => {
const ls = localStorage.getItem("bookmarks");
if (ls) return JSON.parse(ls);
else return [];
});
const toggleItemInLocalStorage = (id) => () => {
const isBookmarked = bookmarks.includes(id);
if (isBookmarked) setBookmarks((prev) => prev.filter((b) => b !== id));
function App() {
return <Users users={users} />;
}
function Users({ users }) {
return (
<div className={"root"}>
<div className={"users"}>
{usersState.map((user) => {
return (
<div key={user.id} className={`user`}>
<div>{user.username}</div>
</div>
);
@ermineaweb
ermineaweb / User.js
Created January 15, 2021 20:01
user
{usersState.map((user) => {
return (
<div key={user.id} className={`user`}>
<div>{user.username}</div>
</div>
);
})}
/* General Scrollbar style */
::-webkit-scrollbar {
/*vertical scroll bar*/
width: 8px;
/*horizontal scroll bar*/
height: 8px;
border-radius: 20px;
}
::-webkit-scrollbar-track,
@ermineaweb
ermineaweb / User.js
Created December 16, 2020 20:12
User
const handleCreateUser = () => {
createUser({
variables: { username },
optimisticResponse: {
__typename: "Mutation",
// use the uuid library to have a unique ID
createUser: { __typename: "User", id: 123456, username },
},
@ermineaweb
ermineaweb / Users.js
Created December 16, 2020 20:11
Users
const mutationRequest = gql`
mutation($username: String!) {
createUser(username: $username) {
id
username
}
}
`;
function Users({ users }) {