Skip to content
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

Add categories #8

Merged
merged 20 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
554fbf3
Removed production env var from docker-compose (causing saving issues)
jordan-dalby Oct 27, 2024
72d3496
Added categories and updated UI to support them
jordan-dalby Oct 27, 2024
a4a2678
Changed design of categories, now much more obvious separation betwee…
jordan-dalby Oct 28, 2024
b3884b3
Moved save / cancel buttons into a floating container at the bottom o…
jordan-dalby Oct 28, 2024
adfc3af
Updated the look of the categories and made it so that clicking anywh…
jordan-dalby Oct 28, 2024
2050ac2
Separated concerns to increase reusability
jordan-dalby Oct 28, 2024
fec4fb4
Added arm support
jordan-dalby Oct 28, 2024
ba1b99a
Added sqlite dependencies
jordan-dalby Oct 28, 2024
21be89b
Switched to better-sqlite3 for cross-platform builds
jordan-dalby Oct 28, 2024
5e3e764
Merge pull request #12 from jordan-dalby/arm-support
jordan-dalby Oct 28, 2024
84c3271
Removed production env var from docker-compose (causing saving issues)
jordan-dalby Oct 27, 2024
ba71b2d
Added categories and updated UI to support them
jordan-dalby Oct 27, 2024
05ca83c
Changed design of categories, now much more obvious separation betwee…
jordan-dalby Oct 28, 2024
0c82adc
Moved save / cancel buttons into a floating container at the bottom o…
jordan-dalby Oct 28, 2024
f2e244e
Updated the look of the categories and made it so that clicking anywh…
jordan-dalby Oct 28, 2024
d11b674
Separated concerns to increase reusability
jordan-dalby Oct 28, 2024
d309b64
Merge branch 'use-categories' of https://github.com/jordan-dalby/Byte…
jordan-dalby Oct 28, 2024
9300178
Fixed border-radius on code blocks
jordan-dalby Oct 28, 2024
8cf5dd9
Added margin to snippet modal
jordan-dalby Oct 28, 2024
cc79085
Updated app image to showcase categories
jordan-dalby Oct 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,18 @@ jobs:
id: docker_tag
run: echo "TAG=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:pr-${{ github.event.pull_request.number }}" >> $GITHUB_ENV

- name: Set up QEMU for cross-platform builds
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
install: true

- name: Build and Push Docker image for Testing
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ env.TAG }}
platforms: linux/amd64,linux/arm64,linux/arm/v7
tags: ${{ env.TAG }}
9 changes: 9 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,20 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up QEMU for cross-platform builds
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
install: true

