-
Notifications
You must be signed in to change notification settings - Fork 359
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
LinkInBio template with LaunchDarkly integration #272
Merged
elviskahoro
merged 12 commits into
reflex-dev:main
from
erinmikailstaples:erin-final-edits
Oct 22, 2024
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9073a55
import file and add readme
erinmikailstaples aab23c5
update spacing and add pronouns.
erinmikailstaples 9742bfb
add details branch
erinmikailstaples a98b9ea
Adding polling for variation
elviskahoro c0178f8
removing commented code
elviskahoro 8bb6b1c
Letting the app work without the feature flags
elviskahoro 0784acb
increasing time counter
elviskahoro b0a6718
update final edits.
erinmikailstaples 83fbdd8
cleaned up for tutorial versions!
erinmikailstaples b64b516
Removed .venv directory
erinmikailstaples eb257bf
Update requirements.txt
erinmikailstaples 2876c70
Update requirements.txt
erinmikailstaples File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"githubPullRequests.ignoredPullRequestBranches": [ | ||
"main" | ||
] | ||
} |
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,6 @@ | ||
*.db | ||
*.py[cod] | ||
.env | ||
.web | ||
__pycache__/ | ||
assets/external/ |
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,90 @@ | ||
# Link in Bio App | ||
This application is built using Reflex.dev, a powerful framework for creating interactive web applications using pure Python. This app allows you to showcase your online presence with a customizable link in bio page. | ||
|
||
## Features | ||
|
||
- **Customizable Links**: Easily add links to your personal website, Twitter, GitHub, LinkedIn, and more. | ||
- **Responsive Design**: The app is designed to look great on both desktop and mobile devices. | ||
- **Stylish UI**: Uses a vibrant gradient background and modern UI components. | ||
|
||
## Installation | ||
|
||
To get started with this project follow these steps: | ||
|
||
### Prerequisites | ||
|
||
- Python 3.7 or higher | ||
- pip (Python package manager) | ||
|
||
### Steps | ||
|
||
1. **Clone the Repository** | ||
|
||
Clone the repository to your local machine using the following command: | ||
|
||
```bash | ||
git clone https://github.com/reflex-dev/reflex-examples | ||
cd reflex-examples/linkinbio | ||
``` | ||
2. **Install Dependencies** | ||
|
||
Install the required Python packages using pip: | ||
|
||
```bash | ||
pip install -r requirements.txt | ||
``` | ||
|
||
The `requirements.txt` file specifies the necessary Reflex version: | ||
```plaintext:linkinbio/requirements.txt | ||
startLine: 1 | ||
endLine: 2 | ||
``` | ||
|
||
|
||
|
||
3. **Run the Application** | ||
|
||
Start the application using the following command: | ||
```bash | ||
reflex run | ||
``` | ||
|
||
The app will be accessible at `http://localhost:3000` by default. | ||
|
||
## Project Structure | ||
|
||
- **linkinbio.py**: Contains the main application logic, including the `link_button` and `index` functions. | ||
```python:linkinbio/linkinbio/linkinbio.py | ||
startLine: 1 | ||
endLine: 57 | ||
``` | ||
|
||
- **style.py**: Defines the styling for the app components, including buttons, links, and layout. | ||
```python:linkinbio/linkinbio/style.py | ||
startLine: 1 | ||
endLine: 55 | ||
``` | ||
|
||
- **rxconfig.py**: Configuration file for the Reflex app. | ||
```python:linkinbio/rxconfig.py | ||
startLine: 1 | ||
endLine: 5 | ||
``` | ||
|
||
- **.gitignore**: Specifies files and directories to be ignored by Git. | ||
```plaintext:linkinbio/.gitignore | ||
startLine: 1 | ||
endLine: 6 | ||
``` | ||
|
||
## Customization | ||
|
||
You can customize the links and personal information by editing the `index` function in `linkinbio.py`. Update the `name`, `bio`, `avatar_url`, and `links` list to reflect your personal details. | ||
|
||
## Contributing | ||
|
||
Contributions are welcome! Please fork the repository and submit a pull request for any improvements or bug fixes. | ||
|
||
## Contact | ||
|
||
This template was created by @erinmikailstaples (https://github.com/erinmikailstaples). Feel free to reach out for any quesitons, feedback, or collaboration opportunities. |
Binary file not shown.
Empty file.
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,202 @@ | ||
import reflex as rx | ||
from linkinbio.style import * | ||
|
||
# add launchdarkly imports | ||
import ldclient | ||
from ldclient.config import Config | ||
from ldclient import Context, LDClient | ||
import os | ||
|
||
# Initialize LD client (this should be done once, typically at app startup) | ||
SDK_KEY: str | None = os.getenv("LD_SDK_KEY", None) | ||
|
||
LD_CLIENT: LDClient | None = None | ||
LD_CONTEXT: Context | None = None | ||
if SDK_KEY is not None: | ||
ldclient.set_config(Config(SDK_KEY)) | ||
LD_CLIENT = ldclient.get() | ||
|
||
COUNTER = 0 | ||
|
||
class State(rx.State): | ||
|
||
# Create a LaunchDarkly context (formerly known as "user") | ||
ld_context_set: bool = False | ||
updating: bool = False | ||
|
||
def build_ld_context( | ||
self, | ||
context_key: str = "context-key-abc-123", | ||
context_name: str = "linkinbio-app", | ||
) -> None: | ||
global LD_CONTEXT | ||
if LD_CLIENT is None: | ||
return | ||
|
||
LD_CONTEXT = ( | ||
Context.builder( | ||
context_key, | ||
) | ||
.name( | ||
context_name, | ||
) | ||
.build() | ||
) | ||
self.ld_context_set = True | ||
|
||
@rx.var | ||
def get_feature_flag_bool( | ||
self, | ||
feature_flag_key: str = "toggle-bio", | ||
) -> bool: | ||
global COUNTER | ||
if not self.ld_context_set: | ||
return False | ||
|
||
flag_value: bool = LD_CLIENT.variation( | ||
key=feature_flag_key, | ||
context=LD_CONTEXT, | ||
default=False, | ||
) | ||
COUNTER += 1 | ||
return flag_value | ||
|
||
def on_update(self, date: str,): | ||
print(f"{COUNTER} :: {date}") | ||
|
||
|
||
def link_button( | ||
name: str, | ||
url: str, | ||
icon: str, | ||
) -> rx.Component: | ||
icon_map = { | ||
"globe": "globe", | ||
"twitter": "twitter", | ||
"github": "github", | ||
"linkedin": "linkedin", | ||
} | ||
icon_tag = icon_map.get( | ||
icon.lower(), | ||
"link", | ||
) | ||
return rx.link( | ||
rx.button( | ||
rx.icon( | ||
tag=icon_tag, | ||
), | ||
name, | ||
width="100%", | ||
), | ||
href=url, | ||
is_external=True, | ||
) | ||
|
||
|
||
def index_content( | ||
name: str, | ||
pronouns: str, | ||
bio: str, | ||
avatar_url: str, | ||
links: list[dict[str, str]], | ||
background: str, | ||
): | ||
return rx.center( | ||
rx.vstack( | ||
rx.avatar( | ||
src=avatar_url, | ||
size="2xl", | ||
), | ||
rx.heading( | ||
name, | ||
size="lg", | ||
), | ||
rx.text( | ||
pronouns, | ||
font_size="sm", | ||
), | ||
rx.text(bio), | ||
rx.vstack( | ||
rx.foreach( | ||
links, | ||
lambda link: link_button(link["name"], link["url"], link["icon"]), | ||
), | ||
width="100%", | ||
spacing="2", | ||
), | ||
padding="4", | ||
max_width="400px", | ||
width="100%", | ||
spacing="3", | ||
), | ||
width="100%", | ||
height="100vh", | ||
background=background, | ||
) | ||
|
||
|
||
def index() -> rx.Component: | ||
return rx.fragment( | ||
rx.cond( | ||
State.get_feature_flag_bool, | ||
index_content( | ||
name="Bio Page if True", | ||
pronouns="dub.link/pronouns", | ||
bio="insert bio here", | ||
avatar_url="https://avatars.githubusercontent.com/<your_username_here>", | ||
links=[ | ||
{"name": "Website", "url": "https://www.google.com"}, | ||
{"name": "Upcoming Events", "url": "lu.ma/launchdarkly"}, | ||
{"name": "Instagram", "url": "https://instagram.com/qtotherescue"}, | ||
{ | ||
"name": "Another Link here", | ||
"url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ", | ||
}, | ||
], | ||
background="linear-gradient(45deg, #FFD700, #FF8C00, #FF4500)", | ||
), | ||
index_content( | ||
name="Bio Page if False", | ||
pronouns="dub.link/pronouns", | ||
bio="< insert bio here >", | ||
avatar_url="https://avatars.githubusercontent.com/<your_username_here>", | ||
links=[ | ||
{ | ||
"name": "Website", | ||
"url": "https://reflex.dev", | ||
"icon": "globe", | ||
}, | ||
{ | ||
"name": "Twitter", | ||
"url": "https://twitter.com/getreflex", | ||
"icon": "twitter", | ||
}, | ||
{ | ||
"name": "GitHub", | ||
"url": "https://github.com/reflex-dev/reflex-examples", | ||
"icon": "github", | ||
}, | ||
{ | ||
"name": "LinkedIn", | ||
"url": "https://www.linkedin.com/company/reflex-dev", | ||
"icon": "linkedin", | ||
}, | ||
], | ||
background="radial-gradient(circle, var(--chakra-colors-purple-100), var(--chakra-colors-blue-100))", | ||
), | ||
), | ||
rx.moment( | ||
interval=3000, | ||
on_change=State.on_update, | ||
format="HH:mm:ss", | ||
), | ||
) | ||
|
||
|
||
app = rx.App( | ||
style=style, | ||
) | ||
app.add_page( | ||
index, | ||
on_load=State.build_ld_context, | ||
) |
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,56 @@ | ||
import reflex as rx | ||
|
||
# Define a vibrant gradient background | ||
background_gradient = "linear-gradient(45deg, #FF6B6B, #4ECDC4, #45B7D1, #7E57C2)" | ||
|
||
style = { | ||
"font_family": "Inter, sans-serif", | ||
"background": background_gradient, | ||
"min_height": "100vh", # Ensure the gradient covers the full height of the viewport | ||
rx.avatar: { | ||
"border": "4px solid white", | ||
"box_shadow": "lg", | ||
"margin_top": "0.25em", | ||
}, | ||
rx.button: { | ||
"width": "100%", | ||
"height": "3em", | ||
"padding": "0.5em 1em", | ||
"border_radius": "full", | ||
"color": "white", | ||
"background_color": "rgba(0, 0, 0, 0.5)", # Semi-transparent black | ||
"backdrop_filter": "blur(10px)", | ||
"white_space": "nowrap", | ||
"box_shadow": "0 4px 6px rgba(0, 0, 0, 0.1)", | ||
"transition": "all 0.3s ease", | ||
"_hover": { | ||
"transform": "translateY(-2px)", | ||
"box_shadow": "0 6px 8px rgba(0, 0, 0, 0.15)", | ||
"background_color": "rgba(0, 0, 0, 0.7)", # Darker on hover | ||
}, | ||
}, | ||
rx.link: { | ||
"text_decoration": "none", | ||
"_hover": { | ||
"text_decoration": "none", | ||
}, | ||
}, | ||
rx.vstack: { | ||
"background": "rgba(255, 255, 255, 0.9)", | ||
"backdrop_filter": "blur(20px)", | ||
"border_radius": "20px", | ||
"padding": "1em", | ||
"box_shadow": "0 4px 16px rgba(0, 0, 0, 0.1)", | ||
"color": "black", | ||
"align_items": "center", | ||
"text_align": "center", | ||
}, | ||
rx.heading: { | ||
"color": "black", | ||
"margin_bottom": "0.25em", | ||
}, | ||
rx.text: { | ||
"color": "black", | ||
"margin_bottom": "0.5em", | ||
}, | ||
} |
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,2 @@ | ||
reflex==0.6.2.post1 | ||
launchdarkly-server-sdk==9.8.0 |
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,5 @@ | ||
import reflex as rx | ||
|
||
config = rx.Config( | ||
app_name="linkinbio", | ||
) |
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.
Could we ignore this file?
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.
or delete it even?