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

8 build list skeleton #55

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
cc3678d
Item List
ThoJah Feb 21, 2023
5e9a74e
List Screen + SortFunctions category/alphabet
ThoJah Feb 21, 2023
d7ee617
minor changes for readability
ThoJah Feb 21, 2023
986cd3a
Merge branch 'main' into 8-build-list-skeleton
ThoJah Feb 21, 2023
b823464
minor change to style
ThoJah Feb 22, 2023
d08c4d9
seperated components from route
ThoJah Feb 23, 2023
a87e4a6
Merge branch 'main' into 8-build-list-skeleton
ThoJah Feb 23, 2023
a79d246
fixed bug and styled ItemListMapper
ThoJah Feb 24, 2023
bef3024
added some paddings
ThoJah Feb 27, 2023
eb185f3
Merge branch 'main' into 8-build-list-skeleton
ThoJah Feb 27, 2023
206084c
styling applied
ThoJah Feb 27, 2023
e1cd992
Merge branch 'main' into 8-build-list-skeleton
ThoJah Mar 1, 2023
44cf642
changed unnecessary ternary to &&
ThoJah Mar 1, 2023
dee0347
minor improvements
ThoJah Mar 2, 2023
150fbde
Merge branch 'main' into 8-build-list-skeleton
ThoJah Mar 2, 2023
bf7b8f4
requested changes applied
ThoJah Mar 6, 2023
1820972
some styling adjusted
ThoJah Mar 6, 2023
23398ab
prisma client update
ThoJah Mar 9, 2023
db1cbf5
reverse merge
ThoJah Mar 9, 2023
4b6d112
fixed nested if statement
ThoJah Mar 9, 2023
0ea6b7e
storybook-static removed
ThoJah Mar 10, 2023
bb0b606
In theory schema changed
TheDoplarEffect Mar 10, 2023
a571d23
Changes schema
TheDoplarEffect Mar 13, 2023
3fc49d9
Merge branch 'main' into 8-build-list-skeleton
ThoJah Mar 13, 2023
72b1994
Trying to get to work with database
TheDoplarEffect Mar 13, 2023
5480c4a
Server side props working
TheDoplarEffect Mar 14, 2023
f8659ed
added css
Mar 14, 2023
731b95c
Removed bubble page
TheDoplarEffect Mar 14, 2023
4b9a000
Merge branch 'SecretProject' into WilliamBackend
TheDoplarEffect Mar 14, 2023
56586db
Added New Backend
TheDoplarEffect Mar 14, 2023
c5a9933
BASIC SLUG
TheDoplarEffect Mar 14, 2023
a02a68c
Backend Working
TheDoplarEffect Mar 14, 2023
7835b93
Merge branch 'WilliamBackend' into 8-build-list-skeleton
TheDoplarEffect Mar 14, 2023
5d8d6b1
Refresh Workign
TheDoplarEffect Mar 14, 2023
4072624
Merge branch 'WilliamBackend' into 8-build-list-skeleton
TheDoplarEffect Mar 14, 2023
07510b6
Added list items without categories for other view
TheDoplarEffect Mar 15, 2023
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
42 changes: 42 additions & 0 deletions src/components/List/ItemListMapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { List } from "@/pages/list";
import { sortByAlphabet, sortByCategory } from "./SortBySwitches";

type ItemListMapperProps = {
itemList: List;
sortBy: string;
};

export function ItemListMapper(props: ItemListMapperProps) {
let sectionName = "";
let sorted: List = [];

switch (props.sortBy) {
case "date":
sorted = props.itemList;
break;
case "category":
sorted = sortByCategory(props.itemList);
break;
case "alphabetical":
sorted = sortByAlphabet(props.itemList);
break;
}
return (
<>
{sorted.map((product) => {
let nameSection = false;

if (props.sortBy === "category" && product.category !== sectionName) {
sectionName = product.category;
nameSection = true;
}
return (
<div className=" py-1">
{nameSection && <p>{sectionName + ":"}</p>}
<p className="px-4 rounded-2xl">{product.item}</p>
</div>
);
})}
</>
);
}
103 changes: 103 additions & 0 deletions src/components/List/SortBySwitches.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { List } from "@/pages/list";
import { RadioGroup } from "@headlessui/react";
import { Dispatch, SetStateAction } from "react";
import { clsx } from "clsx";

export function sortByAlphabet(input: List) {
const sorted = [...input];
sorted.sort((a, b) => {
const nameA = a.item.toUpperCase();
const nameB = b.item.toUpperCase();
if (nameA < nameB) {
return -1;
}
if (nameA > nameB) {
return 1;
}
return 0;
});
return sorted;
}
export function sortByCategory(input: List): List {
const sorted = [...input];
sorted.sort((a, b) => {
const categoryA = a.category.toUpperCase();
const categoryB = b.category.toUpperCase();

const nameA = a.item.toUpperCase();
const nameB = b.item.toUpperCase();

if (categoryA < categoryB) {
return -1;
}
if (categoryA > categoryB) {
return 1;
}

if (categoryA === categoryB) {
if (nameA < nameB) {
return -1;
}
if (nameA > nameB) {
return 1;
}
return 0;
}
return 0;
});
return sorted;
}

