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

Next release #143

Merged
merged 21 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
3b5a0e4
Merge pull request #114 from datagrove/next-release
r-southworth Aug 9, 2024
46a9e55
Merge pull request #130 from datagrove/next-release
r-southworth Aug 16, 2024
4be418f
re done of resource filter
gerzarko Aug 19, 2024
8524d62
add filter working but getting some bugs on the all
gerzarko Aug 19, 2024
323e257
fix some bugs
gerzarko Aug 19, 2024
4c3ad20
fix other bugs from the clear
gerzarko Aug 19, 2024
85d6ad8
fix more bugs, add types, fix secular filter bug
gerzarko Aug 19, 2024
0dc9ba8
fix number of filters in use
gerzarko Aug 19, 2024
ec39a46
Merge branch 'datagrove:main' into ResourceTypeFilter
gerzarko Aug 19, 2024
61e9639
Merge pull request #137 from gerzarko/ResourceTypeFilter
r-southworth Aug 23, 2024
22c1d47
Merge pull request #139 from datagrove/imageOptimization
r-southworth Aug 23, 2024
3a1d496
add outline of draft post migration file, add book to resource types,…
r-southworth Aug 27, 2024
86d079c
change calls to require draft status false except for creator self view
r-southworth Aug 27, 2024
c64631b
make it so full post view comes up for only creators when the post is…
r-southworth Aug 27, 2024
3478052
update mobile full view
r-southworth Aug 28, 2024
6d1df56
update mobile view card, remove borders
r-southworth Aug 28, 2024
aeb4ba6
add draft marker on full post details and mobile full post details
r-southworth Aug 28, 2024
728586c
fix listing button for edit post
r-southworth Aug 28, 2024
cb8362d
Internationalize
r-southworth Aug 28, 2024
4f89d51
update types
r-southworth Aug 28, 2024
7dafbbf
Merge pull request #142 from datagrove/draftPosts
r-southworth Aug 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
6 changes: 2 additions & 4 deletions src/components/common/cart/CartAuthMode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,9 @@ export const CartAuthMode: Component<Props> = (props) => {
<button
class="btn-secondary max-w-1/2 inline"
onclick={props.checkoutAsGuest}
// TODO: INTERNATIONALIZE
aria-label="checkout as guest"
aria-label={t("buttons.checkoutAsGuest")}
>
{/* TODO: Internationalize*/}
Checkout as Guest
{t("buttons.checkoutAsGuest")}
</button>
<form class="max-w-1/2 inline">
<button
Expand Down
2 changes: 2 additions & 0 deletions src/components/home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const Home: Component = () => {
.select("*")
.order("id", { ascending: true })
.eq("listing_status", true)
.eq("draft_status", false)
.limit(8);
if (!data) {
alert("No posts available.");
Expand Down Expand Up @@ -89,6 +90,7 @@ export const Home: Component = () => {
.from("sellerposts")
.select("*")
.eq("listing_status", true)
.eq("draft_status", false)
.order("id", { ascending: false })
.limit(8);

Expand Down
27 changes: 27 additions & 0 deletions src/components/posts/CreateNewPost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import stripe from "../../lib/stripe";
import Dropdown from "@components/common/Dropdown";
import { UploadFiles } from "@components/posts/UploadResource";
import tinymce from "tinymce";
import { sortResourceTypes } from "@lib/utils/resourceSort";

const lang = getLangFromUrl(new URL(window.location.href));
const t = useTranslations(lang);
Expand Down Expand Up @@ -194,6 +195,7 @@ export const CreateNewPost: Component = () => {
const [isAdmin, setIsAdmin] = createSignal<boolean>(false);
const [isHosted, setIsHosted] = createSignal<boolean>(false);
const [resourceLinks, setResourceLinks] = createSignal<string>("");
const [draftStatus, setDraftStatus] = createSignal<boolean>(false);

onMount(() => {
window.addEventListener("storage", (event) => {
Expand Down Expand Up @@ -290,6 +292,7 @@ export const CreateNewPost: Component = () => {
if (error) {
console.log("supabase error: " + error.message);
} else {
sortResourceTypes(resourceType);
resourceType.forEach((type) => {
setResourceTypes([
...resourceTypes(),
Expand Down Expand Up @@ -380,12 +383,25 @@ export const CreateNewPost: Component = () => {
}
});

function saveAsDraft(e: Event) {
e.preventDefault();
setDraftStatus(true);

const button = e.currentTarget as HTMLFormElement;
const form = button.closest("form") as HTMLFormElement;

if (form) {
form.requestSubmit();
}
}

async function submit(e: SubmitEvent) {
e.preventDefault();

const formData = new FormData(e.target as HTMLFormElement);
formData.append("access_token", session()?.access_token!);
formData.append("refresh_token", session()?.refresh_token!);
formData.append("draft_status", JSON.stringify(draftStatus()));
formData.append("lang", lang);
if (isFree()) {
setPrice("0");
Expand Down Expand Up @@ -1338,6 +1354,17 @@ export const CreateNewPost: Component = () => {

<br />
<div class="flex justify-center">
<button
id="save-as-draft"
class={`btn-primary text-2xl`}
onclick={(e) => {
e.preventDefault();
e.stopPropagation();
saveAsDraft(e);
}}
>
Save as Draft
</button>
<button
id="post"
disabled={!allRequirementsMet()}
Expand Down
94 changes: 86 additions & 8 deletions src/components/posts/EditPost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { getLangFromUrl, useTranslations } from "../../i18n/utils";
import { TinyComp } from "./TinyComp";
import { createStore } from "solid-js/store";
import type { Post } from "@lib/types";
import { sortResourceTypes } from "@lib/utils/resourceSort";

const lang = getLangFromUrl(new URL(window.location.href));
const t = useTranslations(lang);
Expand Down Expand Up @@ -74,6 +75,9 @@ export const EditPost: Component<Props> = (props: Props) => {
const [resourceExpanded, setResourceExpanded] =
createSignal<boolean>(false);
const [secular, setSecular] = createSignal<boolean>(false);
const [draftStatus, setDraftStatus] = createSignal<boolean>(false);
const [startDraftStatus, setStartDraftStatus] =
createSignal<boolean>(false);

onMount(async () => {
console.log(props.post);
Expand All @@ -94,6 +98,8 @@ export const EditPost: Component<Props> = (props: Props) => {
setSubjectPick(props.post.product_subject);
setResourceTypesPick(props.post?.resource_types!);
setSecular(props.post.secular);
setDraftStatus(props.post.draft_status);
setStartDraftStatus(props.post.draft_status);

if (props.post?.image_urls) {
setImageUrl(props.post?.image_urls.split(","));
Expand Down Expand Up @@ -136,6 +142,7 @@ export const EditPost: Component<Props> = (props: Props) => {
if (error) {
console.log("supabase error: " + error.message);
} else {
sortResourceTypes(resourceType);
resourceType.forEach((type) => {
setResourceTypes([
...resourceTypes(),
Expand Down Expand Up @@ -199,6 +206,32 @@ export const EditPost: Component<Props> = (props: Props) => {
}
});

function saveAsDraft(e: Event) {
e.preventDefault();
e.stopPropagation();
setDraftStatus(true);

const button = e.currentTarget as HTMLFormElement;
const form = button.closest("form") as HTMLFormElement;

if (form) {
form.requestSubmit();
}
}

function listResourcePost(e: Event) {
e.preventDefault();
e.stopPropagation();

const button = e.currentTarget as HTMLFormElement;
const form = button.closest("form") as HTMLFormElement;

if (form) {
setDraftStatus(false);
form.requestSubmit();
}
}

async function submit(e: SubmitEvent) {
e.preventDefault();

Expand All @@ -217,6 +250,7 @@ export const EditPost: Component<Props> = (props: Props) => {
tmpDiv.innerHTML = formData.get("Content") as string;
let description = tmpDiv.textContent || tmpDiv.innerText || "";
formData.append("description", description);
formData.append("draft_status", JSON.stringify(draftStatus()));

if (subjectPick() !== undefined) {
formData.append("subject", JSON.stringify(subjectPick()));
Expand Down Expand Up @@ -440,6 +474,49 @@ export const EditPost: Component<Props> = (props: Props) => {
}
}

function postButton() {
if (startDraftStatus() === false) {
return (
<>
<button
id="post"
disabled={!allRequirementsMet()}
class={`text-2xl ${
allRequirementsMet()
? "btn-primary"
: "btn-disabled"
}`}
>
{t("buttons.updateResource")}
</button>
</>
);
} else if (startDraftStatus() === true) {
return (
<>
<button
id="post"
disabled={!allRequirementsMet()}
class={`text-2xl ${
allRequirementsMet()
? "btn-primary"
: "btn-disabled"
}`}
onclick={(e) => {
e.preventDefault();
e.stopPropagation();
listResourcePost(e);
}}
>
{t("buttons.listResource")}
</button>
</>
);
} else {
return <></>;
}
}

return (
<div>
<form onSubmit={submit}>
Expand Down Expand Up @@ -1064,16 +1141,17 @@ export const EditPost: Component<Props> = (props: Props) => {
<br />
<div class="flex justify-center">
<button
id="post"
disabled={!allRequirementsMet()}
class={`text-2xl ${
allRequirementsMet()
? "btn-primary"
: "btn-disabled"
}`}
id="save-as-draft"
class={`btn-primary text-2xl`}
onclick={(e) => {
e.preventDefault();
e.stopPropagation();
saveAsDraft(e);
}}
>
{t("buttons.updateResource")}
Save as Draft
</button>
{postButton()}
</div>
</form>
</div>
Expand Down
Loading
Loading