Bread
Bread
Explore posts from servers
NNuxt
Created by Bread on 5/9/2024 in #❓・help
Hydration mismatch / flashing when altering phone number
I'm trying to get a phone number to change using a package called "InfinityTracking". The nuts and bolts of what the issue is, we have a SSR component (or to be specific just a phone number) that is SSR. When the page is loaded, the phone number is returned from the server, it is then overridden client-side by this external library (injected by GTM), then client-side hydration happens and it returns back to the server-rendered value and then the package changes it back. As a pseudo shorthand, its: 123 -> 456 -> 123 -> 456 and the desired behaviour is: 123 -> 456 The package is non-negotiable. I've tried 'wrapping' the phone number in a component that is <client-only> but that obviously prevents the 'initial' value from the Server being rendered.
2 replies
NNuxt
Created by Bread on 3/18/2024 in #❓・help
Prevent routing to a redirection
I have a product page /holidays/grand-canyon and when hitting a CTA (nuxt-link) the user is sent to an interstitional route provided by an API /basket?holidayCode=1234 this then redirects to the correct 'step' in the journey to purchase, ie. /basket/extras if the holiday has any extras available for purchase. When on this first page in the purchase journey, if you hit the back button in the browser you are taken to the redirection step (/basket?holidayCode=1234) which then puts you right back where you started. How can I prevent this? pseduo diag: Desired: PDP ⇨ Book ⇨ Basket Step [back]⇨ PDP Actual: PDP ⇨ Book ⇨ Basket Step [back]⇨ Book ⇨ Basket Step
3 replies
CC#
Created by Bread on 12/22/2022 in #help
❔ Add a new item to a models collection in razor form
This is the code I have:
<div id="items">
@for (var i = 0; i < Model.ImageHighlights.Count; i++)
{
<div class="form-group">
<label asp-for="@Model.ImageHighlights[i].Title"></label>
<input maxlength="250" asp-for="@Model.ImageHighlights[i].Title" class="form-control bg-peach-light" required type="text"/>
<span asp-validation-for="@Model.ImageHighlights[i].Title" class="form-text text-danger"></span>
</div>
<div class="form-group">
<label asp-for="@Model.ImageHighlights[i].Description"></label>
<textarea maxlength="250" asp-for="@Model.ImageHighlights[i].Description" class="form-control bg-peach-light" required type="text"></textarea>
<span asp-validation-for="@Model.ImageHighlights[i].Description" class="form-text text-danger"></span>
</div>
<div class="form-group">
<label asp-for="@Model.ImageHighlights[i].ImageSource"></label>
<textarea maxlength="250" asp-for="@Model.ImageHighlights[i].ImageSource" class="form-control bg-peach-light" required type="file"></textarea>
<span asp-validation-for="@Model.ImageHighlights[i].ImageSource" class="form-text text-danger"></span>
</div>
}
</div>

<button type="button" onclick="addItem()">Add new Feature</button>

<script>
function addItem() {
var itemsDiv = document.getElementById('items');
var newDiv = document.createElement('div');
var index = itemsDiv.childElementCount;
newDiv.innerHTML = '<div class="form-group"><label for="title_' + index + '">Title:</label><textarea id="title_' + index + '" maxlength="250" name="Title" class="form-control bg-peach-light" required type="text"></textarea><span class="form-text text-danger"></span></div>';
itemsDiv.appendChild(newDiv);
}
</script>
<div id="items">
@for (var i = 0; i < Model.ImageHighlights.Count; i++)
{
<div class="form-group">
<label asp-for="@Model.ImageHighlights[i].Title"></label>
<input maxlength="250" asp-for="@Model.ImageHighlights[i].Title" class="form-control bg-peach-light" required type="text"/>
<span asp-validation-for="@Model.ImageHighlights[i].Title" class="form-text text-danger"></span>
</div>
<div class="form-group">
<label asp-for="@Model.ImageHighlights[i].Description"></label>
<textarea maxlength="250" asp-for="@Model.ImageHighlights[i].Description" class="form-control bg-peach-light" required type="text"></textarea>
<span asp-validation-for="@Model.ImageHighlights[i].Description" class="form-text text-danger"></span>
</div>
<div class="form-group">
<label asp-for="@Model.ImageHighlights[i].ImageSource"></label>
<textarea maxlength="250" asp-for="@Model.ImageHighlights[i].ImageSource" class="form-control bg-peach-light" required type="file"></textarea>
<span asp-validation-for="@Model.ImageHighlights[i].ImageSource" class="form-text text-danger"></span>
</div>
}
</div>