export function sortByDate() {}
NoHara42 marked this conversation as resolved.
Show resolved Hide resolved

type SortByProps = {
sortBy: string;
setSort: Dispatch<SetStateAction<string>>;
};

export function SortBySwitches(props: SortByProps) {
return (
<RadioGroup
className="font-sans flex flex-row justify-center items-center bg-secondary-transparent text-sm h-7 rounded-listitem"
value={props.sortBy}
onChange={props.setSort}
>
<RadioGroup.Option className="h-full w-1/3" value="date">
{({ checked }) => (
<p
className={clsx(
"h-full w-full flex justify-center items-center rounded-listitem",
checked && "bg-primary-default-background text-text-white"
)}
>
Date
</p>
)}
</RadioGroup.Option>
<RadioGroup.Option className="h-full w-1/3" value="category">
{({ checked }) => (
<p
className={clsx(
"h-full w-full flex justify-center items-center rounded-listitem",
checked && "bg-primary-default-background text-text-white"
)}
>
Category
</p>
)}
</RadioGroup.Option>
<RadioGroup.Option className="h-full w-1/3" value="alphabetical">
{({ checked }) => (
<p
className={clsx(
"h-full w-full flex justify-center items-center rounded-listitem",
checked && "bg-primary-default-background text-text-white"
)}
>
Alphabetical
</p>
)}
</RadioGroup.Option>
</RadioGroup>
);
}
38 changes: 38 additions & 0 deletions src/pages/list/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { useState } from "react";
import { ItemListMapper } from "@/components/List/ItemListMapper";
import { SortBySwitches } from "@/components/List/SortBySwitches";

export type List = Array<{
item: string;
quantity: number;
category: string;
}>;
export type Categories = Array<{ id: number; name: string; quantity: number }>;

const listItems: List = [
{ item: "tomatoes", quantity: 1, category: "vegetables" },
{ item: "pepper", quantity: 1, category: "spices" },
{ item: "onion", quantity: 1, category: "vegetables" },
{ item: "apple", quantity: 1, category: "fruit" },
{ item: "kiwi", quantity: 1, category: "fruit" },
{ item: "pork", quantity: 1, category: "meat" },
{ item: "toothpaste", quantity: 1, category: "hygiene" },
{ item: "kurkuma", quantity: 1, category: "spices" },
{ item: "pumpkin", quantity: 1, category: "vegetables" },
{ item: "deodorant", quantity: 1, category: "hygiene" },
{ item: "shampoo", quantity: 1, category: "hygiene" },
{ item: "crocodile", quantity: 1, category: "meat" },
{ item: "cinnamon", quantity: 1, category: "spices" },
{ item: "cabbage", quantity: 1, category: "vegetables" },
];

export default function List() {
const [sortBy, setSortBy] = useState("date");

return (
<div className="m-6">
<SortBySwitches sortBy={sortBy} setSort={setSortBy}></SortBySwitches>
<ItemListMapper itemList={listItems} sortBy={sortBy}></ItemListMapper>
</div>
);
}
13 changes: 13 additions & 0 deletions src/stories/ItemListMapper.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Meta, StoryObj } from "@storybook/react";
import { ItemListMapper } from "../components/List/ItemListMapper";

const meta: Meta<typeof ItemListMapper> = {
title: "components/ItemListMapper",
component: ItemListMapper,
};

export default meta;

type Story = StoryObj<typeof ItemListMapper>;

export const Default: Story = {};
13 changes: 13 additions & 0 deletions src/stories/SortBySwitches.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Meta, StoryObj } from "@storybook/react";
import { SortBySwitches } from "../components/List/SortBySwitches";

const meta: Meta<typeof SortBySwitches> = {
title: "components/SortBySwitches",
component: SortBySwitches,
};

export default meta;

type Story = StoryObj<typeof SortBySwitches>;

export const Default: Story = {};
2 changes: 2 additions & 0 deletions storybook-static/39.a67aef79e861abdb9699.manager.bundle.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Prism: Lightweight, robust, elegant syntax highlighting
*
* @license MIT <https://opensource.org/licenses/MIT>
* @author Lea Verou <https://lea.verou.me>
* @namespace
* @public
*/
2 changes: 2 additions & 0 deletions storybook-static/42.cf8836580ae5fba5a45f.manager.bundle.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions storybook-static/817.d60200032a37ed5a4c91.manager.bundle.js

Large diffs are not rendered by default.

Loading