Skip to content

Commit

Permalink
Add previously git ignored lib folder, update gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
Alschn committed Dec 17, 2023
1 parent 9a22592 commit 236a11d
Show file tree
Hide file tree
Showing 6 changed files with 261 additions and 144 deletions.
146 changes: 2 additions & 144 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,146 +1,4 @@
<<<<<<< HEAD
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.idea
vscode
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# Editor settings
.idea
idea
*/idea/
*/idea/*
.vscode

# Static files (except temp file)
/staticfiles
!temp

# Coverage files
coverage
htmlcov
.htmlcov
146 changes: 146 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<<<<<<< HEAD
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# Editor settings
.idea
idea
*/idea/
*/idea/*
.vscode

# Static files (except temp file)
/staticfiles
!temp

# Coverage files
coverage
htmlcov
.htmlcov
17 changes: 17 additions & 0 deletions frontend/src/lib/fetcher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { cookies } from "next/headers";

const fetcher = (...args: Parameters<typeof fetch>) => {
const cookiesStore = cookies();
const token = cookiesStore.get("token")?.value ?? "";
const [input, init] = args;
const { headers, ...restInit } = init ?? {};
return fetch(input, {
headers: {
...headers,
Authorization: `Token ${token}`,
},
...restInit,
});
};

export default fetcher;
74 changes: 74 additions & 0 deletions frontend/src/lib/format.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
export function getMsToTimeString(ms: number, colon_separated = false) {
const seconds: number = Math.floor(ms / 1000);
const minutes: number = Math.floor(ms / (1000 * 60));
const hours: number = Math.floor(ms / (1000 * 60 * 60));
const days: number = Math.floor(ms / (1000 * 60 * 60 * 24));

const cutSeconds: number = seconds > 60 ? seconds - minutes * 60 : seconds;
const cutMinutes: number = minutes > 60 ? minutes - hours * 60 : minutes;
const cutHours: number = hours > 24 ? hours - days * 24 : hours;

const formatCutSeconds: string =
cutSeconds < 10 ? `0${cutSeconds}` : String(cutSeconds);
const formatCutMinutes: string =
cutMinutes < 10 ? `0${cutMinutes}` : String(cutMinutes);
const formatCutHours: string =
cutHours < 10 ? `0${cutHours}` : String(cutHours);

if (seconds < 60)
return colon_separated ? `0:${formatCutSeconds}` : `${seconds} sec`;
else if (minutes < 60)
return colon_separated
? `${minutes}:${formatCutSeconds}`
: `${minutes} min ${cutSeconds} sec`;
else if (hours < 24)
return colon_separated
? `${hours}:${formatCutMinutes}:${formatCutSeconds}`
: `${hours} hrs ${cutMinutes} min`;
else
return colon_separated
? `${days}:${formatCutHours}:${cutMinutes}:${formatCutSeconds}`
: `${days} days ${cutHours} hrs`;
}

const units: { unit: Intl.RelativeTimeFormatUnit; ms: number }[] = [
{ unit: "year", ms: 31536000000 },
{ unit: "month", ms: 2628000000 },
{ unit: "day", ms: 86400000 },
{ unit: "hour", ms: 3600000 },
{ unit: "minute", ms: 60000 },
{ unit: "second", ms: 1000 },
];
const rtf = new Intl.RelativeTimeFormat("en", { numeric: "auto" });

/**
* Get language-sensitive relative time message from Dates.
* @param relative - the relative dateTime, generally is in the past or future
* @param pivot - the dateTime of reference, generally is the current time
*/
export function relativeTimeFromDates(
relative: Date | null,
pivot: Date = new Date(),
): string {
if (!relative) return "";
const elapsed = relative.getTime() - pivot.getTime();
return relativeTimeFromElapsed(elapsed);
}

/**
* Get language-sensitive relative time message from elapsed time.
* @param elapsed - the elapsed time in milliseconds
*/
export function relativeTimeFromElapsed(elapsed: number): string {
for (const { unit, ms } of units) {
if (Math.abs(elapsed) >= ms || unit === "second") {
return rtf.format(Math.round(elapsed / ms), unit);
}
}
return "";
}

export function uriToId(uri: string) {
const splitByColon = uri.split(":");
return splitByColon[2] ?? "";
}
6 changes: 6 additions & 0 deletions frontend/src/lib/tailwind.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";

export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
Loading

0 comments on commit 236a11d

Please sign in to comment.