<button type="button" onclick="addItem()">Add new Feature</button>

<script>
function addItem() {
var itemsDiv = document.getElementById('items');
var newDiv = document.createElement('div');
var index = itemsDiv.childElementCount;
newDiv.innerHTML = '<div class="form-group"><label for="title_' + index + '">Title:</label><textarea id="title_' + index + '" maxlength="250" name="Title" class="form-control bg-peach-light" required type="text"></textarea><span class="form-text text-danger"></span></div>';
itemsDiv.appendChild(newDiv);
}
</script>
The javascript here for adding an item feels wrong. Is there any other alternative ways of allowing the user to "add an item" to the form?
2 replies
CC#
Created by Bread on 11/12/2022 in #help
❔ EF Core duplicating many-to-many?
After saving, the references are duplicated!
var entityShowcase = new Models.Showcase
{
AuthorId = showcase.AuthorId,
Description = showcase.Description,
Title = showcase.Description,
Summary = showcase.Summary,
ImageSource = showcase.ImageSource,
MajorVersion = showcase.MajorVersion,
MinorVersion = showcase.MinorVersion,
PatchVersion = showcase.PatchVersion,
};

foreach (var feature in showcase.Features)
{
var dbFeatures = _context.Feature.FirstOrDefault(x => x.Value == feature);
if (dbFeatures is not null)
{
entityShowcase.Features.Add(dbFeatures);
continue;
}

entityShowcase.Features.Add(new Feature { Value = feature });
}

// after the loop above, enitityShowcase features is 2 (as it should be)

var entityEntry = await _context.AddAsync(entityShowcase, cancellationToken);
// after adding, it's actually 4...

await _context.SaveChangesAsync(cancellationToken);
return entityEntry.Entity.Id;
var entityShowcase = new Models.Showcase
{
AuthorId = showcase.AuthorId,
Description = showcase.Description,
Title = showcase.Description,
Summary = showcase.Summary,
ImageSource = showcase.ImageSource,
MajorVersion = showcase.MajorVersion,
MinorVersion = showcase.MinorVersion,
PatchVersion = showcase.PatchVersion,
};

foreach (var feature in showcase.Features)
{
var dbFeatures = _context.Feature.FirstOrDefault(x => x.Value == feature);
if (dbFeatures is not null)
{
entityShowcase.Features.Add(dbFeatures);
continue;
}

entityShowcase.Features.Add(new Feature { Value = feature });
}

// after the loop above, enitityShowcase features is 2 (as it should be)

var entityEntry = await _context.AddAsync(entityShowcase, cancellationToken);
// after adding, it's actually 4...

await _context.SaveChangesAsync(cancellationToken);
return entityEntry.Entity.Id;
4 replies
CC#
Created by Bread on 9/29/2022 in #help
Possible to 'intercept' a successful sign in attempt with .net core identity?
I was curious if it was possible to add some middleware that would detect if someone has signed in successfully with Identity, I'd like to raise my own events and handle them as I need
7 replies
CC#
Created by Bread on 9/8/2022 in #help
Get longest consecutive date 'streak' [Answered]
I'm trying to figure out a nice way of getting a date-streak from a list of objects which will have activities on them. The premise to the problem is, each user records their 'excercise' which can be multiples per day. I don't care about anything other than some acceptence criteria (namely, duration of the exercise) but I can group these effectively into some structure I assume of:
[date] : [true/false]
[date] : [true/false]
This would indicate if the user has completed an activity on that date. Where I'm struggling is to then calculate the streak of dates (the largest streak) in that full list, ie:
1st : true
2nd : false
3rd : true
4th : true
5th : false
6th : true
7th : false
1st : true
2nd : false
3rd : true
4th : true
5th : false
6th : true
7th : false
Here the users top 'streak' is going to be 2, as completed on the 3rd and 4th
18 replies
CC#
Created by Bread on 8/20/2022 in #help
How do I 'build' a QUERY with EF Core?
18 replies