- name: Build and Push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
platforms: linux/amd64,linux/arm64,linux/arm/v7
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.event.release.tag_name }}
6 changes: 4 additions & 2 deletions client/src/components/common/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ const Modal: React.FC<ModalProps> = ({ isOpen, onClose, children }) => {
>
<div
ref={modalRef}
className={`bg-gray-800 rounded-lg max-w-3xl w-full max-h-[80vh] overflow-y-auto transition-all duration-300 ${isOpen ? 'opacity-100 scale-100' : 'opacity-0 scale-95'}`}
className={`bg-gray-800 rounded-lg max-w-3xl w-full max-h-[80vh] flex flex-col transition-all duration-300 ${isOpen ? 'opacity-100 scale-100' : 'opacity-0 scale-95'}`}
>
<div className="p-4">
<div className="px-4 pt-4 pb-4">
<button
onClick={onClose}
className="float-right text-gray-400 hover:text-white"
>
<X size={24} />
</button>
</div>
<div className="px-4 overflow-y-auto flex-1">
{children}
</div>
</div>
Expand Down
34 changes: 33 additions & 1 deletion client/src/components/settings/SettingsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,18 @@ const SettingsModal: React.FC<SettingsModalProps> = ({ isOpen, onClose, settings
const [showCodePreview, setShowCodePreview] = useState(settings.showCodePreview);
const [previewLines, setPreviewLines] = useState(settings.previewLines);
const [includeCodeInSearch, setIncludeCodeInSearch] = useState(settings.includeCodeInSearch);
const [showCategories, setShowCategories] = useState(settings.showCategories);
const [expandCategories, setExpandCategories] = useState(settings.expandCategories);

const handleSave = () => {
onSettingsChange({ compactView, showCodePreview, previewLines, includeCodeInSearch });
onSettingsChange({
compactView,
showCodePreview,
previewLines,
includeCodeInSearch,
showCategories,
expandCategories
});
onClose();
};

Expand Down Expand Up @@ -61,6 +70,29 @@ const SettingsModal: React.FC<SettingsModalProps> = ({ isOpen, onClose, settings
className="form-checkbox h-5 w-5 text-blue-600 rounded focus:ring-blue-500"
/>
</div>
<div className="flex items-center justify-between">
<label htmlFor="showCategories" className="text-gray-300">Show Categories</label>
<input
type="checkbox"
id="showCategories"
checked={showCategories}
onChange={(e) => setShowCategories(e.target.checked)}
className="form-checkbox h-5 w-5 text-blue-600 rounded focus:ring-blue-500"
/>
</div>

{showCategories && (
<div className="flex items-center justify-between">
<label htmlFor="expandCategories" className="text-gray-300">Expand Categories</label>
<input
type="checkbox"
id="expandCategories"
checked={expandCategories}
onChange={(e) => setExpandCategories(e.target.checked)}
className="form-checkbox h-5 w-5 text-blue-600 rounded focus:ring-blue-500"
/>
</div>
)}
</div>
<div className="mt-6 flex justify-end">
<button
Expand Down
112 changes: 112 additions & 0 deletions client/src/components/snippets/CustomDropdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { CustomDropdownProps } from '../../types/types';
import React, { useState, useRef, useEffect } from 'react';

const CustomDropdown: React.FC<CustomDropdownProps> = ({ options, value, onChange, maxLength }) => {
const [isOpen, setIsOpen] = useState(false);
const [internalValue, setInternalValue] = useState(value || '');
const dropdownRef = useRef<HTMLDivElement>(null);
const inputRef = useRef<HTMLInputElement>(null);

useEffect(() => {
setInternalValue(value || '');
}, [value]);

useEffect(() => {
const handleClickOutside = (event: MouseEvent) => {
if (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) {
setIsOpen(false);
matchCaseAndUpdate();
}
};

document.addEventListener('mousedown', handleClickOutside);
return () => {
document.removeEventListener('mousedown', handleClickOutside);
};
}, [options, internalValue]);

const matchCaseAndUpdate = () => {
const match = options.find(option =>
option.toLowerCase() === internalValue.toLowerCase()
);
if (match) {
setInternalValue(match);
onChange(match);
} else {
onChange(internalValue);
}
};

const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const newValue = e.target.value.slice(0, maxLength);
setInternalValue(newValue);
};

const handleOptionClick = (option: string) => {
setInternalValue(option);
onChange(option);
setIsOpen(false);
};

const handleInputFocus = () => {
setIsOpen(true);
if (inputRef.current) {
inputRef.current.select();
}
};

const handleInputBlur = () => {
matchCaseAndUpdate();
};

const handleKeyDown = (e: React.KeyboardEvent) => {
if (e.key === 'Enter') {
e.preventDefault();
setIsOpen(false);
matchCaseAndUpdate();
}
};

const filteredOptions = options.filter(option =>
option.toLowerCase().includes(internalValue.toLowerCase())
);

return (
<div className="relative" ref={dropdownRef}>
<input
ref={inputRef}
type="text"
className="mt-1 block w-full rounded-md bg-gray-700 border border-gray-600 text-white p-2 text-sm"
value={internalValue}
onChange={handleInputChange}
onFocus={handleInputFocus}
onBlur={handleInputBlur}
onKeyDown={handleKeyDown}
placeholder="Select or type a language"
maxLength={maxLength}
/>
{isOpen && (
<ul className="absolute z-10 mt-1 w-full bg-gray-700 border border-gray-600 rounded-md shadow-lg max-h-60 overflow-auto">
{filteredOptions.length > 0 ? (
filteredOptions.map((option, index) => (
<li
key={index}
className="px-4 py-2 hover:bg-gray-600 cursor-pointer text-white text-sm"
onClick={() => handleOptionClick(option)}
onMouseDown={(e) => e.preventDefault()}
>
{option}
</li>
))
) : (
<li className="px-4 py-2 text-gray-400 text-sm italic">
No matching languages found
</li>
)}
</ul>
)}
</div>
);
};

export default CustomDropdown;
3 changes: 2 additions & 1 deletion client/src/components/snippets/DynamicCodeEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ const DynamicCodeEditor: React.FC<DynamicCodeEditorProps> = ({
};

return (
<div className="relative rounded-md" style={{ backgroundColor: '#1e1e1e', height: editorHeight, minHeight: '400px' }}>
<div className="relative rounded-md" style={{ backgroundColor: '#1e1e1e', height: editorHeight, minHeight: '400px', zIndex: 0 }}>
<textarea
ref={textareaRef}
value={code}
Expand Down Expand Up @@ -195,6 +195,7 @@ const DynamicCodeEditor: React.FC<DynamicCodeEditorProps> = ({
pointerEvents: 'none',
backgroundColor: 'transparent',
overflow: 'hidden',
zIndex: 0,
}}
>
<SyntaxHighlighter
Expand Down
Loading